Announcement

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

  • String to Date--missing values

    I am trying to generate a date variable from a string variable (AnnouncementDate). Unfortunately, my code generates missing values for some observations. Here is my code:
    Code:
    gen date2 = date(AnnouncementDate, "DMY")
    format date2 %td
    and data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str10 AnnouncementDate
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/12/2016"
    " 1/13/1981"
    " 1/13/1981"
    " 1/13/1982"
    " 1/13/1982"
    " 1/13/1983"
    " 1/13/1983"
    " 1/13/1983"
    " 1/13/1983"
    " 1/13/1983"
    " 1/13/1983"
    " 1/13/1984"
    " 1/13/1984"
    " 1/13/1984"
    " 1/13/1984"
    " 1/13/1984"
    " 1/13/1984"
    " 1/13/1984"
    end
    Thanks in advance.

  • #2
    Those dates look MDY to me, not DMY. 1/12 could be either, but what tells the tale is 1/13, which can only be 13 January.

    Comment


    • #3
      Sorry for posting a stupid question. The AnnouncementDate variable is in month-date-year format. So, the appropriate code would be
      Code:
      gen date2 = date(AnnouncementDate, "MDY")
      format date2 %td

      Comment

      Working...
      X