Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

clear all

set mem 1g
set more off
cd /Users/mciteli/Dropbox/Citeli/Work/Tela/WorkingThesis/EventStudy/
use Input/tdata
// egen company_id = group(comnam)
// To select companies:
//list company_id comnam if date==19157
list id comnam if num==1
insheet using test.csv
gen edate = date(date, "MDY")
format edate %td
gen company_id = 1 if comnam == "ALLL3"
replace company_id = 2 if comnam == "ALPA3"
replace company_id = 3 if comnam == "ALPA4"
// Merging two datasets
clear all
use tstockdata, clear
sort company_id
drop targetname
save teventdates, replace
merge m:1 company_id using teventdates
tab _merge
keep if _merge==3
drop _merge
//
clear all
use tstockdata, 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<-30 & dif>=-60
egen count_est_obs=count(estimation_window), by(company_id)
replace event_window=0 if event_window==.
replace estimation_window=0 if estimation_window==.
tab company_id if count_event_obs<5
tab company_id if count_est_obs<30
drop if count_event_obs < 5
drop if count_est_obs < 30
set more off
gen predicted_return=.
egen id=group(company_id)
forvalues i=1(1)3 {
list id company_id if id==`i' & dif==0
regress ret market_retn if id==`i' & estimation_window==1
display `i'
predict p if id==`i'
display `i'
replace predicted_return = p if id==`i' & event_window==1 display `i' drop p
}
sort id date
gen abnormal_return=ret-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(5))
list company_id cumulative_abnormal_return test if dif==0
reg cumulative_abnormal_return if dif==0, robust
outsheet company_id event_date cumulative_abnormal_return test using stats.csv
if dif==0, comma names
forvalues i=1(1)355062 {
display comnam if date[`i']==29dec2000
}
forvalues i=1(1)3 {
display comnam[`i'] if nseg[`i']==3
}
drop if id==15
forvalues i=1(1)102 {
count if id==`i'
}
sort id
by id: gen num = _n

You might also like