Announcement

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

  • Calculating date in stata

    Assuming I have 5 participant with date of birth and exam date, and are enrolled in a study for 12 months, assuming all completed the 12 months treatment course. How do I calculate the end date for each of these participants in stata

    Example data:

    Code:
    clear
    input float( id dob examdate )
    1 01 Apr 2016  15 May 2017
    2 05 Dec 2014  22 Nov 2015
    3 21 Aug 2015  25 Mar 2016
    4 26 Sep 2014  14 May 2015
    5 12 Aug 2016  09 Sep 2017
    end
    thanks

  • #2
    Is this an appropriate way?
    Code:
    gen enddate = dob+365.25

    Comment


    • #3
      Your code won't work as defining your data. You have 7 fields and the input command given won't be successful at reading them into 3 numeric variables. Please use dataex to show us an example of your real data.

      Otherwise with a daily date variable, 12 months exactly later will be

      Code:
      gen newdate = mdy(month(examdate), day(examdate), year(examdate) + 1)
      except that this will yield missing for 29 February in a non-leap year, in which case you can choose a rule, e.g.

      Code:
      replace newdate = mdy(2, 28, year(examdate) + 1) if missing(newdate) & examdate == mdy(2, 29, year(examdate))
      or

      Code:
      replace newdate = mdy(3, 1, year(examdate) + 1) if missing(newdate) & examdate == mdy(2, 29, year(examdate))
      Example of concept:

      Code:
      . di mdy(2, 17, 2017)
      20867
      
      . di %td  mdy(month(20867), day(20867), year(20867) + 1)
      17feb2018

      Comment


      • #4
        Thanks Nick

        Comment

        Working...
        X