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/