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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Re: residuals for each year |

Date |
Sun, 17 Oct 2004 16:56:15 +0100 |

Something like this would be my preferred approach. What may not be apparent is that each call to tempvar temp invokes a new temporary variable, which you can now refer to it as (clearly) `temp'; any and all temporary variables previous Nick n.j.cox@durham.ac.uk > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of > Christopher F > Baum > Sent: 17 October 2004 13:15 > To: statalist@hsphsun2.harvard.edu > Subject: st: Re: residuals for each year > > > 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 baum@bc.edu > 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/ > * * 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:
**st: still having problems with converting string variables** - Next by Date:
**st: RE: Re: residuals for each year** - Previous by thread:
**st: still having problems with converting string variables** - Next by thread:
**st: RE: Re: residuals for each year** - Index(es):

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