Hello!
I am using data about households and I am interested in analyzing homeownership and mortgage rates by 2015 age cohorts.
The data I am using are drawn from a survey which started in 1997 and ended in 2017. During this period of time the survey design changed. So from 1997 until 2001 I have the age of the respondent as a continuous variable while starting from 2002 I have a categorical variable made of 15 categories:
  1. 0-5
  2. 6-14
  3. 15-17
  4. 18-24
  5. 25-29
  6. 30-34
  7. 35-39
  8. 40-44
  9. 45-49
  10. 50-54
  11. 55-59
  12. 60-64
  13. 65-69
  14. 70-74
  15. 75 and more
For data from 1997 until 2001 I defined a program to extract the cohorts as follows (age_var is the age of the respondent while year is the year in which she took part to the survey) but I am having trouble in defining the cohorts using the categorical variable. Do you have any suggestions on how to do this?
Code:
cap program drop create_agecohort
program define create_agecohort
        args age_var year
        local cohort_var "cohort"
        cap drop cohort age_group
        gen cohort = `age_var'-`year'+2015
        qui gen age_group = 1 if (`cohort_var' >=10 & `cohort_var' <=30)
        qui replace age_group = 2 if (`cohort_var' >=31 & `cohort_var' <=40)
        qui replace age_group = 3 if (`cohort_var' >=41 & `cohort_var' <=50)
        qui replace age_group = 4 if (`cohort_var' >=51 & `cohort_var' <=60)
        qui replace age_group = 5 if (`cohort_var' >=61 & `cohort_var' <=70)
        qui replace age_group = 6 if (`cohort_var' >=71 & `cohort_var' ~= .)
end
Thank you for your help.