Announcement

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

  • Adding months to existing dates

    Hello,

    I want to make a "time out variable" for a survival analysis.

    I have a variable of date of diagnosis - "timein" which is formatted as a date %dM_d,_CY,
    I have Survival_months - which is numbers between 1 and 900

    I want to create a new variable adding the number of survived months onto the timein variable to get a timeout.

    I tried the following:

    format Survival_months %tm
    generate timeout = timein + Survival_months

    But this just gives me the time in + the number of days in the survival months variable - ie if the survival was 12 months it adds on 12 days.

    Any ideas of how I can do this?

    Thank you!

  • #2
    Welcome to the Stata Forum / Statalist,

    Please read the FAQ. There you'll find advice on how to share data/output/command.

    In short, you may use - dataex - or CODE delimiters.

    This is the best approach to entail insightful replies. When there is no data to work on, the potential replier would need to: a) make guesses about the real situation; b) provide data to work on, with the risk of reaching results which would'nt dovetail with the real deal.
    Best regards,

    Marcos

    Comment


    • #3
      Along with Marcos's advice on presentation of sample data, let me pose the following question.

      Suppose timein = December 30, 2017 and Survival_months = 2. What would you want timeout to be? February 30, 2018 does not seem a reasonable answer.

      This suggests you might be better off structuring your survival analysis as a monthly analysis, converting your timein from a daily date to a monthly date. Then adding Survival_months to that will work naturally.

      As you've seen, Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

      All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.


      Comment

      Working...
      X