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: RE: How do I create a calendar year variable by person id before reshaping to person-year dataset?
From
Ronnie Babigumira <[email protected]>
To
[email protected]
Subject
Re: st: RE: How do I create a calendar year variable by person id before reshaping to person-year dataset?
Date
Thu, 6 Feb 2014 09:40:12 +0100
Showing an example of the actual data you are trying to reshape will
help because, following your previous posting, the solution Maarten
shared, and this new information about birth1---10, this is what you
would be trying to reshape.
id age sex birthyear year birth1 birth2
1 5 F 1995 1995 2010 2012
1 5 F 1995 1996 2010 2012
1 5 F 1995 1997 2010 2012
1 5 F 1995 1998 2010 2012
1 5 F 1995 1999 2010 2012
2 3 M 1997 1997 2012 2013
2 3 M 1997 1998 2012 2013
2 3 M 1997 1999 2012 2013
3 10 F 1998 1998 2009 2011
I doubt that your data look like this
Ronnie
On Wed, Feb 5, 2014 at 8:23 PM, Holly E Reed <[email protected]> wrote:
> Thank you for your help, Maarten. It worked great. But now I am receiving error messages when I try to reshape the data. No matter how I reshape, it tells me that the data are already in that format: "Data are already wide" or "Data are already long" I have tried to do this several times, but with no luck yet.
>
> This is my code:
>
> reshape wide birth, i(id) j(year)
>
> birth is a variable with suffix 1-10 (e.g., birth1, birth2, birth3, etc.) which is the year of a woman's first birth, second birth etc.
>
> Sometimes the error message says "variable year not found"; I thought that year was a new variable that would be created? And once it said "i=id does not uniquely identify the observations; there are multiple observations with the same value of id." But I thought that was the point!?
>
> If you can shed some light on these issues, I would appreciate it!
> Thanks, Holly
> _____________________________________
>
> 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
> __________________________________________
> Does the age of the person increase each year?
>
> If so, you could use:
> gen year = age+birthyear
>
> If age does not increase each year, how do you know which year an
> observation belongs to?
> For example, how do you know the records aren't sorted like this:
>
> id age sex birthyear year
> 1 5 F 1995 1999
> 1 5 F 1995 1998
> 1 5 F 1995 1997
> 1 5 F 1995 1996
> 1 5 F 1995 1995
>
>
> Mike
>
> _______________________________________
> From: Holly E Reed
> Sent: Wednesday, February 05, 2014 12:03 PM
> To: [email protected]
> Subject: How do I create a calendar year variable by person id before reshaping to person-year dataset?
>
> 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/
*
* 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/