Statalist


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

st: Predicting residuals after regressing


From   Yvonne Capstick <[email protected]>
To   <[email protected]>
Subject   st: Predicting residuals after regressing
Date   Thu, 7 Feb 2008 13:00:22 -0500

Hi,

I am performing regressions company-by-company and would like to save the residuals. I know that you typically use

"predict newvar, residuals"

to do this. However, predict only works immediately after you have run the regression. Since I am regressing company-by-company, rather than on the whole sample, I have to use:

sort companyid
by companyid: reg y x

but I then can't use "predict newvar, residuals" since "predict" only works after the last regression.

Is there a simple way for me to combine "predict" with the "by companyid" form? I know an alternative way to do this would be to use 

gen newvar

forvalues i = 1/10000 {

reg y x if companyid == `i'
predict temp, residuals
replace newvar = temp if temp ~= .
drop temp
}

but I wondered if there is a more elegant way to do this ratehr than hving to loop through all the firms and create and drop a new "temp" variable.

Many thanks,
Yvonne


_________________________________________________________________
Climb to the top of the charts!�Play the word scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan
*
*   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