Bookmark and Share

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: Re: How do I create a calendar year variable by person id before reshaping to person-year dataset?


From   Holly E Reed <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Re: How do I create a calendar year variable by person id before reshaping to person-year dataset?
Date   Thu, 6 Feb 2014 20:31:52 +0000

Hi Nick,

Here is an extract from the dataset:

i_weight    masterid  birth1  birth2  birth3  birth4  hhid  id  provage12  urbanage12  evermig  relation              sex  age  cyear1  cyear2  cyear 3  yrbirth  yrdate
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1979
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1980
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1981
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1982
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1983
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1984
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1985
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1986
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1987
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1988
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1989
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1990
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1991
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1992
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1993
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1994
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1995
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1996
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1997
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1998
37.64478   43           1998  .         .         .          4     17  "E Cape"   "Rural"         1           "Son/Daughter"   "F"  21    1908    1909     1910      1979    1999
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1982
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1983
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1984
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1985
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1986
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1987
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1988
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1989
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1990
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1991
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1992
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1993
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1994
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1995
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1996
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1997
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1998
37.64478   54           .        .         .         .          5     23  "W Cape"  "Urban"        0           "Son/Daughter"   "F"  18    1908    1909     1910      1982    1999
37.64478   111         1955  1959   1964  1966    11    51   "E Cape"   "Rural"        1            "Head"               "F"  67    1908    1909     1910      1933    1933
37.64478   111         1955  1959   1964  1966    11    51   "E Cape"   "Rural"        1            "Head"               "F"  67    1908    1909     1910      1933    1934
37.64478   111         1955  1959   1964  1966    11    51   "E Cape"   "Rural"        1            "Head"               "F"  67    1908    1909     1910      1933    1935
37.64478   111         1955  1959   1964  1966    11    51   "E Cape"   "Rural"        1            "Head"               "F"  67    1908    1909     1910      1933    1936
37.64478   111         1955  1959   1964  1966    11    51   "E Cape"   "Rural"        1            "Head"               "F"  67    1908    1909     1910      1933    1937
37.64478   111         1955  1959   1964  1966    11    51   "E Cape"   "Rural"        1            "Head"               "F"  67    1908    1909     1910      1933    1938
37.64478   111         1955  1959   1964  1966    11    51   "E Cape"   "Rural"        1            "Head"               "F"  67    1908    1909     1910      1933    1939
37.64478   111         1955  1959   1964  1966    11    51   "E Cape"   "Rural"        1            "Head"               "F"  67    1908    1909     1910      1933    1940

And so on...So these are three women, first is age 21, with one birth in 1998; second is age 18, with no births; third is 67 years old, with four births (she actually had seven, but I didn't show all birth* variables here to save space) in 1955, 1959, 1964, and 1966.  

I only listed birth1-birth4, but in fact there are birth 1-birth10 which follow along the same lines.  Also cyear1-cyear93 are in the dataset; same for each person and each year 1908-2000.

In terms of code, I have tried three iterations of coding for the reshape command:

reshape long birth, i(id) j(year)

reshape long birth cyear, i(id) j(year)

AND
reshape wide birth, i(id) j(year)

Hoping that this helps to clarify things a bit...any ideas?

Thanks,
Holly
_______________________________________________
From	  Nick Cox <[email protected]>
To	  "[email protected]" <[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 19:30:53 +0000
 Without seeing exactly the kind of data and exactly the kind of code
that produce problems, it is very hard to comment further. We are not
asking to see the whole dataset, but enough that is concrete to
understand your problem.

If you have variables -birth*- then -reshape wide birth- will
inevitably fail, but why -reshape long- will fail is unclear.

Nick
[email protected]
________________________________________
From: Holly E Reed
Sent: Thursday, February 06, 2014 1:27 PM
To: [email protected]
Subject: Re: How do I create a calendar year variable by person id before reshaping to person-year dataset?

Hi Ronnie,

Thanks for your reply.  That is, in fact, exactly what my data look like; of course, some people do not have births, so they have missing values for birth1, birth2, etc. or if they only have one child, they have missing values for all birth variables except birth1.

The dataset is so large and there are a number of variables in addition to the ones listed, such as weights, region at age 12, urban/rural at age 12, relationship to HH head, ever migrated...that's why I didn't post a sample of the actual dataset.

Thanks,
Holly
_______________________________________________________


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index