On Oct 17, 2004, at 2:33, Alex wrote:
Sort year
By year: quietly reg y x1 x2 x3
Normally, after a regression you can type "predict res, residual", but
I am
not sure how to incorporate it in the above framework. Stata doesn't
seem to
let me type more than one command after the "by" function. E.g. it
won't let
me type something like
By year: quietly reg y x1 x2 x3, predict res, residual
As useful as the by: prefix is, this is an example of where a little
bit of Stata programming goes a long way.
forvalues y = 1960/2000 {
qui regress y x1 x2 x3 if year==`y'
qui predict double eps`y' if e(sample), resid
}
If you really want them in different variables. A common variation that
I have used often that stuffs them all into one variable (saves a whole
lot of space) is
gen eps = .
forvalues y = 1960/2000 {
qui regress y x1 x2 x3 if year==`y'
tempvar temp
qui predict double `temp' if e(sample), resid
qui replace eps = `temp' if e(sample)
}
Note that the 'if e(sample)' will generate residuals only for in-sample
observations; e.g. if there are 1960 obs that do not enter the
regression due to missing values in the reglist, they will not have
residuals.
Kit Baum, Boston College Economics [email protected]
http://ideas.repec.org/e/pba1.html
*
* 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/