Announcement

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

  • Generate of missing values when creating date variables using the mdy command

    Hi All,

    I have date variable in this format (M/D/Y).
    I want to change it to a numeric format like 13149.
    I have tried to run the following command and STATA output is as follows.


    . gen stdate=mdy(stmo, stdy, styr)
    (4 missing values generated)

    . list styr stmo stdy xityr xitmo xitdy if stdate==.
    +---------------------------------------------+
    | styr stmo stdy xityr xitmo xitdy |
    |---------------------------------------------|
    4789. | 1974 2 29 2018 12 31 |
    44691. | 1997 2 29 2013 1 23 |
    46976. | 1998 2 29 2018 12 31 |
    65341. | 2001 2 29 2018 12 31 |
    +---------------------------------------------+

    . gen pd=xitdat-stdate
    (4 missing values generated)

    . gen py=pd/365.25
    (4 missing values generated)


    I tried solve the problem by generating a new variable as suggested in many threads in this forum.
    I don't know why four values turn into missing in the new created variable.

    Is anybody here who can help me with this issue?

    Thank you for your time and insights.
    Ye Jin Bang

  • #2
    The missing values arise because there were no such dates.

    .ÿforeachÿyearÿinÿ1974ÿ1997ÿ1998ÿ2001ÿ{
    ÿÿ2.ÿdisplayÿinÿsmclÿasÿtextÿ%tdCY-N-Dÿlastdayofmonth(mdy(2,ÿ1,ÿ`year'))
    ÿÿ3.ÿ}
    1974-02-28
    1997-02-28
    1998-02-28
    2001-02-28

    .


    I recommend going back to your source for the dataset and asking for corrections to it.

    Comment


    • #3
      Otherwise put, 29 February is a date that occurs only in leap years.

      Comment

      Working...
      X