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

st: Re: consecutive obs


From   Christopher F Baum <[email protected]>
To   [email protected]
Subject   st: Re: consecutive obs
Date   Tue, 12 Oct 2004 07:32:17 -0400

On Oct 12, 2004, at 2:33, Roberto wrote:


with the tsspell command I have been able to identify the maximum number of
consecutive observations per firms.
The problem is that if I write
keep if maxrun>=5
stata only drops firm "C" whereas I would want it to drop all the
non-consecutive observations in all panels so that the database would look
like:
You're almost there. Here is a snippet of code in which I wanted to drop spells in which there were two years' consecutive net cash flow (gvkey is the firm id):

* screen2: use tsspell to find spells of at least two years negative CF
tsset
tsspell , cond(data13 < 0)
* the spells must be at least length 2
bysort gvkey _spell : egen _length = max(_seq)
gen byte todrop = _length >= 2
* drop the firm-years identified by todrop
drop if (todrop)

You want to reverse the logic and keep spells that satisfy a condition on firm# and _seq, as defined by tsspell.

Kit Baum, Boston College Economics [email protected]
http://ideas.repec.org/e/pba1.html

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