Announcement

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

  • Disease Duration. Finding number of years between two dates.

    Hi everyone,

    I am trying to calculate disease duration for my study. I have two dates that are long format and just calculate how many years there are between them. Sounds simple but I have been unable to find a way to do it.

    Do you have suggestions on how to do that?

    Thanks!
    Bjarki

  • #2
    long is a storage type not a display format. Knowing the storage type doesn't reveal anything about the dates held inside.

    Are they daily dates? or something else? Please give a data example.

    Comment


    • #3
      The date and datetime system in Stata is detailed and can be tricky to approach. I would strongly recommend you to take some time to read the output of -help datetime- to learn about how human dates and times are internally represent, and how to perform functions on them. It will pay dividends going forwards.

      Dates are internally represented as integers. In short, simple subtraction will do the trick to give you elapsed days since diagnosis.

      Since no data were provided, here is a minimal working data example. Note that since version 16, there are convenience functions if you wanted to compute the duration in units other than days (e.g., years). See -help datediff()-.

      Code:
      clear *
      cls
      
      input int(diag_dt date1)
      21895 22714
      end
      format %td diag_dt
      format %td date1
      
      gen int duration = date1 - diag_dt
      list
      Res.:

      Code:
           +----------------------------------+
           |   diag_dt       date1   duration |
           |----------------------------------|
        1. | 12dec2019   10mar2022        819 |
           +----------------------------------+

      Comment

      Working...
      X