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
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Identifying the second occurrence of event in panel data
Date
Wed, 14 Aug 2013 11:33:02 +0100
It is the same idea. -noccur- gets bumped up (increased by 1) every
time there is a new event. So, within panels, you want (a) -noccur- to
equal 2, but (b) only the first such observation.
by pid: gen byte first = noccur == 2
gets (a) and
by pid: gen byte first = noccur == 2 & noccur[_n-1] != noccur
gets you both (a) and (b). In general, someone's record could be
a block of 0s for -noccur- if they start out employed
a block of 1s for -noccur- starting at the first time employed
a block of 2s for -noccur- starting at the second time employed
Nick
[email protected]
On 14 August 2013 10:52, Daniel Sage <[email protected]> wrote:
> 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/
*
* 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/