Announcement

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

  • Changing date from Str9 to Float

    I am currently trying to change the format of a date variable from a str9 to a float and I am getting a type mismatch error. I was able to successfully change my first variable that was not a str9. Can anyone help me with this? STATA also says, "string %fmt required for string variables", but it will not let me destring this variable.

    The dates are currently reading like "30-Oct-12" and I need them to read "30oct2012"
    . gen endA = dofc(Date_A)
    type mismatch
    r(109);
    Thanks!

  • #2
    help datetime is essential reading here,

    destring
    is useless for string date variables unless exceptionally you have a year such as 2012 given as a string. At most destring could convert your example to 3012, which has less information in it.

    dofc() is for changing a numeric date-time variable (not what you have at all) to a numeric daily date variable.

    I think you need something like

    Code:
    gen wanted = daily(DateA, "DMY", 2025)
    format wanted %td
    We can't see your "first variable" or what you did with it, but I can't be confident that what you did -- while evidently legal -- was correct, so you should show both example data for that variable and what you did,

    Comment

    Working...
    X