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]
Nick
[email protected]
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/