Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: Re: Determining residuals following adjustment in a regression model

 From Daniel Herbert Opi To statalist@hsphsun2.harvard.edu Subject st: Re: Determining residuals following adjustment in a regression model Date Thu, 19 Dec 2013 12:48:06 +1100

```Thanks Maarten,

You are right, I seem to have been getting the models mixed up before
the predict command. I have checked and confirmed that the residuals
are indeed different.

I have a follow up question but I think it might fall into a slightly
different heading so I'll send a separate email.

Many thanks
Herbert

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

That is incorrect as you can see in the example below:

*------------------ begin example ------------------
sysuse auto, clear
reg price i.foreign i.rep78
reg price i.foreign
predict resid_unadj if rep78 < ., resid
function reference = x, range(-3200 9900) ///
*------------------- 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
>
> Example of the commands in I've used in stata:
>
> xi:regress continous_variable i.variable2 i.variable3
>
> 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
you estimate the unadjusted model, and you can then use -predict- to

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/
```