Announcement

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

  • Birth date coded as number of months since a given date

    I have a date of birth variable coded as the number of months elapsed since January 1900. So, for instance, for a person born on January 1901, this variable would take the number 12.
    From this variable, I need to create the actual date of birth, but I am unsure of how to do it efficiently. Any ideas?
    Thank you!

  • #2
    Here is an example. Begin at the "Start here". I set up some trivial data to show that the monthly dates you have can be converted to the calendar birth month by adding back in the offset date (Jan 1900). I am assuming that the number of months you have is already a numeric variable.

    Note: you cannot accurately create a date of birth, because your data are coarsened up to the level of a month, hence my use of birth months, and not birth dates.

    Code:
    input str7 mob
    1901jan
    2023may
    end
    label var mob "month of birth"
    
    gen birthmonth = mofd(date(mob, "YM"))
    format %tm birthmonth
    
    gen have = birthmonth - tm(1900jan)
    
    * start here
    gen want = have + tm(1900jan)
    format %tm want

    Comment

    Working...
    X