Bookmark and Share

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   "Biljana Dlab" <[email protected]>
To   <[email protected]>
Subject   RE: st: consecutive years
Date   Tue, 19 Oct 2010 11:35:20 +0200

The following error message is generated:
. tsset firm year
. gen break=L.firm==.
. bys firm(year): gen spellid=sum(break) list
time-series operators not allowed

if list is taken out - again the same error message:
. bys gvkey_n(fyear): gen spellid=sum(break)
time-series operators not allowed




-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Maarten buis
Sent: 18 October 2010 15:05
To: [email protected]
Subject: Re: st: consecutive years

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

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index