jeffrey
jeffrey

Reputation: 2096

Using xline() with values from a matrix in Stata

I am using xline() to add vertical lines to scatter plots in Stata. I stored the values for the lines, which are the means for different subsamples, in a matrix. Now I want to use the values from the matrix as coordinates in xline().

I tried:

mat means=J(1,5,.)
mat means[1,1]=mean(subsample1)
...

scatter data1 data2, xline(means[1,1])
scatter data3 data4, xline(means[1,2])
...

However, I get the error invalid line argument.

I am grateful for any hint!

Upvotes: 0

Views: 623

Answers (1)

Maarten Buis
Maarten Buis

Reputation: 2694

// open some example data
sysuse nlsw88, clear

// create a matrix of means
reg grade ibn.race, hascons
matrix means = e(b)

// use those means in -xline()-
scatter wage grade, xline(`=el(means,1,1)' `=el(means,1,2)' `=el(means,1,3)')

Upvotes: 4

Related Questions