|
sort companyid date
by companyid: gen datenum=_n
by companyid: gen target=datenum if date==Eventdate
egen td=min(target), by(companyid)
drop target
gen dif=datenum-td
by companyid: gen event_window=1 if dif>=-10 & dif<=30
egen count_event_obs=count(event_window), by(companyid)
by companyid: gen estimation_window=1 if dif<-20 & dif>=-220
egen count_est_obs=count(estimation_window), by(companyid)
replace event_window=0 if event_window==.
replace estimation_window=0 if estimation_window==.
tab companyid if count_event_obs<20
tab companyid if count_est_obs<100
.
drop if count_event_obs < 20
drop if count_est_obs < 100
set more off /* this command just keeps stata from pausing after each screen of output */
gen predicted_return=.
egen id=group(companyid)
/* for multiple event dates, use: egen id = group(group_id) */
forvalues i=1(1)569 { /*note: replace N with the highest value of id */
l id companyid if id==`i' & dif==0
reg ln_return ln_Mktreturn if id==`i' & estimation_window==1
predict p if id==`i'
replace predicted_return = p if id==`i' & event_window==1
drop p
}
sort id date
gen abnormal_return=ln_return-predicted_return if event_window==1
by id: egen cumulative_abnormal_return = sum(abnormal_return)
sort id date
by id: egen ar_sd = sd(abnormal_return)
gen test =(1/sqrt(41)) * ( cumulative_abnormal_return /ar_sd)
list companyid cumulative_abnormal_return test if dif==0
reg cumulative_abnormal_return if dif==0, robust
|