[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Erasmo Giambona" <e.giambona@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: multiple rolling regressions |

Date |
Thu, 8 May 2008 19:21:53 +0200 |

Hi Austin, Thanks very much. Your code really gets me very very close to what I want to achieve. Here are some additional clarifications that you required. Yes, I am only interested in saving the estimated coefs d of reg ye xe. If there are missing data in the 5 year window, I would still like to get the estimates with whatever data is available. If there are gaps, for instance for a company I have data for the window 1980-1984 and 1990-1994, then I would like to get estimates for the first window and independently for the second window. I noticed that you code calculates d based on observations from -2 to +2. This is what I get if I run it: +-----------------------------------+ | firm year y x d | |-----------------------------------| | 1 1980 20 23 . | | 1 1981 22 34 . | | 1 1982 20 19 .15129763 | | 1 1983 20 23 .1403674 | | 1 1984 22 34 .24162679 | | 1 1985 20 19 .15236427 | | 1 1986 28 34 . | | 1 1987 30 19 . | |-----------------------------------| For instance, d=.15129763 for 1982 is based on data from 1980-1984. What I would really like to achieve is for instance that d for 1984 is based on the data from 1980-1984. Hope you can provide some additional hints on how I could obtain what I need. Thanks very much, Erasmo On Thu, May 8, 2008 at 4:21 PM, Austin Nichols <austinnichols@gmail.com> wrote: > 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/ > * * 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/

**Follow-Ups**:**Re: st: multiple rolling regressions***From:*"Austin Nichols" <austinnichols@gmail.com>

**References**:**st: multiple rolling regressions***From:*"Erasmo Giambona" <e.giambona@gmail.com>

**Re: st: multiple rolling regressions***From:*"Erasmo Giambona" <e.giambona@gmail.com>

**Re: st: multiple rolling regressions***From:*"Austin Nichols" <austinnichols@gmail.com>

- Prev by Date:
**Re: st: Create dataset of variable names and variable labels** - Next by Date:
**Re: st: multiple rolling regressions** - Previous by thread:
**Re: st: multiple rolling regressions** - Next by thread:
**Re: st: multiple rolling regressions** - Index(es):

© Copyright 1996–2017 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |