Announcement

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

  • how to keep the first occurence of a date surrounding another date

    Hi,

    I have an M&A dataset and I want to analyze the returns surrounding the announcement date. However, sometimes the announcement date is on Friday for example. As a result, the 1st available returns are 3 days later on Monday. Then I want to keep the returns of Monday (the first day after the announcement date). Another case is where the announcement day is Monday and you want to include the Friday returns. A simple date difference variable will not help because it will state that the difference is 3 days. Therefore I would like to keep the data from the 1st available date after the announcement date.

    an example:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long DealNumber int Announceddate long date double RET
    649667 18026 18023  .007169831544160843
    649667 18026 18024  -.04645933955907822
    649667 18026 18025 -.007858576253056526
    649667 18026 18028  .004356459714472294
    649667 18026 18029  .014589862897992134
    end
    format %td Announceddate
    format %td date
    How can I keep the observations which are 1 day earlier and 1 day after the announcement date?

  • #2
    This is where a business calendar would help.

    Code:
    help bcal
    Alternatively, create your own time variable that ignores gaps.

    Comment


    • #3
      Hi Nick,

      Thanks for your quick response. I tried to convert my dates to business dates but it does not seem to work properly.

      i read this blog and i tried this:
      https://blog.stata.com/2016/02/04/ha...ess-calendars/

      bcal load sp500
      generate bcaldate = bofd("sp500",date)

      however only . (empty values) were created.

      Alternatvely i tried to create a time variable as follows

      Code:
      sort DealNumber
      by DealNumber, gen time = _n

      How can I keep the previous and next observation compared to the observation which has a date equal to the announcement date?

      Comment


      • #4
        Sorry; I have never used business calendars myself. I just know that they exist.

        Comment


        • #5
          In your data example, you do not have an observation with the date equal to the announcement date. You'll need to identify a record to reference.
          Another approach is to calculate a difference of dates
          Code:
          gen diff=date-Announceddate
          gen keep=abs(diff)<=1
          This identifies all records within one day, which is what I assume you want?

          Comment


          • #6
            Hi Daniel,

            Yes sometimes the announcement date is in the weekend. On saturday and Sunday, there are no returns. This also an extra obstacle and therefore the difference in days method does not work properly. Therefore i want to generate a window with the closest return date before and after the event.

            Comment


            • #7
              You can place only entries with returns into a new frame, generate your wanted variable and then merge with the default frame. The assumption is that you identify non business days by missing returns.

              Code:
              frame put var1 var2 ... if !missing(return), into(newframe)
              frame change newframe
              *GEN WANTED VAR
              frame change default
              frlink 1:1 var1 var2, frame(newframe)
              frget wanted, from(newframe)
              Last edited by Andrew Musau; 11 Jun 2021, 09:14.

              Comment


              • #8
                Timme Ariens, I can't say why the bofd() function is generating missing values (#3). I am guessing it is related to centerdate and range in your business calendar file.

                Anyway, if you want to use a business calendar for this problem, this may be helpful. There is a little catch in that Saturdays and Sundays are not strictly non-business days because, although returns are available only on weekdays, announcements can be made during the weekend. I assume that for any weekend announcement, you would like to keep only observations for the preceding Friday and following Monday. One workaround is to move all weekend announcements to one business day, say Saturday. So you would omit only Sunday in your business calendar.

                The business calendar file for your M&A dataset, say ma.stbcal, will look like this:
                Code:
                *! version 1.0.0
                *  ma.stbcal
                
                version 16
                purpose "M&A"
                dateformat dmy
                
                range 01jan2009 31dec2009
                centerdate 01jan2009
                
                omit dayofweek (Su)
                Note that range and centerdate are compatible with your example. I augmented the example to include, besides a Saturday, a Sunday and a weekday (Wednesday) as announcement days:
                Code:
                clear
                input long DealNumber int Announceddate long date double RET
                
                649667 18026 18023  .007169831544160843
                649667 18026 18024  -.04645933955907822
                649667 18026 18025 -.007858576253056526
                649667 18026 18028  .004356459714472294
                649667 18026 18029  .014589862897992134
                
                649667 18027 18024  .007169831544160843
                649667 18027 18025  -.04645933955907822
                649667 18027 18028 -.007858576253056526
                649667 18027 18029  .004356459714472294
                649667 18027 18030  .014589862897992134
                
                649667 18030 18028  .007169831544160843
                649667 18030 18029  -.04645933955907822
                649667 18030 18030 -.007858576253056526
                649667 18030 18031  .004356459714472294
                649667 18030 18032  .014589862897992134
                end
                
                format %td Announceddate
                format %td date
                The following code should tell you which observations to keep. First, all Sunday announcements are moved to the preceding Saturday. Then business dates for both date and Announceddate are generated. They are bcal_date and bcal_announce respectively. The function dow() is used to find the numeric day of the week. Note that dow() returns 0 for Sunday, 1 for Monday, etc. Finally, keep observations if the difference between bcal_date and bcal_announce is 1 or less.

                Code:
                replace Announceddate = Announceddate - 1 if dow(Announceddate) == 0
                
                generate bcal_date = bofd("ma", date)
                generate bcal_announce  = bofd("ma", Announceddate)
                format %tbma bcal_date
                format %tbma bcal_announce
                
                generate keep = 0
                replace keep = 1 if abs(bcal_announce - bcal_date) <= 1
                I hope this helps.

                -- Kreshna

                Comment

                Working...
                X