I am a beginner in Stata and I am trying to create a loop regression, store the coefficients of the DVs and then plot these. Does this code make sense?
forvalues i = 1/100 {
regress y x1 x2 x3 if ID==`i'
matrix b1 = e(x1)
matrix b2 = e(x2)
matrix b3 = e(x3)
}
I am using coefplot right after and it just does not work. Any help will be very highly appreciated.
Does this code make sense? As you say, it does not work.
I see three bugs.
After each regression, the coefficients are not stored in
e(x1)
and so on. Such references are not illegal, but they just return missing values.Similarly a command like
matrix b1 = e(x1)
just creates a 1 x 1 matrix with a single missing value.
Hence, a natural question is: where did this code come from?
There are several ways to get coefficients stored from say 100 regressions. See for example
statsby
and the community-contributedrangestat
(SSC).