Announcement

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

  • Add command to datetime: -dowinmonth-

    For a long panel or time series, I'd like to generate dummies for holidays, such as Thanksgiving or MLK day, that always fall on the Nth DOW of a month.

    Stata bcal allows to omit these through loading an .stbcal and using the command -omit dowinmonth 4th Th of Nov- (see -help datetime_business_calendars-).

    But I do NOT want to omit them, I want to estimate the effect of these days.

    Why is there not this command under -datetime- functionality, or is there?

    Thank you. Laura Grant (Stata 15 user)

  • #2
    Only StataCorp can say why functionality does not exist: presumably the reasons might well include “Never thought about that”. A better reason for such a function (rather than a command) not existing might be if a work-around exists.

    Given variables mdate ddate for monthly and daily dates then I think that

    Code:
    bysort mdate (ddate): gen wanted = sum(dow(ddate) == 4) == 4
    selects the 4th Thursday in each month. Does that help?

    Comment


    • #3
      You can add extra conditions such as being in November.

      Comment


      • #4
        After defining the holidays in your .stbcal file, generate the business date with the bofd() function. The holidays will have missing values, so you can easily generate a dummy variable.
        Last edited by Braulio Santos; 11 Mar 2020, 18:17.

        Comment


        • #5
          Hi Nick and Braulio, thank you for the ideas -- they give me more to work with. I can and have coded a workaround (see below for generic code for any Nth dow in month).

          But yes, I was thinking that a *function,* as is the hope, makes it so others do not have to figure this out every time. I will add my -dowinmonth()- request to the Stata 17 wish list that is going.

          Cheers, Laura

          Code:
          *Useful with complete time series only; panel data is more complicated
          gen dow = dow(date)
          gen month = month(date)
          gen year = year(date)
          bysort year month dow: gen Nthdow = _n
          *MLK
          gen holiday = dow == 1 & month == 1 &  Nthdow == 3
          *President's day
          replace holiday = 1 if dow == 1 & month == 2 &  Nthdow == 3
          * Thanksgiving
          replace holiday = 1 if dow == 4 & month == 11 &  Nthdow == 4

          Comment


          • #6
            Panel data indeed are more complicated, but the tweak to my code is then just

            Code:
             
             bysort id mdate (ddate): gen wanted = sum(dow(ddate) == 4) == 4
            You could code this up as an egen function. That is what I would have done about 20 years ago, but now I have a different bias: it's best to explain to people how to do it in a few steps with existing functionality.

            The flak that StataCorp gets about dates and times -- almost all unfairly, but there you go -- is that the functionality is hard to understand, so wanting extra functions is swimming against the tide, which is not to deny that people who want this really want this.

            As an Editor of the Stata Journal I am always open to submission of extra Tips for publication.



            Comment

            Working...
            X