Announcement

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

  • Finding the difference in time

    HI All:
    I am unable to replicate a variable that I was able to previously generate. I am trying to finding the difference between time expressed in minutes using the command:
    generate onset_hospitarrival = Clockdiff(hosp_datetime , str_datetime, "minute")

    I wonder if it is a formatting issue because I don't see the below values on my screen but I tried %tC, %tc, and %td with no success. Thanks in advance!

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(str_datetime hosp_datetime) float onset_hospitarrival
    1.8099516e+12 1.8099597e+12 -135
    1.8009639e+12  1.800972e+12 -135
    1.8008136e+12 1.8008148e+12  -20
    1.7996175e+12 1.7996196e+12  -35
    1.7987937e+12 1.7987952e+12  -25
    1863141360000 1863145440000  -68
    1.5904071e+12 1.5904134e+12 -105
     1.608462e+12 1608469740000 -129
     1.615239e+12 1.6152498e+12 -180
    1.6184745e+12 1.6184802e+12  -95
    end
    format %tc str_datetime
    format %tc hosp_datetime
    format %tc onset_hospitarrival

  • #2
    Because the value produced by Clockdiff is a number of minutes, it does not need a datetime format. Also, you need to reverse the order of the first two arguments in your code.
    Code:
    . drop onset_hospitarrival
    
    . generate onset_hospitarrival = Clockdiff(str_datetime, hosp_datetime , "minute")
    
    . list, abbreviate(20) clean noobs
    
              str_datetime        hosp_datetime   onset_hospitarrival  
        09may2017 12:20:00   09may2017 14:35:00                   135  
        25jan2017 11:45:00   25jan2017 14:00:00                   135  
        23jan2017 18:00:00   23jan2017 18:20:00                    20  
        09jan2017 21:45:00   09jan2017 22:20:00                    35  
        31dec2016 08:55:00   31dec2016 09:20:00                    25  
        15jan2019 03:16:00   15jan2019 04:24:00                    68  
        25may2010 11:45:00   25may2010 13:30:00                   105  
        20dec2010 11:00:00   20dec2010 13:09:00                   129  
        08mar2011 21:30:00   09mar2011 00:30:00                   180  
        15apr2011 08:15:00   15apr2011 09:50:00                    95

    Comment


    • #3
      Thanks! I used the format command because when I used the sum command on onset_hospitarrival, the output is in stata format that I can't make sense of... Does anyone know how to convert these values to ones that I can make sense of?

      Variable | Obs Mean Std. Dev. Min Max
      -------------+---------------------------------------------------------
      onset_hosp~l | 177,542 725.0271 49110.02 -535926 1.05e+07
      Last edited by Van Ha; 07 Jan 2023, 17:09.

      Comment


      • #4
        I take it you are not familiar with numbers in scientific notation, like 1.05e+07. If you are going to be doing statistical work on a regular basis, you should invest the time to learn about them. Read about the %e and %g formats in -help format- to do that.

        However, if you -format onset_hospitarrival %10.0fc-, and then -summ onset_hospitarrival, format-, you will get numbers written out as integers with up to 8 digits, and commas separating groups of 3. The -format- option of -summarize- tells Stata to display the minimum and maximum in the same format that was applied to the variable itself.

        All of that said, I wonder if there is a problem with your data in the first place. The maximum observed value, 1.05e+07 amounts to just a little under 20 years. Is that plausible? And the minimum value, -535926 is a little bit longer than a year. Is that plausible? And is it plausible for this variable to be negative at all? (Depends on what str_datetime represents, I suppose.)

        Comment


        • #5
          Thanks Clyde for trying to help

          Comment

          Working...
          X