Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Combining residuals of multiple regressions |
Date | Wed, 19 Feb 2014 12:57:32 +0000 |
What is often easier is something like this gen residual = . forval i = 1/50 { regress accidentsvso unemp if state == `i' quietly predict work, res quietly replace residual = work if state == `i' drop work } Nick njcoxstata@gmail.com On 19 February 2014 12:49, roderick <roderickstokx@live.nl> wrote: > 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/ * * 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/