# Re: st: multiple rolling regressions

 From "Austin Nichols" To statalist@hsphsun2.harvard.edu Subject Re: st: multiple rolling regressions Date Thu, 8 May 2008 10:21:10 -0400

```Erasmo Giambona <e.giambona@gmail.com>:
You haven't said what output you hope to save from this exercise, so
it's impossible to propose an actual solution--did you want to save
the estimated coefs d?  Residuals?

As written, if you go through the whole exercise, the dataset is
unchanged at the end!

Also, why not make the "trend" variable range -2 to 2 for 5 years, so
the intercept is the mean of the depvar?  The residuals are the same
either way, but you can derive and interpret the coefs in the latter
case much more easily.

If you start with some actual fake data (see below) and show what you
hope to end up with, someone is bound to show you how to do it!  If
you just want the estimated coefs d_{it}, and there are no gaps in
year, here's one way to do it:

clear
input firm year y x
1 1980 20 23
1 1981 22 34
1 1982 20 19
1 1983 20 23
1 1984 22 34
1 1985 20 19
1 1986 28 34
1 1987 30 19
2 1980 15 23
2 1981 55 34
2 1982 29 19
2 1983 15 23
2 1984 55 34
2 1985 29 19
2 1986 28 34
2 1987 30 19
end
tsset firm year
sort firm year
g double d=.
qui forv i=3/`=_N-2' {
loc f=`i'-2
loc l=`i'+2
reg y year in `f'/`l' if firm==firm[`i']
if e(N)==5 {
predict double ye if e(sample), resid
reg x year in `f'/`l' if firm==firm[`i']
predict double xe if e(sample), resid
reg ye xe
replace d=_b[xe] in `i'
drop ye xe
}
}
li, noo sepby(firm)

If you have gaps in year (which -tsset- will report above), or missing
data, you will need to specify what you want to do in those cases...

On Thu, May 8, 2008 at 5:50 AM, Erasmo Giambona <e.giambona@gmail.com> wrote:
> Here is my problem:
>
> I have a panel dataset that looks as follows:
>
> firm year y x
> 1 1980 20 23
> 1 1981 22 34
> 1 1982 20 19
> 1 198320 23
> 1 1984 22 34
> 1 1985 20 19
> 1 1986 28 34
> 1 1987 30 19
> ...........
> 2 1980 15 23
> 2 1981 55 34
> 2 1982 29 19
> 2 1983 15 23
> 2 1984  55 34
> 2 1985 29 19
> 2 1986 28 34
> 2 1987 30 19
> .............
> etc.
>
> Assume also that "trend" is a trend variables ranging from 1 to 5.
>
> I need to implement a two-step procedure. In the first step, I run for
> each "firm" a regression of y on the trend variable and an intercept
> and a regression of x on the trend variable and an intercept, using in
> both cases 5 years of data: 1) y = intercept +b*trend + errory;
> 2) x = intercept + c*trend + errorx. After the first step, I output
> the errors from regression 1) and regression 2). Now I regress the
> errors
> from 1) on the errors from 2) (again for each firm): 3) errory =
> d*errorx+error. I repeat the two steps for each year in the sample.
>
> I hope you have some suggestions on how I could handle this issue.
>
> Best regards,
> Erasmo
*
*   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/
```