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: st: generating lag variable in a Panel Dataset
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: st: generating lag variable in a Panel Dataset
Date
Fri, 3 Feb 2012 10:17:04 +0000
I assume these are Stata (not STATA) daily dates, i.e. numeric date
variables with date formats assigned.
You could use lag operators, but it is as easy or easier to use subscripts
bysort ID (JobNumber) : gen Duration = Start - End[_n-1]
No -if- is involved. The Duration for the first JobNumber will
inevitably be returned as missing.
Nick
On Thu, Feb 2, 2012 at 11:20 PM, Clifton Chow
<[email protected]> wrote:
> I have a panel dataset on employment in which individuals progress between jobs, each with a job start and end date as follows:
>
> ID JobNumber Start End
> 1 1 8/1/10 12/30/10
> 1 2 1/20/11 3/10/11
> 1 3 5/25/11 12/20/11
> 2 1 11/1/10 3/20/11
> 2 2 4/1/11 9/30/11
>
> I am trying to calculate the duration of Unemployment by lagging job end date so that unemployment duration is the date difference between the end of the previous job and the start of the following job. However, I need to carefully generate the lag variable by ID. Is there a way I could do this easily within STATA? For example, something like
>
> gen unempdur=Start - lag(End) if ID = lag(ID) ?
*
* 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/