*============================================================================* local summary "C:\Final_Sample.dta" local datadir "C:\Data" local output "C:\Output" *============================================================================* use "`output'/EAD.dta", clear gen B_d=mdy(1, 1, 2016) format B_d %td gen E_d=mdy(12, 31, 2016) format E_d %td gen Ind=cond(AD>=B_d & AD<=E_d, 1, 0) keep if Ind==1 keep country stock AD sort stock save "`output'/Temp_EAD.dta", replace drop _all use "`output'/NIT_Volumn.dta", clear sort country stock date foreach k in "1" "2" "3" "7" "8" "9" { gen double OI_`k'0=(i_`k'01-i_`k'00)/(i_`k'01+i_`k'00) replace OI_`k'0=0 if OI_`k'0==. drop i_`k'01 i_`k'00 } sort stock merge stock using "`output'/Temp_EAD.dta" keep if _merge==3 drop _merge erase "`output'/Temp_EAD.dta" sort country stock date merge country stock date using "`output'/3 Factor Model.dta" keep if _merge==3 drop _merge sort country stock date bysort country stock: gen datenum=_n bysort country stock: gen target=datenum if date==AD bysort country stock: egen td=min(target) drop target gen dif=datenum-td drop datenum td sort country stock date bysort country stock: gen event_window=1 if dif>=-1 & dif<=11 bysort country stock: egen count_event_obs=count(event_window) bysort country stock: gen estimation_window=1 if dif<-1 & dif>=-11 bysort country stock: egen count_est_obs=count(estimation_window) replace event_window=0 if event_window==. replace estimation_window=0 if estimation_window==. drop if count_event_obs<13 drop if count_est_obs<10 preserve keep country stock date price MB MV index dif event_window count_event_obs estimation_window count_est_obs bysort country stock: gen double ret=(price[_n]-price[_n-1])/price[_n-1] bysort country stock: gen double m_ret=(index[_n]-index[_n-1])/index[_n-1] gen double ma_ret=. gen double fa_ret=. egen id=group(country stock) sum id forvalues i=1(1)`r(max)' { capture reg ret m_ret if id==`i' & estimation_window==1 if _rc==0 { predict p if id==`i' replace ma_ret = p if id==`i' & event_window==1 drop p } capture reg ret m_ret MB MV if id==`i' & estimation_window==1 if _rc==0 { predict p if id==`i' replace fa_ret = p if id==`i' & event_window==1 drop p } } keep country stock date ret m_ret ma_ret fa_ret sort country stock date save "`output'/Temp_CR.dta", replace restore sort country stock date merge country stock date using "`output'/Temp_CR.dta" drop _merge erase "`output'/Temp_CR.dta" sort country stock date gen double ab_ma_ret=ret-ma_ret if event_window==1 gen double ab_fa_ret=ret-fa_ret if event_window==1 gen double ab_ra_ret=ret-m_ret if event_window==1 local varlist "OI_10 OI_20 OI_30 OI_70 OI_80 OI_90" foreach arg in `varlist' { sort country stock date bysort country stock: egen double m`arg'=mean(`arg') if estimation_window==1 bysort country stock: egen double m1`arg'=min(m`arg') bysort country stock: egen double sd`arg'=sd(`arg') if estimation_window==1 bysort country stock: egen double sd1`arg'=min(sd`arg') gen double ab_`arg'=(`arg'-m1`arg')/sd1`arg' if event_window==1 drop m`arg' m1`arg' sd`arg' sd1`arg' } preserve keep if dif>=-1 & dif<=1 collapse (sum) ret ab_ra_ret ab_OI_10 ab_OI_20 ab_OI_30, by(country stock) sort country stock save "`output'/Temp_AVOL.dta", replace restore keep if dif>=2 & dif<=11 collapse (sum) CAR1=ab_ma_ret CAR2=ab_fa_ret CAR3=ab_ra_ret CAR4=ret, by(country stock) sort country stock merge country stock using "`output'/Temp_AVOL.dta" drop _merge erase "`output'/Temp_AVOL.dta" preserve statsby b_r=_b[ret] s_r=_se[ret] b_R=_b[ab_OI_20] s_R=_se[ab_OI_20] obs=e(N) R2=e(r2), clear by(country): reg CAR1 ret ab_OI_20 replace s_r=b_r/s_r replace s_R=b_R/s_R