Announcement

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

  • Two digit year to four digit year for date making

    Hello Statalist, I need to use "gen start_date = mdy(month, day, year)" to get a date var. However, the year column is two digits (17) rather than four (2017), which renders the code "mdy" invalid. Is there any way I can change the year column from "17" to "2017"? Tks!

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(month2 day year)
    . .  .
    . .  .
    . .  .
    . .  .
    . .  .
    . .  .
    . .  .
    . .  .
    . .  .
    . .  .
    3 4 17
    3 4 17
    . .  .
    . .  .
    . .  .
    . .  .
    3 4 17
    3 4 17
    3 4 17
    3 4 17
    3 4 17
    3 4 17
    3 4 17
    3 4 17
    3 4 17
    . .  .
    . .  .
    . .  .
    . .  .
    3 4 17
    . .  .
    3 4 17
    . .  .
    3 4 17
    3 4 17
    . .  .
    . .  .
    . .  .
    . .  .
    3 4 17
    . .  .
    . .  .
    . .  .
    end

  • #2
    Code:
    generate int start_dt = mdy(month2, day, 2000 + year)
    format *_dt %tdCY-N-D

    Comment


    • #3
      Thank you, Joseph. The code works!

      Comment

      Working...
      X