James Ferng
I ran the following regression :
By code: regress x y z;
How can I fetch and save the variance-covariance of estimates for each
code
I ran. The stata command "matrix cv=get(VCE) \svmat cv" only gives the
VCE
of last one.
>>> One way resembles an answer given to another question earlier
today.
For simplicity, I'll imagine that the levels of code are
smallish integers or simple strings which can be part
of matrix names. (If not, map them to integers using -egen, group-.)
1. Get -levels- from SSC, then
levels code, local(levels)
2.
qui foreach l of local levels {
regress x y z if code == `l'
matrix cv`l' = get(VCE)
}
You should get a series of matrices, perhaps called
cv1, cv2, ...
Note that -levels- is not mandatory here. It is just
a general way of picking up the levels of a categorical
or classifying variable. But the
idea of looping over the distinct levels of a
categorical variable with -foreach- is very
general and powerful.
For more, see Stata Journal 2(2), 202-222 (2002),
or (for the slide show version)
http://fmwww.bc.edu/RePEc/usug2002/fortitude.pdf
Nick
[email protected]
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/