Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Residuals from sequence of regressions


From   "Alex Edmans" <[email protected]>
To   <[email protected]>
Subject   st: Residuals from sequence of regressions
Date   Sun, 17 Oct 2004 01:35:26 -0400

Hi,

I'm relatively new to Stata, and have a seemingly simple question but,
despite consulting physical and on-line manuals, I have been unable to
answer it so assistance would be appreciated.

I have a large balanced panel of N observations over T years. I would like
to do a cross-sectional regression for each year, and record the residuals
for the regression for each of the N observations for that year. E.g. for
1960, I want each of the N observations to have a new variable which is the
residual from the 1960 cross-sectional regression across the N observations.
Then I want the same for 1961 etc.

I know how to run individual regressions for each year, but I am unsure how
to store the residuals from the regression for each year. To run the
regressions, I type:

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

and typing "predict res, residual" at the end merely gives me the residuals
for the cross-sectional regression for the last year.

Any help would be gratefully received.

Thanks, Alex

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index