Statalist


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

Re: st: multiple rolling regressions


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: multiple rolling regressions
Date   Fri, 9 May 2008 14:04:46 -0400

Erasmo--this problem seems constantly to have a "new" wrinkle.  Try this:

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 48
      1 2005 30 45
      1 2006 35 50
      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
su year, meanonly
loc ny=r(max)-r(min)+1
loc fy=r(min)
tempfile allyrs
preserve
drop _all
set obs `ny'
g year=`fy'+_n-1
save `allyrs'
restore
append using `allyrs'
fillin firm year
drop if mi(firm)
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'] {
 cap reg y year in `f'/`l' if firm==firm[`i']
 if _rc==0 {
 if e(N)>2 {
  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)

On Fri, May 9, 2008 at 11:58 AM, Nick Cox <[email protected]> wrote:
> 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.
*
*   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