Announcement

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

  • #16
    Thanks Nick Cox, that was it!


    Other question...
    I am trying to make a time difference but is not working:


    Code:
    gen differenceBG = datediff_frac(Arri_lab_hemat_Hb_datetime, Arri_lab_bg_Hb_datetime, "day")

    Thanks again

    Comment


    • #17
      The reason is that the first two arguments supplied to datediff() must be daily dates. Specifying that you want the result in days is not enough for what I guess you want. Perhaps you need push your first arguments through dofc().

      Comment


      • #18
        Thanks Nick Cox. It works, but it gives me an integer. It doesn't give me the fraction part.
        datediff_frac(

        Comment


        • #19
          -datediff()- is designed to produce an integer result. And it also works with dates, not datetimes, so there will never be a fraction of a date, even if you use datediff_frac()-. That will give you fractions of months or weeks or years, or larger units, but never fractions of a day. What you want to do is
          Code:
          gen differenceBG = clockdiff_frac(Arri_lab_hemat_Hb_datetime, Arri_lab_bg_Hb_datetime, "day")
          N.B. No dofc() used here.

          Comment


          • #20
            Please don't write as if we can see what you're giving as a command to Stata, because we can't.

            Code:
            gen double wanted = (Arri_lab_hemat_Hb_datetime - Arri_lab_bg_Hb_datetime) / (24 * 60 * 60000)
            is I think a difference in days, including fractions, but I am lost here on why you want that as far as I can see your times are typically very close indeed and there is no obvious rationale for choosing days as a unit.

            Comment


            • #21
              Thanks Clyde Schechter and Nick Cox !!

              Nick Cox indeed, the dates in this example are too close to use days as units (they are first measurements taken). However, we also want to calculate the time between subsequent measurements (that is the reason behind).


              Thanks again.
              Last edited by Carolina Hincapie; 29 Nov 2024, 02:29.

              Comment

              Working...
              X