Announcement

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

  • Datetime variables

    Hello Stata users,
    I am working with a data set where I have datetime variables and I want to be able to use them to calculate time differences

    The content of the variables have two types of style (both are string)

    - 2020-05-10 18:23:54.061000+00:00
    - 2020-05-11 19:05:23.485Z

    What commands do I need to use to make Stata understand that these variables are datetime variable so that I can calculate time differences? I am using Stata 15

    Thank you for your help!

    Regards,

    Désirée

  • #2
    Code:
    . gen double wanted = clock(ustrregexra(var1,"(.*?)\..*?$","$1"),"YMDhms")
    . format wanted %tcCCYY-NN-DD_HH:MM:SS
    
    . list
         +--------------------------------------------------------+
         |                             var1                wanted |
         |--------------------------------------------------------|
      1. | 2020-05-10 18:23:54.061000+00:00   2020-05-10 18:23:54 |
      2. |         2020-05-11 19:05:23.485Z   2020-05-11 19:05:23 |
         +--------------------------------------------------------+
    Last edited by Ali Atia; 12 Apr 2022, 12:32.

    Comment

    Working...
    X