Statalist


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

RE: st: multiple rolling regressions


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: multiple rolling regressions
Date   Fri, 9 May 2008 16:58:06 +0100

The -fillin- does not work as you hoped because _no_ observations exist
anywhere for years 1988-2003. -fillin- rectangularises, rather than
"fills in"! 

You'd need to fix that by hand by explicitly adding some observations
with those years but missings otherwise. However, for the example data
given here, that sounds futile if I understand what is being tried, as
your gap is too big to be bridged, anyway. 

Erasmo Giambona

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 <[email protected]>
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).
>

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index