Announcement

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

  • Business Day computation

    Hello everyone!

    I am dealing with an event study for financial application and I am facing the following issue:

    For each of my events I would like to pull data for the 5 trading days prior and 5 trading days after the event date (i,e, 11 observations including the event date).
    I am doing my stock data requests through Stata, but i cannot simply deduct 5 off the event date, because then in most cases I will receive less than 11 observations, given that this timeframe will include non-business days.

    What I therefore would need is a function to deduct/add 5 business days from the original event date. Is there a function built in Stata's added Business Calendar? I am still struggling to work myself through some of the Stata documentations.

    Many thanks!
    Hans

  • #2
    If you have already converted your date variable to business calendar dates, then adding or subtracting 5 to the date will give you the bounds for 5 business days before or after the index date. That is the whole point of business calendars. If a date is a Monday and you subtract 1, the result is the preceding Friday.

    If the thrust of your question is how to then associate each observation with the information from observations corresponding to the interval from 5 business days before to 5 business days after, then you should look into the -rangestat- and -rangejoin- commands. The former is written by Robert Picard, Nick Cox, and Roberto Ferrer, and the latter by Robert Picard. Both are available from SSC.

    Comment


    • #3
      Hi Clyde,

      Thank you for your response! I tried adding and subtracting with a sample file on S&P 500 I found on the Stata website. I had some problems understanding that I need to give Stata a full calendar to work with as an input, but I have resolved this by pulling a sample stock price series over the time frame I am considering. Now this is all resolved!

      Best,
      Hans

      Comment


      • #4
        Hello again,

        sorry that I have to bother again, but I am apparently still stuck in some kind of misunderstanding of the feature. After creating and applying the business calendar format to the dates of my dataset there still seems to be some kind of problem. I will illustrate it using the sp500 file built in Stata:

        Code:
        sysuse sp500
        bcal create sp500, from (date) replace
        
        // Apply the created format to the date variable
        format date %tbsp500
        
        // Try #1 - Simply add a number:
        gen test1 = date + 1
        
        // Try #2 - Use bofd() function:
        gen test2 = bofd("sp500", date)
        
        // Reformat to make them readable:
        format date %td
        format test1 %td
        format test2 %td
        When I browse the data, then I still have weekends and holidays in my test1 variable (e.g. 4th of July)
        The result of the test2 is completely unclear to me.. Every time I use the bofd() function i get numeric date variables starting from zero.

        Would be grateful for some insight which part of the feature I misunderstood.

        Comment


        • #5
          The first thing to understand is that Stata dates are numeric and relative to a reference time point. So for example, daily dates store the number of days since Jan. 1, 1960. For example:
          Code:
          . dis %td 0
          01jan1960
          
          . dis %td 7
          08jan1960
          You can do the same with the "sp500" business calendar you create in #4. The reference time point is the earliest date in the data that created the business calendar.
          Code:
          . sysuse sp500, clear
          (S&P 500)
          
          . 
          . sum date, format
          
              Variable |        Obs        Mean    Std. Dev.       Min        Max
          -------------+---------------------------------------------------------
                  date |        248   30jun2001    105.3335  02jan2001  31dec2001
          Since business calendars omit certain dates (usually weekends and holidays), note that 7 business days later falls on a different date.
          Code:
          . dis %tbsp500 0
          02jan2001
          
          . dis %tbsp500 7
          11jan2001
          The following code is a reworking of #4. I create the "sp500" business calendar and generate a new bdate. I then create one-day-ahead variables in both calendar (fdate and fbdate). I then convert fdate, which is a daily date, into a business date (dconv) using the bofd() function. Since fdate includes values that fall on weekend days, this creates missing values in dconv as these are skipped in this business calendar. Finally, I list the date variables, first with the appropriate date format and then using a format that shows the actual numeric values stored.
          Code:
          sysuse sp500, clear
          
          * clone the original date variable, give it a format that shows the day
          clonevar doriginal = date
          format %tdDayDDmonCCYY doriginal
          
          * create a business calendar based on the daily date variable
          bcal create sp500, from(date) gen(bdate) replace
          
          * a one day lead
          gen fdate = date + 1
          format %td fdate
          gen fbdate = bdate + 1
          format %tbsp500 fbdate
          
          * convert a daily date to a "sp500" bcal date
          gen dconv = bofd("sp500", fdate)
          format %tbsp500:DayDDmonCCYY dconv
          
          * list all date variables
          list doriginal date bdate fdate fbdate dconv in 1/10
          
          * list just the stored numerical values
          format %9.0g doriginal date bdate fdate fbdate dconv
          list doriginal date bdate fdate fbdate dconv in 1/10
          and the list results:
          . * list all date variables
          Code:
          . list doriginal date bdate fdate fbdate dconv in 1/10
          
               +-----------------------------------------------------------------------------+
               |    doriginal        date       bdate       fdate      fbdate          dconv |
               |-----------------------------------------------------------------------------|
            1. | Tue02jan2001   02jan2001   02jan2001   03jan2001   03jan2001   Wed03jan2001 |
            2. | Wed03jan2001   03jan2001   03jan2001   04jan2001   04jan2001   Thu04jan2001 |
            3. | Thu04jan2001   04jan2001   04jan2001   05jan2001   05jan2001   Fri05jan2001 |
            4. | Fri05jan2001   05jan2001   05jan2001   06jan2001   08jan2001              . |
            5. | Mon08jan2001   08jan2001   08jan2001   09jan2001   09jan2001   Tue09jan2001 |
               |-----------------------------------------------------------------------------|
            6. | Tue09jan2001   09jan2001   09jan2001   10jan2001   10jan2001   Wed10jan2001 |
            7. | Wed10jan2001   10jan2001   10jan2001   11jan2001   11jan2001   Thu11jan2001 |
            8. | Thu11jan2001   11jan2001   11jan2001   12jan2001   12jan2001   Fri12jan2001 |
            9. | Fri12jan2001   12jan2001   12jan2001   13jan2001   16jan2001              . |
           10. | Tue16jan2001   16jan2001   16jan2001   17jan2001   17jan2001   Wed17jan2001 |
               +-----------------------------------------------------------------------------+
          
          . 
          . * list just the stored numerical values
          . format %9.0g doriginal date bdate fdate fbdate dconv
          
          . list doriginal date bdate fdate fbdate dconv in 1/10
          
               +---------------------------------------------------+
               | dorigi~l    date   bdate   fdate   fbdate   dconv |
               |---------------------------------------------------|
            1. |    14977   14977       0   14978        1       1 |
            2. |    14978   14978       1   14979        2       2 |
            3. |    14979   14979       2   14980        3       3 |
            4. |    14980   14980       3   14981        4       . |
            5. |    14983   14983       4   14984        5       5 |
               |---------------------------------------------------|
            6. |    14984   14984       5   14985        6       6 |
            7. |    14985   14985       6   14986        7       7 |
            8. |    14986   14986       7   14987        8       8 |
            9. |    14987   14987       8   14988        9       . |
           10. |    14991   14991       9   14992       10      10 |
               +---------------------------------------------------+

          Comment


          • #6
            What you want is:
            Code:
            sysuse sp500, clear
            bcal create sp500, from (date) replace
            
            generate business_date = bofd("sp500", date)
            format business_date %tbsp500
            
            
            gen next_business_date = business_date+1
            format next_business_date %tbsp500
            The reasons your code didn't work:

            1. Just creating the business calendar from variable date does not convert the variable date to a business-date variable. You have to explicitly do that with the bofd() function.

            2. Adding 1 to the original non-business date variable just gives the ordinary next calendar date.

            3. The variables test2 that you created is on the right track. (It's the same as the variable business_date in my code.) But you erred in applying a %td format to it, instead of %tbsp500.

            So what is needed is to first create the business calendar, then create new business_date variables and format them %tb. Then using the new business_date variables you can add or subtract as needed, but you must, again, apply the %tb formatting to them in order for them to come out right. Never apply a %td format to a business date variable, and never apply a %tb format to a regular calendar date variable. Either one gives you nonsense.

            Added: Crossed with #5.

            Comment


            • #7
              Thank you very much for these helpful posts! I replicated the procedure in the sp500 file and did the same with my own dataset successfully!
              I was almost there but mixed up which variable to give what kind of format, but now I've got it in order.

              Comment


              • #8
                Hi,

                I am also looking to generate trading days and compute CAR but I need Indian Calander for NSE/BSE Sensex. How do I do that??

                Comment

                Working...
                X