Bookmark and Share

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Combining residuals of multiple regressions

From   Daniel Feenberg <>
To   "" <>
Subject   Re: st: Combining residuals of multiple regressions
Date   Wed, 19 Feb 2014 07:30:21 -0500 (EST)

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>>; I want the seventh column to contain all residuals).

Try -rowmean- function of the -egen- command.

(from the -egen-  helpfile):

   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
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index