I wonder if there is a way to extract some scalars from a matrix based on their ROW NAMEs and COLUMN NAMEs?
For example, after the -sem- command, I got an r(table) and save it to a matrix named "test".
The matrix "test" goes like this:
Now, I want to extract the vector in red whose column is "y:mx" and row is "ul". I know there is a way to do so:
But, the number [6,5] is meaningless to me. Could I extract the vector based on a more meaningful way, for example, the row and column names of the vector. If yes, how to do it? Can anyone help me?
Btw, the following command does NOT work:
For example, after the -sem- command, I got an r(table) and save it to a matrix named "test".
Code:
use https://stats.idre.ucla.edu/stat/data/hsb2, clear rename science y /* dependent variable */ rename math x /* independent variable */ rename read m /* mediator variable */ rename write w /* moderator variable 1 */ rename socst z /* moderator variable 2 */ generate mx=m*x /* mv by iv interaction */ sem (m <- x)(y <- m x mx) matrix test = r(table)
Code:
mat list test
test[9,8]
m: m: y: y: y: y: /:
x _cons m x mx _cons var(e.m)
b .72480697 14.072537 .97661637 1.03094 -.01158689 -20.839211 58.719247
se .05798238 3.1002009 .28750807 .29697067 .00530912 15.169517 5.8719247
z 12.500469 4.5392338 3.3968311 3.4715212 -2.182452 -1.3737558 .b
pvalue 7.421e-36 5.646e-06 .00068171 .00051752 .02907619 .16951751 .b
ll .61116359 7.9962547 .41311091 .44888815 -.02199257 -50.570918 48.268113
ul .83845035 20.148819 1.5401218 1.6129918 -.00118122 8.8924952 71.433286
df . . . . . . .
crit 1.959964 1.959964 1.959964 1.959964 1.959964 1.959964 1.959964
eform 0 0 0 0 0 0 0
/:
var(e.y)
b 49.709937
se 4.9709937
z .b
pvalue .b
ll 40.862323
ul 60.473257
df .
crit 1.959964
eform 0
Code:
scalar ymxul = test[6,5] display ymxul
Btw, the following command does NOT work:
Code:
scalar ymxul = test["ul","y:mx"]
Comment