Event Study Analysis using Stata

To run Event Study Analysis using Stata, copy, paste and edit the following do file and ensure the variable names (returns and market returns are properly named) to run the code on your data. The data should be prepared in Excel using this video to be running the do file with success.


***Note change the folder location path where data is saved
import delimited "F:\Dropbox\Stata Training\Do File For Event Study Analysis using Stata Workshop\data.csv", clear

***Create return series from stock and market prices
gen ret = ln(price[_n] / price[_n-1])
gen market_return = ln(index[_n] / index[_n-1])

****Create Compani Numeric ID
sort name
by name : gen newid = 1 if _n==1
replace newid = sum(newid)
replace newid = . if missing(name)
br newid name

*** Create Event Windows
sort newid date
by newid: gen datenum=_n
gen evwin = 0
by newid: gen target=datenum if date==20080219 | date==20130512
egen td=min(target), by(newid)
drop target
gen dif=datenum-td
by newid: gen event_window=1 if dif>=-7 & dif<=30
egen count_event_obs=count(event_window), by(newid)
by newid: gen estimation_window=1 if dif<-50 & dif>=-300
egen count_est_obs=count(estimation_window), by(newid)
replace event_window=0 if event_window==.
replace estimation_window=0 if estimation_window==.
tab newid if count_event_obs<5
tab newid if count_est_obs<30
drop if count_event_obs < 5
drop if count_est_obs < 30
set more off

* this command just keeps Stata from pausing after each screen of output *
gen predicted_return=.
egen id=group(newid)
* for multiple event dates, use: egen id = group(group_id) *
*note: replace N with the highest value of id *
summ id
local N = r(max)
forvalues i=1(1)`N' {
l id newid if id==`i' & dif==0
reg ret market_return if id==`i' & estimation_window==1
predict p if id==`i'
replace predicted_return = p if id==`i' & event_window==1
drop p

*** Determine the AAR and CAAR

sort id date
gen abnormal_return=ret-predicted_return if event_window==1
bysort id: egen cumulative_abnormal_return = sum(abnormal_return)
sort id date
by id: egen ar_sd = sd(abnormal_return)

***note frequency of 1
gen test =(1/sqrt(385)) * ( cumulative_abnormal_return /ar_sd)
list newid cumulative_abnormal_return test if dif==0

The do file can be better understood with practical demonstration. Request a free demo on www.aneconomist.com/workshops here.

Also there is extensive list of resources and literature on Event Study Analysis using Stata. One can begin reading the material here and here.

Event Analysis using Stata

Advanced Econometrics using Stata training workshop and tutorial. The following Stata code computes simple t-test to test the hypothesis that the variables are different between two time periods. The time periods have been defined based on pre-event and post-event time periods. Thus, we can employ this method to test an event impact on a few variables in a single script of the Stata code which also produces a single table ready for publication or inserting into a word document.

****Open the data file using the following code.
use "E:\Dropbox\Advanced Econometrics using Stata Trainings\data12.dta", clear

****The following two lines of codes creates a few temprary files in Stata to create and save the results in our analysis. The results will be available to call into Stata from the same temprary files.
tempname econometrics_ttest
tempfile ttests
postfile `econometrics_ttest' str12 name t_statistic swilk rankstat pearson fisher using `ttests'

****Now, loop over the given variables to be used for testing the hypothesis. These are the variables which will make the hypothesis to be tested on using Stata and following the simple t-test to verify the post-event variable values has equal greater average than the pre-event time period sample of the same variable.
foreach var of varlist  y x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 {

****t-test is used to test the null hypothesis that the variable has equal means between post-event and pre-event samples for the variables. The -local-command saves the given statistics saved under the Stata routine r().
ttest `var', by(event)
local tstat = r(t)

****Shapiro Wilk test can be employed and produced results can be saved using the following code.
swilk `var'
local swilk = r(W)

****RankSum test is applied using the following code.
ranksum `var', by(event)
local rankstat = r(z)

****Chi-square tests can be employed using the following code.
median `var', by(event)
local pearson = r(chi2)
median `var', by(event) exact
local fisher = r(chi2_cc)

****The following code writes the produced and saved results in -local-s to the given variables defined under -postfile-.
post `econometrics_ttest' ("`var'") (`tstat') (`swilk') (`rankstat') (`pearson') (`fisher')

****These lines of the code closes the above temprary files, calculations and saving the results.
postclose `econometrics_ttest'

****Call in the results to see the output of the above code.
use `ttests'

****Change any variable, their labels or create further statisticals.
label var t_statistic "Unequal Variance type t-Statistic"
rename name variable_name
label var variable_name "Variable Tested for Different in Mean Post minus Pre event"

****Now export the table which is already saved in form of a Stata file. This can be a simple table in a standard format.
export excel using "E:\Dropbox\Advanced Econometrics using Stata Trainings\tables_econometrics_research.xls", firstrow(variables) replace

****See the results.

Event Study Stata is one of the most interesting area that we can help you with. You can request a freelance project from our top freelancers in Stata to help you complete the event study even for a complex study. We handle Event Study using Stata for all kinds of data from cross sectional, panel data and time series. You can request a Event Study Stata help from our freelancers in econometrics and Stata using the following proforma.