Announcement

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

  • Keep oberservation -20 and +20 without counting the weekends..


    I am creating a new variable "EventT" which must takes the value of zero on the day of the announcement, -1 on the trading day before, -1 etc..
    And +1 on the day after, +2 two days after etc..
    I have to keep only observations within a -20/+20 trading day window around the announcement. (Started with -35 +35).
    So after creating EventT. But because the weekends and the holidays are already dropped, stata is assigning the days instead of the trading days to the values.
    So stata is not assigning the days I want, because I want to select -20 / +20 of the trading days and delete the other observations (see screenshot).

    Could you tell me how to select the 20 before and 20 after ?

    Kind regards,

    Jan

  • #2
    See the sections of the manual relating to business calendars, which Stata Corp. invented for precisely this purpose. I don't use them myself, so I can't advise you on any specifics, but the solution to your problem will be found there.

    Comment


    • #3
      Thank you for your advice, I tried it, but there are mulptiple zero's so there is going something wrong. Maybe someone can give advice by stata code?

      Comment


      • #4
        I'm a little confused when you say you've already got weekends and holidays removed. Presumably the only days left would be valid trading days. Would not any count of rows from your index date, (EventT)==0, be the actual number of trading days from the index date (assuming no date gaps)? An advantage of business calendars is you can designate records as being business or non-business days without removing records.

        If weekends and holidays are removed could you not just do:

        Code:
        gen index=0 if date==td(15jan2015) /* just put a date in as an example/*
        replace index=index[_n-1]+1 if missing(index)
        count if missing(index)
        replace index=-1*`r(N)' in 1
        replace index=index[_n-1]+1 if missing(index)
        replace index=. if index>20|index<-20
        I don't use business calendars much but I'll take a shot at it. You'll need a calendar that matches the dates in the dataset you're using. The "sample" calendar included in Stata only includes dates for November 2011. So create your own calendar based on simple or create your own from a dataset.

        enter
        Code:
        bcal dir
        to see where your simple calendar is located. Modify the date range and the omission section to add any statutory holidays you may have to deal with.

        Code:
        *! version 1.0.0
        *  simple.stbcal
        
        version 12
        purpose "Example for manual"
        dateformat dmy
        
        range 01nov2011 30nov2011
        centerdate 01nov2011
        
        omit dayofweek (Sa Su)
        omit date 24nov2011
        omit date 25nov2011
        Once you've created your calendar, load it with
        Code:
        bcal load calendarname
        You can then create business day variable from your calendar date from your compete dataset, here named "date"

        Code:
        format %td date /* just to be sure it's in a format that you can read*/
        gen bdate=bofd("calendarname",date)
        Then format your new variable using the business calendar format

        Code:
        format %tbcalendarname bdate
        What you'll see in your dataset is bdate that appears identical to your original calendar date. However, bdate will be missing for calendar days excluded by your business calendar (weekends, holidays)

        There's probably a few different ways to select the rows you want based on your 20 day window.

        For example:

        Code:
        gen lower=bdate-20
        gen upper=bdate+20
        format %tbcalendarname lower upper
        What this should give you is a new variable with the business day 20 days lower and higher than the business day on each row. You could probably do something along the lines of what you want to do with -20 to +20 but this is all I have time to look at. :-)



        Comment

        Working...
        X