Announcement

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

  • Age calculated from months and years

    Hi,

    I know that many questions have been posted about working with dates in Stata. I have not been able to find an answer to my question, but apologies if this has already been covered. I would like to create a variable reflecting "age at death." I have four variables: birth month (float), birth year (float), death month (byte), death year (integer). Ideally, the "age at death" variable will be formatted as a fraction; 80.5 would be 80 years and 6 months old at death.

    I don't know if I am on the right track. I converted the years and months to dates:

    Code:
    gen ymdobr=ym(bryear,brmonth)     // birth month/year
    gen ymdodth=ym(dthyear,dthmonth)  // death month/year
    I think I can then subtract:

    Code:
    gen agedth = ymdodth - ymdobr
    If that's the correct step (don't know if it is), it is at this point that I am stuck. I probably need to format the agedth variable, since the variable's values currently range from 235 to 1173. As I mentioned, I am hoping that the agedth variable will have the age in years with one or two decimals for the months.

    Thanks for your help,
    Robbie

  • #2
    If that's the correct step (don't know if it is), it is at this point that I am stuck. I probably need to format the agedth variable, since the variable's values currently range from 235 to 1173. As I mentioned, I am hoping that the agedth variable will have the age in years with one or two decimals for the months.
    That was, indeed, the correct step. But you don't need to re-format it: you need to divide it by 12. It is showing you the age at death in months. After all, both ymdobr and ymdodth are in months, so their difference is, too.

    Comment


    • #3
      Thanks Clyde. I am amazed I was that close! I appreciate your help.

      Comment

      Working...
      X