Announcement

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

  • How to convert a date into numerical for subtraction

    Dear members

    I have the following date: 12-Dec-15 and would like to convert it to numerical so I can great a dummy variable equal to one if the data is less than 12-Dec-15 and zero otherwise.

    What’s the right code to convert the data so I can use to create the dummy variable?

    thanks for your help

  • #2
    Consider

    .
    Code:
     di %td daily("12-Dec-15", "DMY", 2025)
    12dec2015
    
    . di %td daily("12-Dec-98", "DMY", 2025)
    12dec1998
    showing that you may need some variation on

    Code:
    gen wanted = daily(whatever, "DMY", 2025)
    or

    Code:
    gen wanted = whatever < daily("12-Dec-15", "DMY", 2025)
    except that

    Code:
    gen indicator = whatever < mdy(12, 12, 2015)
    gets you there directly. All documented in

    Code:
    help datetime

    Comment


    • #3
      Same question at https://www.statalist.org/forums/for...or-subtraction

      Comment


      • #4
        Thank you so much, Nick for your help. Your second code worked well.

        Comment

        Working...
        X