[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
DBernstein@lecg.com |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Residuals from sequence of regressions |

Date |
Mon, 18 Oct 2004 13:38:13 -0400 |

Hello, I'm new to replying to messages, so I hope I post this correctly. Anyway, here is a solution to the residual question that should work: If anyone has a more efficient solution, I would be interested in seeing it. levels year, local(Y) gen residual=. for each y of local Y { reg y x1 x2 x3 if year==`y' predict temp, residual replace residual=temp if year==`y' drop temp } Regards, David J. Bernstein, Ph.D. Managing Economist LECG Inc. dbernstein@lecg.com Office: 215-546-4950 ext. 239 Fax: 215-546-3568 Subject: st: Residuals from sequence of regressions 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/ ------------------------------ End of statalist-digest V4 #1765 ******************************** * * 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/ * * 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/

- Prev by Date:
**RE: Macoreconometric dynamic panels (was: Re: st: panel autocorrelation)** - Next by Date:
**RE: st: Residuals from sequence of regressions** - Previous by thread:
**st: Residuals from sequence of regressions** - Next by thread:
**RE: st: Residuals from sequence of regressions** - Index(es):

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