Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: Re: st: Keep longest consecutive streak in panels


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: Re: st: Keep longest consecutive streak in panels
Date   Fri, 14 Jan 2005 18:14:17 -0000

More instructive in some ways is to 
do it from scratch, with no use of user
add-ons. Something like 

gen spell = sum(L.time == .) 
bysort firm spell : gen length = _N 
bysort firm length (time) : keep if spell == spell[_N] 

Nick 
[email protected] 

Nick Cox
 
> I would try -tsspell- from SSC. 
> 
> Assuming 
> 
> . tsset firm time 
> 
> 
> then get the spells 
> 
> . tsspell, fcond(L.time == .) 
> 
> get the lengths  
> 
> . egen length = max(_seq), by(firm _spell) 
> 
> keep the longest 
> 
> . bysort firm (length time) : keep if _spell == _spell[_N] 
> 
> [not tested] 

LACHENMAIER
 
> >  thanks for the quick answer. I have not found the problem in the
> > Statalist Archive yet. But I will have a closer look then. To your
> > question: In the case of two streaks of equal length I would want to
> > keep the newer one. I think this could be done in a second step.
 

*
*   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