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: Identifying the second occurrence of event in panel data
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Identifying the second occurrence of event in panel data
Date
Wed, 14 Aug 2013 12:31:55 +0200
On Wed, Aug 14, 2013 at 11:52 AM, Daniel Sage wrote:
>
> I have panel data and wish to record the second occurrence of an event. The event is unemployment.
> I am able to identify the first occurrence of unemployment using the following:
>
> by pid (wav), sort: gen noccur = sum(unemployed)
> by pid: gen byte first = noccur == 1 & noccur[_n-1] != noccur
>
> But I am unsure how to identify the second occurrence.
*------------------ begin example ------------------
clear
input id year unemployed
1 1 0
1 2 1
1 3 1
1 4 0
1 5 0
1 6 0
1 7 1
1 8 1
1 9 1
1 10 1
2 1 0
2 2 1
2 3 1
2 4 0
2 5 0
2 6 0
2 7 1
2 8 1
2 9 1
2 10 1
end
tsset id year
bys id (year): gen change = unemployed == 1 & L.unemployed == 0 if _n >1
bys id (year):gen spell = sum(change) if change == 1
list, sepby(id)
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )
Hope this helps,
Maarten
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/