Here is one way:
use http://www-personal.umich.edu/~chooper/stata/rrtest2, clear
tsset id year
gen gap = 0
foreach var of varlist y - x2 {
replace gap = 1 if `var' == .
}
sort id gap
by id: replace gap = gap[_N]
rollreg y x1 x2 if gap == 0, move(5) stub(rr)
Hope this helps,
Scott
> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Cameron Hooper
> Sent: Saturday, March 05, 2005 10:58 PM
> To: [email protected]
> Subject: Re: st: Eliminating gaps
>
> To answer my own question ...
>
> I just came across the tsfill function. I can use this to do what I want.
>
> drop if x1 >= .
> tsfill
> save tmpdata
> drop if x1 < .
> keep id
> duplicates drop id, force
> merge id using tmpdata
> sort id year
> drop if _merge == 3
> drop _merge
>
> If anyone knows a better solution, please let me know.
>
> Cameron
>
*
* 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/