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

From |
Christopher F Baum <baum@bc.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Re: residuals for each year |

Date |
Sun, 17 Oct 2004 08:14:56 -0400 |

On Oct 17, 2004, at 2:33, Alex wrote:

As useful as the by: prefix is, this is an example of where a little bit of Stata programming goes a long way.

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

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/

- Prev by Date:
**st: Re: printing graphs to PDF** - Next by Date:
**st: still having problems with converting string variables** - Previous by thread:
**st: Re: printing graphs to PDF** - Next by thread:
**st: still having problems with converting string variables** - Index(es):

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