Announcement

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

  • How to add 12, 24, 36 month to a data variable in (day, month, year) format

    Dear Stata Users,

    I have a date variable "date" that is in (day, month, year) format. What I want to have to create "stdt" variable that will be "date" + 1 month; "end1dt" = "date" + 12 months; "end2dt" = "date" + 24 months and "end3dt" = "date" + 36 months. Please, help me to resolve this issue.

  • #2
    Not enough detail. We need your rules for what to do with days 29, 30, 31 when they don't occur in a particular month and year, i.e. in February, April, June, September and November.

    Comment


    • #3
      Thank you for the reply! The rule is that it simply adds the number of months. For example, if "date" is 20Jan2000 then adding 2 months should result in 20March2000.

      Comment


      • #4
        No; you don't get my point. 30 or 31 January can never become 30 or 31 February and in non-leap years 29 January can never become 29 February.

        Comment


        • #5
          The following website explains some of the problems with "adding time to dates": https://www.ssc.wisc.edu/sscc/pubs/stata_dates.htm. See especially the section on Using Dates and Months and Years. It explains why this is more complex than you are considering. It also has some suggestions and codes for what you might do.
          Stata/MP 14.1 (64-bit x86-64)
          Revision 19 May 2016
          Win 8.1

          Comment

          Working...
          X