Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Maarten Buis <maartenlbuis@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Determining residuals following adjustment in a regression model |
Date | Wed, 18 Dec 2013 10:11:25 +0100 |
On Wed, Dec 18, 2013 at 6:50 AM, Daniel Herbert Opi wrote: > I am carrying out a regression model and I am interested in > determining the residuals for each single observation. The model is > adjusted for at least one variable. But I realise the residuals > generated in the adjusted model are identical to those in those in the > unadjusted model. That is incorrect as you can see in the example below: *------------------ begin example ------------------ sysuse auto, clear reg price i.foreign i.rep78 predict resid_adj, resid reg price i.foreign predict resid_unadj if rep78 < ., resid scatter resid_adj resid_unadj || /// function reference = x, range(-3200 9900) /// ytitle("adjusted residuals") /// xtitle("unadjusted residuals") *------------------- end example ------------------- * (For more on examples I sent to the Statalist see: * http://www.maartenbuis.nl/example_faq ) > Is there a way of determining residuals that take into account the > adjustment in the model. > > Example of the commands in I've used in stata: > > The adjusted model > xi:regress continous_variable i.variable2 i.variable3 > > The unadjusted model > xi:regress continous_variable i.variable2 > > The prediction command I've used: > predict resid_sample, resid My guess of what happens is that you first estimated both models where the unadjusted model is the last model, and only after that used the predict command. -predict- will use the last model, so when you do this this way you will get the predicted residuals for the unadjusted model. So, to get the residuals you want you first estimate the adjusted model, use -predict- to get the adjusted residuals, only then you estimate the unadjusted model, and you can then use -predict- to get the unadjusted residuals. Also note that you did not tell us which version of Stata you use, so per the Statalist FAQ we assume you use the latest version (13). In that case it would be better not to use the -xi:- prefix. Instead you should use the factor variable notation, see -help fvvarlist-. In this case it is simple: just remove the -xi:- part from your commands and leave everything else unchanged. Hope this helps, Maarten --------------------------------- Maarten L. Buis WZB Reichpietschufer 50 10785 Berlin Germany http://www.maartenbuis.nl --------------------------------- * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/