Announcement

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

  • Event Study in Stata

    Dear All!

    First of all I would like to thank everybody for help I found on this forum previously.

    Can you please help me with my event study I am trying to do.
    My general idea is to perform short-term analysis of the merger outcomes for both bidders and targets.
    I have collected data for companies that were involved into merger activities between 1990 and 2014. Afterwards, I collected data for the market indices in countries, where the above-mentioned companies are registered. I reshaped the data into panel data (long format) and combined it, assigning identifiers for companies (as I have companies that were involved into multiple M&A events) and markets. Furthermore, I calculated returns for both companies and market indices. Summarising, I have three datasets at the moment: dataset with companies' returns, dataset with markets' returns and dataset with merger event dates, market identifiers and company identifiers.

    The first two files are organised in the form of panel data in long format (first file - [event_id, bidder_name, return]; second file - [market_id, market_name, return]).

    You can see the table with my event information variables below:

    obs: 4,301
    vars: 9 28 Nov 2014 17:46
    size: 554,829
    storage display value
    variable name type format label
    event_id int %8.0g General ID
    Bidder str64 %64s Name
    company_id float %9.0g group(Bidder)
    market_name str44 %44s Acquiror Market
    market_id float %9.0g group(market_name)
    date_announced float %td
    date_effective float %td
    Sorted by: event_id

    According to my idea, I need to perform several steps:

    1) I need to combine all the three files together. Can you please give advice on how it can be better done (taking into account further details)?
    2) Afterwards, I need to match the merger event dates with the trading dates and calculate abnormal returns for each day in the event window (say, for period of -30 and +30 days around merger event date). The abnormal return is simply difference between market return and company return. Then, I need to sum up all abnormal returns during the event window and obtain CARs (cumulative abnormal returns) for each company. Can you please help me with building a code for this task?

    I will appreciate your help. I am looking forward to hearing from you.

    Best regards,
    Misha Iasinskyi,
    PhD Finance,
    Nottingham Business School



  • #2
    Have you visited this page http://dss.princeton.edu/online_help...ventstudy.html
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment


    • #3
      Misha:
      welcome to the list.
      Your first message(please, do not take it personally. It happened to me several times in the past and will probably happen again in the future) is quite difficult to follow.
      Please, take a look at FAQ on how to post effectively.
      As far as I can understand a part of your problem, I would recommend you to take a look at -help merge-.
      Kind regards,
      Carlo
      (Stata 18.0 SE)

      Comment


      • #4
        Originally posted by Carlo Lazzaro View Post
        Misha:
        welcome to the list.
        Your first message(please, do not take it personally. It happened to me several times in the past and will probably happen again in the future) is quite difficult to follow.
        Please, take a look at FAQ on how to post effectively.
        As far as I can understand a part of your problem, I would recommend you to take a look at -help merge-.


        Thank you for response.
        I have just written so much because I thought it would be better to describe the problem in details to give more understanding of my research and my dataset.
        Now I can narrow down the problem.

        Maybe it could be better to upload a file with my small parts of datasets to be even more exact.
        In the first dataset (EventData) I provide all the information on merger event that I have. The second file contains information on daily market index (MarketData). The third one (attached URL from datafilehost, FirmData) contains all the share prices for the companies involved into mergers
        I try to merge them. I found the following code for that:

        HTML Code:
        use "C:\EventStudy\EventData.dta"
        
        sort co_id
        summ co_id
        local tot_cos = `r(max)'
        forvalues i = 1/`tot_cos' {
        local mkt_name_co_id_`i' = mkt_name[`i']
        local mkt_id_co_id_`i' = mkt_id[`i']
        }
        
        sort co_id edate
        merge co_id edate using "C:\EventStudy\FirmData.dta"
        drop _merge
        
        forvalues i = 1/`tot_cos' {
        if co_id == `i' {
        replace mkt_name = "`mkt_name_co_id_`i''"
        replace mkt_id = `mkt_id_co_id_`i''
        }
        }
        However, this code seems to be not working, because it replaces ALL market_name and market_id with the first market name and market ID.
        Can you please help me with the code in order to build final dataset for my event study?

        Thank you in advance.
        Best regards,
        Misha Iasinskyi
        Attached Files
        Last edited by Misha_Iasinskyi; 29 Nov 2014, 17:35.

        Comment


        • #5
          OK, there are a couple of problems with your code. First, I am assuming that you are using Stata 13. (You are supposed to tell us if you are using an earlier version.) So your syntax for the -merge- command is incorrect. It will still run because Stata will interpret this as "old style" -merge- syntax. But it is safer to use the modern syntax. The MarketData data set has one observation per mkt_id edate pair. The EventData file has multiple observations per mkt_id edate pair. The only part of the code that you need to merge these is one, corrected, -merge- statement if you just start with the MarketData:

          Code:
          use MarketData, clear
          merge 1:m mkt_id edate using EventData
          All of the code you wrote before and after your -merge- command is just an unsuccessful attempt to copy all of the mkt_ids and mkt_names into macros and then, post-merge, recopy them back into the data set. But there is no need to do that. -merge- does not damage any of the data in the MarketData set: whatever was there beforehand will remain there afterward.

          Even though all of that extra code was superfluous, let me point out why you all of the market_name and market_id values were replaced with the first market name and ID in what you did. The problem is that you used an -if- statement when what you needed was -if- qualifiers, and you also misunderstood how Stata would interpret co_id in that -if- statement. These are common errors.

          The -if co_id == `i'- statement, followed by a block of statements in curly braces, is executed each time through the loop. Within it, co_id, without other specification, is taken to mean the first value of co_id. So on the one pass through the loop where `i' actually equals the first co_id, the entire block of code in the curly braces gets executed. That block of code then replace all observations of mkt_name and mkt_id with the values in the corresponding local macros for that value of `i': in other words, mkt_name and mkt_id get replaced throughout by the first values of mkt_name and mkt_id. On all other runs through the outer loop, the first value of co_id is not equal to `i', so the code guarded by the -if- statement is skipped.

          Finally, a subtle point about -merging-. In your situation, both data sets have mkt_id and edate in common, but they also have mkt_name in common. It would be a problem if some mkt_id were associated with different names in the two data sets. That would almost certainly indicate a problem with your data that you would want to investigate before proceeding with analysis. So, a safer way to do the merge than what I wrote above would be:

          Code:
          use MarketData, clear
          merge 1:m mkt_id edate using EventData, update replace assert(match master using)
          By including the -update replace- options you allow Stata to overwrite the MarketData instance of mkt_name with the corresponding one in EventData in the event they are different. If there were such observations, the corresponding values of the _merge variable would be match_update or match_conflict (depending on whether the value in EventData were missing, or non-missing but different from the one in MarketData). The -assert(match master using)- option will cause Stata to complain and stop if it finds any such mismatches.



          Comment


          • #6
            Dear Clyde, thank you for help.
            I understood that everything I was trying to do can be executed only with help of -merge- command according to the appropriate identifiers.
            Can you also please help me with small event-study-related methodological issue I plan to do, which I assume would be my next step after merging datasets.

            Let me explain my difficulty on example of MarketData file.
            I have following variables: "edate" - the trading days on stock exchange; "closing_price_mkt" - the closing value of market index; "mkt_return" - daily return on market index; "days_mkt" - the variable that counts the trading days beginning from the first one.
            Suppose I have one more variable - "event_date", which indicates the dates when merger event occurred.
            My objective is to match the "event_date" with "edate", to count 10 days before and 10 days after the event date and to display market returns for the selected [-10;+10] event window period in the separate column.
            How can it be better done in my case?

            Thank you in advance. I will be very grateful for your help.

            Comment


            • #7
              I'm not sure I fully understand what you want to do here. Do you have a third file which contains this variable event_date, and you want to combine it with what you have in such a way that all pairs of observations where edate is between 10 days before and 10 days after eventdate are retained? Can I also assume that the third file also contains the company variable co_id? If so, then I think you want to do this:

              Code:
              // Start with merged MarketData and EventData as above
              joinby co_id  using third_data_set, unmatched(master)
              keep if inrange(edate, event_date-10, event_date+10)
              This assumes that edate and event_date are both Stata date variables, not strings that humans read as dates. (That was true in the EventData.dta that you posted.)

              Comment


              • #8
                Sorry for possible misunderstanding. Thank you for advice considering merging technique.
                I was inquiring on the actions which I need to do if I already have variables in one MarketData dataset:
                1) "market_return" - all market returns for each market index by trading days;
                2) "edate" - trading days
                3) "event_date" - list of merger dates

                The question is how the code should look like to make Stata:
                1) match the merger "event_date" with the trading days dates ("edate");
                2) display the values of "market_return" for the days in the range of [-10;+10] days according to selected merger event date?

                The point is I can then choose any event window period I want, and not try to perform -merge- every time I need to change the length of event window.
                Last edited by Misha_Iasinskyi; 01 Dec 2014, 13:44.

                Comment


                • #9
                  Now I'm completely confused about what you want to do. What do you mean "match the merger "event_date" with the trading days date ("edate")?" If it's already in the data set, what is it you want to match? Perhaps we will not get far with words. Why don't you hand calculate a few results and show some examples of what you want.

                  Comment


                  • #10
                    Originally posted by Clyde Schechter View Post
                    Now I'm completely confused about what you want to do. What do you mean "match the merger "event_date" with the trading days date ("edate")?" If it's already in the data set, what is it you want to match? Perhaps we will not get far with words. Why don't you hand calculate a few results and show some examples of what you want.

                    Sure, will be glad to provide small example of my task.
                    First, to make the task simpler, we assume that we have 20 companies and each company was involved into merger event only once.
                    Here you can find my final dataset - http://www.datafilehost.com/d/023b2317.

                    The idea of my task is following:
                    1) to order Stata to find "merger_date" values in "edate" values (for each company);
                    2) to count -10 and +10 from the found value in the "edate" (these dates will be included into our event window);
                    3) to display "co_ret" and "mkt_ret" for each date included into the above-mentioned event window;
                    4) calculate abnormal returns for each event window (simply "co_ret" - "mkt_ret").

                    Will be grateful for any offered thoughts to fulfil my task.

                    Thank you in advance.

                    Comment


                    • #11
                      Thanks. I'm afraid the site at the link looks a little sketchy to me, and as I don't know you, I'm not going to download from there. I assume you made a sample data set for the 20 companies with just the relevant variables? Why don't you just -list- that and paste the output into a code block here?

                      Comment


                      • #12
                        Originally posted by Clyde Schechter View Post
                        Thanks. I'm afraid the site at the link looks a little sketchy to me, and as I don't know you, I'm not going to download from there. I assume you made a sample data set for the 20 companies with just the relevant variables? Why don't you just -list- that and paste the output into a code block here?

                        OK, here is the link to my GoogleDrive - https://docs.google.com/file/d/0B8w5...wteEZwVUk/edit
                        I would have downloaded it to the forum directly, but it seems that 4 Mb is too large.



                        Comment


                        • #13
                          OK. So it's pretty simple working from this data set:
                          Code:
                           clear*
                          use Final_Dataset
                            // VERIFY ONLY ONE MERGER DATE PER COMPANY
                          by co_id (merger_date), sort: assert merger_date[1] == merger_date[_N]
                            // IDENTIFY OBSERVATIONS WITH edate IN 10 DAY WINDOW AROUND merger_date
                          gen byte in_window = inrange(edate, merger_date-10, merger_date+10)
                            // TOTAL UP THE ABNORMAL RETURNS FOR WITHIN WINDOW DATES ONLY
                          egen total_abnl_return = total(abnormal_return*in_window), by(co_id)
                          The variable total_abnl_return created by the above code will contain, for each company the sum of the abnormal_return variable on in-window dates for that company. This code presumes that there is only one merger event per company--which is true in your data set.

                          If in the full data sets there are companies with more than one merger event, then you need to clarify whether you want the result to combine all of the window periods and give a company total, or whether you want a separate result for each merger event.

                          Comment


                          • #14
                            Thank you very much, it works, for shorter and longer event windows as well!

                            Would you be so kind to clarify two issues:

                            1) Does -inrange- command identify "merger_date" value among "edate" values? When we generate new variable "in_window", what do its values mean?
                            2) Suppose I have dataset with more than one merger event per company. How should the code look like in this case, provided that I would need separate result for each merger event?

                            Thank you in advance.
                            Last edited by Misha_Iasinskyi; 01 Dec 2014, 17:59.

                            Comment


                            • #15
                              1. The -inrange()- function works as follows: inrange(a, b, c) is equal to 1 if a is greater than or equal to b and less than or equal to c, and 0 otherwise.*

                              2. I notice that in your Final_Dataset there is a variable called event_id. I also notice that in that data set, event_id and co_id are always equal. But I will assume that if a company has more than one merger event (which does not happen in the data set you posted), then there would be multiple event_ids corresponding to that co_id. To do the calculations on a per-merger event basis rather than a per-company basis the code would be almost the same:

                              Code:
                               
                              clear*
                              use Final_Dataset
                                // VERIFY ONLY ONE MERGER DATE PER event_id
                              by event_id (merger_date), sort: assert merger_date[1] == merger_date[_N]
                                // IDENTIFY OBSERVATIONS WITH edate IN 10 DAY WINDOW AROUND merger_date
                              gen byte in_window = inrange(edate, merger_date-10, merger_date+10)
                                // TOTAL UP THE ABNORMAL RETURNS FOR WITHIN WINDOW DATES ONLY
                              egen total_abnl_return = total(abnormal_return*in_window), by(event_id)
                              Note that this code is only sensible if the window periods around the multiple merger events for a company do not overlap. If they do overlap, I don't even know how you can assign a single event_id to observations where edate is in both window periods. Then again, from the very, very little I know about finance, it seems unlikely that the same company would undergo two mergers in the space of 22 days, so this probably won't happen and we don't have to worry about it.

                              * It's a little more complicated than this if we take missing values into account. In your data set, none of the variables that appear in the code I wrote have any missing values, so I wrote this to keep it simple. If you need more information about -inrange()-, you will find it in the [D] manual in the functions chapter, in the programming functions section.

                              Comment

                              Working...
                              X