Announcement

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

  • Converting Date/Time to Numeric Returns Missing Values

    Hi all,

    I have run successfully converted other strings in my dataset using this code, but for this variable it only returns missing values. I've tried a few things, listed below. For reference the shift_start variable looks like this:

    shift_start
    17-May-82 13:00:00

    generate double num_shift_start = clock(shift_start, "DMYhm")

    generate double num_shift_start = clock(shift_start, "DM19Yhm")

    generate double num_shift_start = clock(shift_start, "DMYhm", 1982)
    Last edited by Amanda Buechele; 26 Apr 2022, 23:50.

  • #2
    Code:
    gen double num_shift_start = clock(shift_start, "DM19Yhms")
    Without that s, that value doesn't conform to the second argument in clock(). Now, if this is the only value of shift_start that is extended out to include seconds, and all the others have only hours and minutes, then first convert the others as you have done before, and then convert this straggler with:
    Code:
    replace num_shift_start = clock(shift_start, "DM19Yhms") if missing(num_shift_start)

    Comment


    • #3
      Thank you! Clyde Schechter the missing s was what I needed. I appreciate your detailed reply.

      Comment

      Working...
      X