Announcement

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

  • Calculating month between two dates

    Dear All,
    May data set contains a variable named month1 for the first month and year1 for the first year and month2 for the second month and year2 for the second year. there is no specific day on the month. In this case, how do I generate a new variable which contains both month and year and how can I calculate the month difference between two dates?

    Thank you for your help

  • #2
    On this information you may need as little as

    Code:
    gen difference = ym(year2, month2) - ym(year1, month2)
    and the components may also go in separate variables if you wish.

    But, but, but:

    0. With date variables there is no good shortcut beyond reading

    Code:
    help datetime
    to understanding how Stata handles dates.

    1. We can't see your data. Your month variables could be say string variables with values like "October" and then their making perfect sense to you buys you nothing with this recipe given above. You need please to show example data. You need please to read the FAQ Advice again until you know that you need to give example data.

    2. If that is all there is to say your present data layout may suffice. But if you have a bundle of other variables of the same kind you almost certainly need reshape long to make your Stata life easier.

    Comment


    • #3
      Dear Nick Cox
      thank you very much and I solved the problem with your direction. Thank You.

      Comment

      Working...
      X