Announcement

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

  • creating an age variable

    I want to create an age variable from a head of household date of birth variable (HOH_DOB) and a YearMonth date variable (BeneMonth_date). I tried the following code, but it is giving me incorrect age values. Is this because my HOH_DOB is in a numeric daily date format and BeneMnth_date is in a numeric monthly date format? if so, how do i get them to be the same format?

    gen HOH_age = ((BeneMonth_date) - HOH_DOB)/365.25
    replace HOH_age = floor(age)

  • #2
    Yes, that is why. Monthly and daily internal format date variables are on very different scales, and you cannot directly combine them in calculations.

    Since you have only monthly information in BeneMonth_date, you cannot get an exact age, but it appears you ultimately only want to truncate it to an integer. Now, if the person's birthday falls in the same month of year as the BeneMonth_date, you cannot even get integer accuracy, because the result will differ by 1 depending on whether the birthdate precedes or follows the BeneMonth_date within the month.

    Probably the best you can do is treat the BeneMonth_date as if it were the first day of that month and calculate the person's age as of the first day of that month. You can get that first day of the month as a daily date using the -dofm()- function.

    Code:
    gen HOH_age = age(HOH_DB, dofm(BeneMonth_date))

    Comment

    Working...
    X