Announcement

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

  • Problem with time in minutes between two datetimes variables

    Hi everyone,

    I am working on a transplant trial comparing different methods of preservations.
    I need to calculate the duration of some procedures, like total duration of operation or total preservation time, and I am using datetime variables (like start of procedure and end of procedure) that are type=double and format=%tcDDmonCCYY_HH:MM.

    I have already done it for total duration of operation and it worked fine; I know the time elapsed is given in millisecond so, as I wanted it in minutes, I have divided it by 60000 (1000*60). I checked the results manually and they were correct.

    I have tried to do the same for total preservation time using the same formula above but different variables. The command work but the values resulting are way too high, even after dividing them by 60000. I checked the type and format of the variables used in the formula and everything looks fine so I do not really know why this time is not calculating correctly.

    The only difference with the formula above is that some observations have missing values for one of the datetime variable as that depends on which treatment arm they are. But I also repeated the formula using the "if" options i.e. limiting the formula to work only on the observations with non.missing value for that datetime variable.

    Does anyone know what this wrong calculation could be due to?

    Many thanks,
    Virginia

  • #2
    Sorry, but despite your attention to detail you have not given a reproducible example. Note that display format is not pertinent here; it has no impact on what is stored.

    The difference between date-times in milliseconds is a time (duration) in milliseconds which (as you state) should be divided by 60,000 to get minutes.

    We need to see, minimally, observations with actual values and exactly what you used to calculate the difference.

    Suppose t1 and t2 are date-time variables for which you subtract the difference and get what you think are wrong answers. Then a report of what happens when you do something like

    Code:
    di %14.0f t1[1]
    di %14.0f t2[1]
    di %14.0f t1[1] - t2[1]
    di %14.0f (t1[1] - t2[1])/60000

    might be enough to check your problem. Clearly you need to use your actual variable names.

    Note: Missing arguments should just mean missing results in those observations.

    Comment


    • #3
      Thank you, Nick.

      This is what I have done for Operative Time:
      gen TotOperativeTime_Mins = (EndOperation - StartOperation)/60000
      It worked correctly and the resulting values are correct, as you can check below:

      sum TotOperativeTime_Mins

      Variable Obs Mean Std. Dev. Min Max
      TotOperati~s 25 336.48 85.59357 220 505

      When I try to do it for Preservation time I am using the same formula:
      gen TotPreservationTime_Mins = ( LiverOutIce - CrossClampTime )/60000
      But the resulting values are way too high, see below:

      sum TotPreservationTime_Mins

      Variable Obs Mean Std. Dev. Min Max
      TotPreserv~s 11 2.88e+07 42499.44 2.87e+07 2.88e+07

      Comment


      • #4
        You have not done as I asked. Nevertheless if your difference has values like

        Code:
         
        . di %tc 2.88e+07
        01jan1960 08:00:00
        and further division gives

        Code:
         
        . di %10.0f 2.88e+07 / (60000)
               480
        it seems clear that the problem lies in CrossClampTime

        Remember that

        date_time - date_time = duration

        date_time +/- duration = date_time

        Either
        CrossClampTime is just a duration (a length of time) or it doesn't have units of milliseconds.

        (If I start a job at 28 Nov 2014 09:20:00 and finish at
        28 Nov 2014 09:30:00 those are date-times and their difference is a duration, namely 10:00. )


        NB Please note our firm preference here for full real names, meaning given names and family names. See FAQ Advice.)






        Comment

        Working...
        X