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

# RE: st: Combining residuals of multiple regressions

 From roderick To "statalist@hsphsun2.harvard.edu" Subject RE: st: Combining residuals of multiple regressions Date Wed, 19 Feb 2014 13:49:05 +0100

```Thank you so much!

----------------------------------------
> Date: Wed, 19 Feb 2014 07:30:21 -0500
> From: feenberg@nber.org
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: Combining residuals of multiple regressions
>
>
> On Wed, 19 Feb 2014, roderick wrote:
>
>> Dear Stata community,
>>
>> For my thesis, I am running US-state-specific regressions and saving the state-specific residuals. The commands for the first two regressions look as follows (the variables shown are just for illustration purposes):
>>
>> regress accidentsvso unemp if(state==1)
>> predict res1 if(state==1), r
>> regress accidentsvso unemp if(state==4)
>> predict res4 if(state==4), r
>>
>> Now, I would like to create a variable that captures the residuals of all these regressions. So, I want to 'merge' all state-specific residuals and put them in into one list (as can be seen here>> http://i60.tinypic.com/9ptceo.png; I want the seventh column to contain all residuals).
>>
>
> Try -rowmean- function of the -egen- command.
>
> (from the -egen- helpfile):
>
> rowmean(varlist)
> may not be combined with by. It creates the (row) means of
> the variables in varlist, ignoring missing values; for
> example, if three variables are specified and, in some observations,
> one of the variables is missing, in those observations newvar will
> contain the mean of the two variables that do exist...
>
> Dan Feenberg
> NBER
> *
> * 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/
*
*   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/
```