Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loop for a variable based on date of birth & interview date

    Hi there,

    I am measuring key variables in my dataset when respondents are 75 years old. To do so, I am matching based on quarter of birth + year of birth + interview month + interview year. The data is in wide form with 9 waves of data.

    For e.g:

    bysort idauniq: gen age_main = .
    bysort idauniq: replace age_main = age_fin1 if yob_fin1 == 1928 & qmonth1 == 1 & iintdaty1 == 2003 & iintdatm1 < 4
    bysort idauniq: replace age_main = age_fin1 if yob_fin1 == 1928 & qmonth1 == 2 & iintdaty1 == 2003 & iintdatm1 > 3 & iintdatm1 < 7
    bysort idauniq: replace age_main = age_fin1 if yob_fin1 == 1928 & qmonth1 == 3 & iintdaty1 == 2003 & iintdatm1 > 6 & iintdatm1 < 10
    bysort idauniq: replace age_main = age_fin1 if yob_fin1 == 1928 & qmonth1 == 4 & iintdaty1 == 2003 & iintdatm1 > 9

    This code will be repeated for yob_fin2-9 (year of birth) for 1929-1938, qmonth2-9 (quarter of birth), iintdaty2-9 (interview year) for 2003-2013 and iintdatm2-9 (interview month). Please, can I get some help on how best to create a loop for this? I've had to omit quarter of birth in the data extract below due to data confidentiality.

    Thanks in advance for your help with this.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(age_fin1 age_fin2 age_fin3 yob_fin1 yob_fin2 yob_fin3) int(iintdaty1 iintdaty2 iintdaty3) byte(iintdatm1 iintdatm2 iintdatm3)
     . 52 54    . 1951 1951    . 2004 2006  .  9  7
     .  .  .    .    .    .    .    .    .  .  .  .
     .  .  .    .    .    .    .    .    .  .  .  .
     . 56 58    . 1948 1948    . 2004 2006  . 12 11
     .  . 66    .    . 1940    .    . 2006  .  .  7
     .  .  .    .    .    .    .    .    .  .  .  .
     .  . 58    .    . 1947    .    . 2006  .  .  9
     .  . 55    .    .    .    .    . 2006  .  . 10
     . 50 52    . 1954 1954    . 2004 2007  . 12  2
     . 54 56    . 1950 1950    . 2004 2006  .  9  7
     .  .  .    .    .    .    .    .    .  .  .  .
     .  . 77    .    . 1929    .    . 2006  .  .  9
     .  . 75    .    . 1931    .    . 2007  .  .  1
     .  .  .    .    .    .    .    .    .  .  .  .
     . 55 56    . 1950 1950    . 2005 2006  .  4 10
     .  .  .    .    .    .    .    .    .  .  .  .
     .  .  .    .    .    .    .    .    .  .  .  .
    67 69  . 1935 1935    . 2002 2005    . 10  2  .
    53  .  . 1948    .    . 2002    .    .  5  .  .
    68  .  . 1934    .    . 2002    .    .  4  .  .
    64 67  . 1937 1937    . 2002 2004    .  7 12  .
    53 55 57 1948 1948 1948 2002 2004 2006  5  9  8
    48 50 52 1954 1954 1954 2003 2005 2007  2  3  2
    70  .  . 1931    .    . 2002    .    .  5  .  .
    67  .  . 1934    .    . 2002    .    .  7  .  .
    52  .  . 1950    .    . 2002    .    .  8  .  .
    72 75 76 1929 1929 1929 2002 2004 2006  4  7  7
    66  .  . 1935    .    . 2002    .    .  7  .  .
    30 32 34 1972 1972 1972 2002 2004 2006  5  7  7
    63 65 67 1939 1939 1939 2002 2004 2006  4  8  7
    34 36 38 1968 1968 1968 2003 2005 2006  1  3 12
    57  .  . 1945    .    . 2003    .    .  2  .  .
    33 35 37 1969 1969 1969 2002 2004 2006  4  8  9
    44  .  . 1957    .    . 2002    .    .  5  .  .
    51 53 55 1951 1951 1951 2002 2004 2006  7 10  6
    43 45  . 1959 1959    . 2002 2005    .  9  1  .
    53 55 57 1949 1949 1949 2002 2004 2006  9 12 10
    56 58 60 1946 1946 1946 2002 2005 2006  9  1 11
    56 58 60 1946 1946 1946 2002 2005 2007  9  3  1
    55 57 59 1947 1947 1947 2002 2005 2006 11  4 11
    65 67 69 1937 1937 1937 2002 2005 2006 12  2 12
    67 69 71 1935 1935 1935 2002 2004 2006  8 11  6
    41  .  . 1961    .    . 2003    .    .  1  .  .
    55 58  . 1946 1946    . 2002 2004    .  4  9  .
    36  .  . 1965    .    . 2002    .    .  6  .  .
    50  . 53 1953    . 1953 2003    . 2006  1  . 11
    50 53  . 1952 1952    . 2002 2005    .  9  3  .
    50 52  . 1952 1952    . 2002 2005    .  6  4  .
    49  .  . 1952    .    . 2002    .    .  5  .  .
    72  .  . 1930    .    . 2002    .    .  4  .  .
    end

    Many thanks
    Karen

  • #2
    Just following up whether anyone has any ideas on how to do this? Much appreciated!

    Comment

    Working...
    X