Announcement

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

  • Merge two datasets for event study

    Hi,

    I want to merge two datasets for my event study. One file consists of the stock return date (for every company_id over the period 01feb2005 until 01aug2016) and the other one consists of event date (but also includes important variables I do not want to lose). Companies can have multiple events, therefore, I want to use two key variables for merging: company_id and date.

    The stock return dataset looks like:
    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float date str12 company_id
    16468 "AEA000201011"
    16469 "AEA000201011"
    16470 "AEA000201011"
    16471 "AEA000201011"
    16474 "AEA000201011"
    16475 "AEA000201011"
    end
    format %td date
    ------------------ copy up to and including the previous line ------------------

    The eventdates dataset looks like:
    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int date str12 company_id
    20298 "AEA000201011"
    20663 "AEA000201011"
    20207 "AEA001501013"
    20571 "AEA001501013"
    20006 "AEA002001013"
    20355 "AEA002001013"
    20720 "AEA002001013"
    19823 "AEA002401015"
    end
    format %td date
    ------------------ copy up to and including the previous line ------------------


    How can I merge these two datasets and preserve all the stock return dates where no event occurs?

    Thank you


  • #2
    In the data sets you show, only company AEA000201011 appears in both. And in the events data set it appears in association with date 29 July 2015. But in the returns data set it shows up only in dates between 1 and 8 February 2005. So it doesn't appear there is any useful way to merge these data sets if the examples you show are representative.

    I think you need to either explain this differently or provide better examples of your data to illustrate the problem.

    Also, although I do not work in finance or economics and I know the term "event study" only from what I have seen of it here on Statalist, that limited experience suggests that what is usually wanted is to pair the event dates with returns for those firms during some defined window period around the event dates. If that is what you hope to do, it is not a -merge- operation in Stata. Rather it would be a join operation of a more general kind, and would probably be best accomplished using the -rangejoin- command, which was written by Robert Picard and is available from SSC.

    Comment


    • #3
      Thank you for your reply, I see the misunderstanding.

      For every company_id, I collected stock return data from 1 February 2005 until 1 August 2016. Thus the dates in my event dataset are also in the stock return dataset. Unfortunately, I cannot provide a better example because even the first 100 observations will not show a different company_id yet. For not all company_id's in the event dataset I will have stock return data, as I could not collect it for all of them. But I assumed I would be able to drop those (the event dates of company_id with no matching stock returns) after the merging.

      Since I have two variables reoccurring in both datasets I hoped I could merge them like this. I will also look into the -rangejoin-command.

      Comment


      • #4
        Unfortunately, I cannot provide a better example because even the first 100 observations will not show a different company_id yet.
        The output of help dataex tells us that it accepts the if clause, so you can select the same companies and date range from both datasets to provide a sample of your data.

        Comment


        • #5
          Well, it sounds like you want to pair up each event observation with all of the returns information available on that company throughout the period from February 2005 to August 2016. Is that right? If so,

          Code:
          use events_data, clear
          rename date event_date
          joinby company_id using returns_data
          will get you that.

          Comment

          Working...
          X