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: How do I create a calendar year variable by person id before reshaping to person-year dataset?
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: How do I create a calendar year variable by person id before reshaping to person-year dataset?
Date
Wed, 5 Feb 2014 18:13:45 +0100
by id : gen year = birthyear + _n -1
also look at -help stsplit- as that command is there for creating such datasets.
Hope this helps,
Maarten
On Wed, Feb 5, 2014 at 6:03 PM, Holly E Reed <[email protected]> wrote:
> Hi,
>
> I am trying to create a person-year dataset for event history analysis. The dataset currently has one observation per person per year of their life, e.g.:
>
> id age sex birthyear
> 1 5 F 1995
> 1 5 F 1995
> 1 5 F 1995
> 1 5 F 1995
> 1 5 F 1995
> 2 3 M 1997
> 2 3 M 1997
> 2 3 M 1997
>
> So person with id==1 is a 5-year old female born in 1995 and person with id==2 is a 3-year old male born in 1997. This is a simplified example to illustrate the dataset, as they are all adults and there are far more observations for each individual.
>
> The problem is that I have age and birthyear variables, but I want to create a calendar year variable before reshaping the data to person-year data. What is the easiest way to do this? In other words, I want the dataset to look like this:
>
> id age sex birthyear year
> 1 5 F 1995 1995
> 1 5 F 1995 1996
> 1 5 F 1995 1997
> 1 5 F 1995 1998
> 1 5 F 1995 1999
> 2 3 M 1997 1997
> 2 3 M 1997 1998
> 2 3 M 1997 1999
>
> Thank you very much for any help you can give me!
> Holly
>
> *
> * 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/
--
---------------------------------
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/