Dear Statalisters
I am trying to run a polychoric factor analysis for 4 variables (perma prinActSta union woutwrk) by state. I have 35 states and the variables are binary and ordered categorical, so I wrote a for loop for it which is as follows:
forval j = 1/35 {
polychoric perma prinActSta union woutwrk if STATE==`j'
display r(sum_w)
local N`j' = r(sum_w)
matrix r`j' = r(R)
factormat r`j' ,n($N`j') factors(1) ml
predict Wbp`j' if STATE==`j'
}
Stata seems to execute the first 4 lines correctly, however in the 5th line i.e the factormat, the number of observations change so it's executed incorrectly. Stata does not update the number of observations in n($N`j').
What I would ideally like to do is run the following for 35 states.
polychoric perma prinActSta union woutwrk if STATE==1
display r(sum_w)
local N1 = r(sum_w)
matrix r1 = r(R)
factormat r1 ,n($N1) factors(1) ml
predict Wbp1 if STATE==1
Is there any way I could update the local in the for loop?
Best Regards
Sayli
I am trying to run a polychoric factor analysis for 4 variables (perma prinActSta union woutwrk) by state. I have 35 states and the variables are binary and ordered categorical, so I wrote a for loop for it which is as follows:
forval j = 1/35 {
polychoric perma prinActSta union woutwrk if STATE==`j'
display r(sum_w)
local N`j' = r(sum_w)
matrix r`j' = r(R)
factormat r`j' ,n($N`j') factors(1) ml
predict Wbp`j' if STATE==`j'
}
Stata seems to execute the first 4 lines correctly, however in the 5th line i.e the factormat, the number of observations change so it's executed incorrectly. Stata does not update the number of observations in n($N`j').
What I would ideally like to do is run the following for 35 states.
polychoric perma prinActSta union woutwrk if STATE==1
display r(sum_w)
local N1 = r(sum_w)
matrix r1 = r(R)
factormat r1 ,n($N1) factors(1) ml
predict Wbp1 if STATE==1
Is there any way I could update the local in the for loop?
Best Regards
Sayli
Comment