Announcement

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

  • Combining separate day month year string variables to one dob variable

    Hello,

    I have three variables (birth_day_child birth_month_child birth_year_child) which I need to convert to numeric variables, and combine to create a date of birth variable (dob).

    I am not sure how to do it.

    Thank you.

  • #2
    If your variables are currently string, show us examples. Please read and act on FAQ Advice #12 to learn how.

    If your variables are really numeric, you can proceed to

    Code:
    gen bdate = mdy(birth_month_child, birth_day_child,  birth_year_child)
    format bdate %td
    Resources you should be using:

    Code:
    help datetime
    
    
    help mdy()
    
    
     mdy(M,D,Y)
           Description:  the e_d date (days since 01jan1960) corresponding to M, D, Y
           Domain M:     integers 1 to 12
           Domain D:     integers 1 to 31
           Domain Y:     integers 0100 to 9999 (but probably 1800 to 2100)
           Range:        %td dates 01jan0100 to 31dec9999 (integers -679,350 to 2,936,549) or missing
    Last edited by Nick Cox; 15 Apr 2018, 03:33.

    Comment


    • #3
      destring does allow you to work on several variables at once. You could also do something like.

      Code:
      gen child_dob = mdy(real(month), real(day), real(year))
      or

      Code:
      gen child_dob = daily (month + day + year, "MDY")

      Comment

      Working...
      X