Statalist


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

Re: st: multiple rolling regressions


From   "Erasmo Giambona" <e.giambona@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: multiple rolling regressions
Date   Fri, 9 May 2008 17:46:28 +0200

Sorry Austin. Here are the codes and outputs for my questions 1 and 2.

Question 1:

clear
input firm year y x
1 1980 20 23
1 1981 22 34
1 1982 20 19
1 1984 22 34
1 1985 20 19
1 1986 28 34
1 1987 30 19
1 2004 33 45
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

fillin firm year

tsset firm year
sort firm year
g double d=.
qui forv i=3/`=_N-2' {
 loc f=`i'-2
 loc l=`i'+2

 if firm[`f']==firm[`i'] & firm[`l']==firm[`i'] {

 reg y year in `f'/`l' if firm==firm[`i']

 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 `l'

 drop ye xe
 }
 }
li, noo sepby(firm)


  +----------------------------------------------+
  | firm   year    y    x   _fillin            d |
  |----------------------------------------------|
  |    1   1980   20   23         0            . |
  |    1   1981   22   34         0            . |
  |    1   1982   20   19         0            . |
  |    1   1983    .    .         1            . |
  |    1   1984   22   34         0    .13832633 |
  |    1   1985   20   19         0    .13333333 |
  |    1   1986   28   34         0    .24102564 |
  |    1   1987   30   19         0    .26666667 |
  |    1   2004   33   45         0   -.02459217 |
  |----------------------------------------------|
  |    2   1980   15   23         0            . |
  |    2   1981   55   34         0            . |
  |    2   1982   29   19         0            . |
  |    2   1983   15   23         0            . |
  |    2   1984   55   34         0    2.4384318 |
  |    2   1985   29   19         0    2.0094206 |
  |    2   1986   28   34         0    1.2739234 |
  |    2   1987   30   19         0    1.0499124 |
  |    2   2004    .    .         1    .36666667 |
  +----------------------------------------------+

.
Question 2:

clear
input firm year y x
1 1984 1.061948 3.49672
1 1985 1.83066 4.003654
2 1984 0.5492768 2.696585
2 1985 0.5056121 3.226407
2 1986 1.076026 3.619208
2 1987 -0.3400373 3.646911
2 1988 -1.6812 3.520697
2 1989 -1.200567 3.008994
end

fillin firm year

tsset firm year
sort firm year
g double d=.
qui forv i=3/`=_N-2' {
 loc f=`i'-2
 loc l=`i'+2

 if firm[`f']==firm[`i'] & firm[`l']==firm[`i'] {

 reg y year in `f'/`l' if firm==firm[`i']

 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 `l'

 drop ye xe
 }
 }
li, noo sepby(firm)



  +--------------------------------------------------+
  | firm   year           y          x   _fillin   d |
  |--------------------------------------------------|
  |    1   1984    1.061948    3.49672         0   . |
  |    1   1985     1.83066   4.003654         0   . |
  |    1   1986           .          .         1   . |
  |    1   1987           .          .         1   . |
  |    1   1988           .          .         1   0 |
  |    1   1989           .          .         1   . |
  |--------------------------------------------------|
  |    2   1984    .5492768   2.696585         0   . |
  |    2   1985    .5056121   3.226407         0   . |
  |    2   1986    1.076026   3.619208         0   . |
  |    2   1987   -.3400373   3.646911         0   . |
  |    2   1988     -1.6812   3.520697         0   . |
  |    2   1989   -1.200567   3.008994         0   . |
  +--------------------------------------------------+

.
.








On Fri, May 9, 2008 at 5:31 PM, Austin Nichols <austinnichols@gmail.com> wrote:
> Did you leave out the -fillin- command I added after you mentioned you
> might have gaps in years?  I am just guessing--as you are still asking
> incomplete questions (per the Statalist FAQ: show what you typed and
> what output you got).
>
> On Fri, May 9, 2008 at 6:20 AM, Erasmo Giambona <e.giambona@gmail.com> wrote:
>> Thanks Austin. There is still something I don't quite grasp. Thanks in
>> advance for your patience. 1. If I insert another row of data for firm
>> 1 in the dataset from your example, say: 1 2004 33 45, then I noticed
>> that the code does not create missing values from 1988-2003, but
>> rather uses data from 1984-1987 and 2004 to estimate d for 2004, while
>> I would like to get a missing d in this case; 2. When I run the code
>> with my data I cannot obtain any results, despite the fact that the
>> data look very similar to the example at least to me. Here is an
>> excerpt from the real data:
>>
>> 1 1984 1.061948 3.49672
>> 1 1985 1.83066 4.003654
>> 2 1984 0.5492768 2.696585
>> 2 1985 0.5056121 3.226407
>> 2 1986 1.076026 3.619208
>> 2 1987 -0.3400373 3.646911
>> 2 1988 -1.6812 3.520697
>> 2 1989 -1.200567 3.008994
> *
> *   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/



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