Bookmark and Share

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


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

Re: st: Cycling Through Regressions and Storing Residuals


From   Joerg Luedicke <[email protected]>
To   [email protected]
Subject   Re: st: Cycling Through Regressions and Storing Residuals
Date   Wed, 13 Feb 2013 18:18:22 -0500

Consider the following example, assuming -industry- ranges from 1 to
12 with delta 1:

*--------------------------
webuse nlsw88, clear

gen myresid = .

forval i = 1/12 {
	reg wage hours if industry == `i'
	predict t if e(sample), resid
	replace myresid = t if e(sample)
	drop t
}
*--------------------------

Joerg


On Wed, Feb 13, 2013 at 4:42 PM, FINERTY A.J.J.
<[email protected]> wrote:
> Dear Statalist members,
>
> I am new to Stata (and Statalist), so please accept my apologies if this
> question lacks the finesse of one posed by a more seasoned user.
>
> I have panel (longitudinal) data on three variables (not that it's
> relevant, but the variables are output, general government consumption
> and general government investment). Each of these variables is observed
> over 21 countries and a maximum of 99 time periods.
>
> For each country, I want to de-trend each variable quadratically, i.e. I
> want to find the residuals of the regression for each country (denoted
> by the variable id, ranging from 1 to 21) of e.g. output on time and
> time^2.
>
> I'm sure that this must be a common sort of thing to want to do and that
> there's some way to implement a foreach loop, but I can't work out what
> it is.
>
> One potential complication is that the data are unbalanced; output,
> consumption and investment data are not available for every country in
> every time period.
>
> I would be most grateful if anyone could help.
>
> Best wishes,
>
> Alistair Finerty.
>
> *
> *   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/


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