Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: consecutive years
From
Maarten buis <[email protected]>
To
[email protected]
Subject
Re: st: consecutive years
Date
Mon, 18 Oct 2010 14:04:35 +0100 (BST)
--- On Mon, 18/10/10, Biljana Dlab wrote:
> However this code results that for some firms I have two
> (or more) strings with consecutive years - both these strings are 4
> or more consecutive years long.
> I would like to indentify such a cases and I would like to
> keep both (all) string, but under modified "firm" (i.e. original firm
> number + 1)
In that case I would typically create another id variable, one identifying
firms, and a new one identifying spells. This is how I would do that:
*--------------------- begin example ---------------------
clear
input firm year corr run13 maxrun13
31 1991 -0.5604 1 6
31 1992 -0.5604 2 6
31 1993 -0.5604 3 6
31 1994 -0.5604 4 6
31 1995 -0.5604 5 6
31 2000 -0.5604 1 6
31 2001 -0.5604 2 6
31 2002 -0.5604 3 6
31 2003 -0.5604 4 6
31 2004 -0.5604 5 6
31 2005 -0.5604 6 6
end
tsset firm year
gen break = L.firm == .
bys firm (year) : gen spellid = sum(break)
list
*-------------------- end example ----------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )
If you want you can combine the two id-variables into a single
one using -egen long newid = group(firm spellid), label-
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/