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]
st: Identifying the second occurrence of event in panel data
From
Daniel Sage <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Identifying the second occurrence of event in panel data
Date
Wed, 14 Aug 2013 10:52:20 +0100
Hello,
I have panel data and wish to record the second occurrence of an event. The event is unemployment. So for example I want to do the following:
ID YEAR UNEMPLOYED FIRST SECOND
1 1 0 0 0
1 2 1 1 0
1 3 1 0 0
1 4 0 0 0
1 5 0 0 0
1 6 0 0 0
1 7 1 0 1
1 8 1 0 0
1 9 1 0 0
1 10 1 0 0
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. Any help and explanations very welcome.
Daniel
--
The University of Stirling is ranked in the top 50 in the world in The Times Higher Education 100 Under 50 table, which ranks the world's best 100 universities under 50 years old.
The University of Stirling is a charity registered in Scotland,
number SC 011159.
*
* 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/