Announcement

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

  • Creating age variable from date of birth

    Hi,
    My data has a birthday variable that I need to convert into age. I've spent some time researching and trying different options, but for some reason, I wasn't able to do so.

    Code:
    clear
    input long id double birthdate
    658434  2.374452e+11
    658442  3.366324e+11
    658443  1.474164e+11
    658449 1.0698264e+12
    658453   8.80524e+11
    658481  4.694328e+11
    658499  2.720916e+11
    658511 -3.924972e+11
    658516  4.042836e+11
    658554 -4.187628e+11
    658571  2.077632e+11
    658576   4.52322e+11
    658577 -4.264524e+11
    658579  -8.35308e+10
    658582  7.777044e+11
    658616    3.8988e+10
    658621 -5.313384e+11
    658633  -3.99852e+10
    658659  4.171203e+11
    658677 -3.253644e+11
    end
    format %tc birthdate
    Thank you.

  • #2
    You need the date on which the survey was held. Assuming that was 2017, then you would get the age with: gen age = 2017 - year(dofc(birthdate))


    The relevant helpfile is: help datetime
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you. That was really helpful.

      Comment

      Working...
      X