clear
set more off

********************************************************************************
* Preamble
********************************************************************************

global ctrl_ind executive inter_executive log_eur_amount inter_log_eur_amount

********************************************************************************
* Table 2 (and A1), panel A
********************************************************************************

* Regression table
global export_file "$tables/table_2_A.xls"
capture erase "$tables/table_2_A.txt"
capture erase "$export_file"
global export outreg2 using "$export_file", dec(3) nocons label nor2

foreach dep in abret comply dist{

use "$temp/final_data", clear

* Select dependent variable
if "`dep'" == "abret"{ // Abnormal returns on purchases at announcement date
local var an_abret_index_SBF120_30_1
keep  if  type == "Purchase"
local cluster_list "id_firm id_ind id_announcementdate"
}
if "`dep'" == "comply"{ // Compliance with legal reporting requirements
local var diff_comply
local cluster_list "id_firm id_ind id_transactiondate"
}
if "`dep'" == "dist"{ //  Time to next public announcement
local var dist_next_res_all
local cluster_list "id_firm id_ind id_transactiondate"
}

* No controls
********************************************************************************
reghdfe `var' after connect inter if sample_res == 1, vce(cluster `cluster_list') absorb(t)
$export
foreach exvar in after connect inter{
local `dep'_`exvar'_res_nct_nfe_co = _b[`exvar']
local `dep'_`exvar'_res_nct_nfe_se = _se[`exvar']
local `dep'_`exvar'_res_nct_nfe_st = _b[`exvar']/_se[`exvar']
}
* Firm FE and controls
********************************************************************************
reghdfe `var' after connect inter $ctrl_ind if sample_res == 1, vce(cluster `cluster_list') absorb(id_firm)
$export addtext(Firm fixed effects, "Yes") noobs
foreach exvar in after connect inter{
local `dep'_`exvar'_res_ct_fe_co = _b[`exvar']
local `dep'_`exvar'_res_ct_fe_se = _se[`exvar']
local `dep'_`exvar'_res_ct_fe_st = _b[`exvar']/_se[`exvar']
}
} // End of foreach dep in abret comply dist{

* Store DiD estimates
********************************************************************************

clear
set obs 1
foreach dep in abret comply dist{
foreach exvar in after connect inter{
foreach text in nct_nfe ct_fe{
foreach suffix in co se st{
gen `dep'_`exvar'_res_`text'_`suffix' = .
}
}
}
}

foreach dep in abret comply dist{
foreach exvar in after connect inter{
foreach text in nct_nfe ct_fe{
foreach suffix in co se st{
replace `dep'_`exvar'_res_`text'_`suffix' = ``dep'_`exvar'_res_`text'_`suffix''
}
}
}
}

save "$temp/did_estimates", replace

********************************************************************************
* Table 2 (and A1), panel B
********************************************************************************

* Regression table
global export_file "$tables/table_2_B.xls"
capture erase "$tables/table_2_B.txt"
capture erase "$export_file"
global export outreg2 using "$export_file", dec(3) nocons label nor2

foreach dep in abret comply dist{

use "$temp/final_data", clear

* Select dependent variable
if "`dep'" == "abret"{ // Abnormal returns on purchases at announcement date
local var an_abret_index_SBF120_30_1
keep  if  type == "Purchase"
local cluster_list "id_firm id_ind id_announcementdate"
}
if "`dep'" == "comply"{ // Compliance with legal reporting requirements
local var diff_comply
local cluster_list "id_firm id_ind id_transactiondate"
}
if "`dep'" == "dist"{ //  Time to next public announcement
local var dist_next_res_all
local cluster_list "id_firm id_ind id_transactiondate"
}

* Firm fixed effects interacted with post_election dummy
********************************************************************************
egen id_firm_2 = group(id_firm after)
replace id_firm_2 = 0 if after == 0

reghdfe `var' connect inter $ctrl_ind if sample_res == 1,   vce(cluster `cluster_list') absorb(id_firm id_firm_2)
$export addtext(Firm fixed effects, "Yes", Post-election $\times$ firm fixed effects, "Yes")  noobs

* Group-specific time trends
********************************************************************************
gen trend = transactiondate
gen trend_spe = trend * connect

reghdfe `var' after connect inter trend trend_spe $ctrl_ind if sample_res == 1 , vce(cluster `cluster_list') absorb(id_firm)
$export keep(connect after inter $ctrl_ind) addtext(Firm fixed effects, "Yes", Group-specific trends, "Yes")  noobs
}
