  # Re: st: series of regs over adjacent periods

 From Ulrich Kohler To statalist@hsphsun2.harvard.edu Subject Re: st: series of regs over adjacent periods Date Tue, 30 Sep 2003 09:34:26 +0200

```John D. Levendis wrote:
> I'm trying to perform a series of regressions pooled over adjacent years.
> For example, I'd like to do:
>
> regress y x1 x2 if (year == 1980 | year == 1981)
> regress y x1 x2 if (year == 1981 | year == 1982)
> regress y x1 x2 if (year == 1982 | year == 1983)
>
> I realize I could just do a whole bunch of statements like I have done
> above, but I've got a LOT of periods, and I figure there has to be a more
> economical way to do this.
>
> Any suggestions would be appreciated. Thanks in advance.

Use a loop. If your periods ranges from---say--1980 to 2003 you could go on
like this

---------------------------------------------
forvalues i =1984/2003 {
local j = `i' + 1
regress y x1 x2 if inlist(year,`i',`j')
}
---------------------------------------------

If there are any missing periods you are better off by coding

------------------------------------------------
levels year, local(K)
foreach i of local K {
local j = `i' + 1
regress y x1 x2 if inlist(year,`i',`j')
}
------------------------------------------------

However, you will end up with a lot of output by this approach. A further
refinement gives you a dataset with the results of your regression:

-----------------------------------------------------
post b year1 year2 bx1 bx2 using myresults
levels year, local(K)
foreach i of local K {
local j = `i' + 1
regress y x1 x2 if inlist(year,`i',`j')
post b (`i') (`j') (_b[x1]) (_b[x2])
}

use myresults, clear
list
-----------------------------------------------------

Hope this helps

uli

--
kohler@wz-berlin.de

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```