Announcement

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

  • Converting Python-generated UTC time to Stata's datetime

    Dear all,

    I have the following UTC time format in a string variable and want to import it to Stata with this code:
    Code:
    clear
    input str25 python_time float
    "2020-06-01 T 13:07:04 UTC"
    "2020-06-01 T 13:07:06 UTC"
    end
    
    generate stata_time = Clock(python_time, "YMD#hms#",2020)
    format stata_time %tC
    I get this result:

    Code:
    python_time    stata_time
    2020-06-01 T 13:07:04 UTC    01jun2020 13:07:49
    2020-06-01 T 13:07:06 UTC    01jun2020 13:07:49
    Why are the seconds incorrect?

    Thank you,
    Max

  • #2
    Datetimes should always be stored as double. There are not enough bytes in the default storage type, float. See

    Code:
    help datetime
    Code:
    generate double stata_time = Clock(python_time, "YMD#hms#",2020)

    Comment


    • #3
      Oh, I did not pay attention to the storage type.
      Thank you very much Andrew.

      Comment

      Working...
      X