Announcement

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

  • help with event study! :(

    Dear Stata Community,

    I'm hoping to get some guidance with calculating the test statistic for my event study analysis. I'm aiming to compute for each company_id the value of test statistic using the formula cumulative_abnormal_return/sqrt(5)*ar_sd.

    Context:
    • I'm working on an event study to assess the impact of an event on various companies (company_id).
    • I've successfully completed the initial stages of the analysis, as shown in the provided code snippet.
    • The code calculates the cumulative abnormal return (CAR) for each company around the event window.
    • I've also computed the standard deviation of abnormal returns (AR_SD) for a specific estimation window.
    Issue:
    The problem I'm facing is that Stata generates the test variable but leaves it empty (without any values). This prevents me from calculating the desired test statistic (cumulative_abnormal_return/sqrt(5)*ar_sd).

    code snippet:
    clear
    import excel "/Users/...per stata.xlsx", sheet("Foglio2") firstrow clear

    sort company_id date
    by company_id: gen datenum=_n
    by company_id: gen target=datenum if date==event_date
    egen td=min(target), by(company_id)
    drop target
    gen dif=datenum-td
    by company_id: gen event_window=1 if dif>=-2 & dif<=2
    egen count_event_obs=count(event_window), by(company_id)
    by company_id: gen estimation_window=1 if dif<-40 & dif>=-240
    egen count_est_obs=count(estimation_window), by(company_id)
    replace event_window=0 if event_window==.
    replace estimation_window=0 if estimation_window==.
    gen predicted_return=.
    egen id=group(company_id)
    forvalues i=1(1) 332{
    l id company_id if id==`i' & dif==0
    reg ret market_ret if id==`i' & estimation_window==1
    predict p if id==`i'
    replace predicted_return = p if id==`i'
    drop p
    }

    sort id date
    gen abnormal_return=ret-predicted_return
    by id: egen cumulative_abnormal_return = sum(abnormal_return) if event_window==1
    sort id date
    sort company_id
    by company_id: gen sporca=1 if dif<=-3 & dif>=-40
    by company_id: egen ar_sd = sd(abnormal_return) if sporca==1
    egen std=min(ar_sd), by(company_id)

    Unfortunatly the data file that I'm using is too heavy, I post a screenshot with the basic elements

    Any guidance you can offer would be greatly appreciated.

    Thank you for your time and assistance!

    Attached Files

  • #2
    Your code is lengthy and somewhat convoluted. I don't see any glaringly obvious errors, but it is complicated enough to be hard to visualize exactly where things might be going wrong. There is also the possibility that the data are the source of the problem, rather than the code. A screenshot of the data set is well intended, but not very helpful as it is impossible to import a screenshot into Stata and actually work with it. The effective way to share data is with the -dataex- command. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Perhaps somebody else can visualize what is going on and propose a solution. But if you don't get a helpful response in a reasonable amount of time, I advise you to post back and use the -dataex- command to share usable example data. That will increase the likelihood that somebody can figure out why you are getting only missing values for your key variables.

    Comment

    Working...
    X