clear
set more off

***********************************************
* Representation of SCM results
***********************************************

foreach limit in 0 1{

foreach dep in abret comply dist{

********************************************************************************
use "$temp/scm_individual_dependent_variables", clear

keep if dep == "`dep'"

********************************************************************************
gen quality_pre = sqrt(pre_gap^2)
local quality_limit = quality_pre[1]

local post_gap = post_gap[1]

quietly{
use "$temp/scm_individual_placebo", clear
keep if dep == "`dep'"

gen quality_pre = sqrt(pre_gap^2)

if `limit' == 1{
keep if quality < 2 * `quality_limit'
local text_limit = "quality_limit"
}
if `limit' == 0{
local text_limit = "no_quality_limit"
}

if "`dep'" == "abret"{
count if post_gap > `post_gap'
}
if "`dep'" != "abret"{
count if post_gap < `post_gap'
}
local p_post = r(N)/(_N+1)


renvars pre_gap post_gap \ gap_0 gap_1


foreach stat in p5 p10 p25 p50 p75 p90 p95 mean{
preserve
collapse (`stat') gap_*,  by(dep)
reshape long gap_, i(dep) j(t) string
ren gap_ `stat'
tempfile tmp_`stat'
save `tmp_`stat'', replace
restore
}

keep in 1

reshape long gap_, i(dep) j(t) string
keep dep t

foreach stat in p5 p10 p25 p50 p75 p90 p95 mean{
merge 1:1 dep t using `tmp_`stat''
drop _merge
}

destring t, replace

tempfile tmp
save `tmp', replace

********************************************************************************
use "$temp/scm_individual_dependent_variables", clear

keep if dep == "`dep'"

*******************************************************************************

renvars pre_gap post_gap \ gap_0 gap_1

keep gap_* dep

reshape long gap_, i(dep) j(t) string
destring t, replace

merge 1:1 dep t using `tmp'
drop _merge

********************************************************************************
* Figure A3
********************************************************************************

if `limit' == 0{ // Draw only for limit == 0

if "`dep'" == "abret"{
twoway scatteri -0.025 -0.5 0.025 1 0 0.5 0 1.5, mcolor(white) msymbol(none) ///
|| rcap p95 p5 t if dep == "`dep'", color(gs12) ///
|| rcap p90 p10 t if dep == "`dep'", color(gs10) ///
|| rcap p75 p25 t if dep == "`dep'", color(gs8) ///
|| scatter gap_ t if dep == "`dep'", connect(direct) mcolor(black) lcolor(black) lpattern(solid) msize(large) msymbol(O) ///
|| scatter mean t if dep == "`dep'", msymbol(O) mcolor(black) mfcolor(white) ///
|| , yline(0, lcolor(black) lwidth(vthin)) xline(0.5, lcolor(black) lwidth(vthin)) ///
	ylabel(-0.02(0.01)0.02 0 "0", angle(0) nogrid format(%9.2fc)) yscale(titlegap(-3)) ///
	ytitle("Relative abnormal returns following" "stock purchases by {it:Sarkozy associates}" " ") ///
	bgcolor(white) graphregion(color(white)) plotregion(margin(zero)) xsize(4) ysize(3) ///
	legend(col(1) order(5 "{it:Sarkozy associates} synthetic control method estimate" ///
	6 "Mean of placebo group estimates" ///
	4 "25-75th percentiles interval of placebo group estimates" ///
	3 "10-90th percentiles interval of placebo group estimates" ///
	2 "5-95th percentiles estimates of placebo group estimates" ///
	) region(lstyle(none) lcolor(white))) ///
	xlabel(0 "Pre-election" 1 "Post-election", labsize(small))
}

if "`dep'" == "comply"{
twoway scatteri -0.35 -0.5 0.35 1 0 0.5 0 1.5, mcolor(white) msymbol(none) ///
|| rcap p95 p5 t if dep == "`dep'", color(gs12) ///
|| rcap p90 p10 t if dep == "`dep'", color(gs10) ///
|| rcap p75 p25 t if dep == "`dep'", color(gs8) ///
|| scatter gap_ t if dep == "`dep'", connect(direct) mcolor(black) lcolor(black) lpattern(solid) msize(large) msymbol(O) ///
|| scatter mean t if dep == "`dep'", msymbol(O) mcolor(black) mfcolor(white) ///
|| , yline(0, lcolor(black) lwidth(vthin)) xline(0.5, lcolor(black) lwidth(vthin)) ///
	ylabel(-0.30(0.10)0.30 0 "0", angle(0) nogrid format(%9.2fc)) yscale(titlegap(0)) ///
	ytitle("{it:Sarkozy associates}' relative probability" "to comply with disclosure requirements" " ") ///
	bgcolor(white) graphregion(color(white)) plotregion(margin(zero)) xsize(4) ysize(3) ///
	legend(col(1) order(5 "{it:Sarkozy associates} synthetic control method estimate" ///
	6 "Mean of placebo group estimates" ///
	4 "25-75th percentiles interval of placebo group estimates" ///
	3 "10-90th percentiles interval of placebo group estimates" ///
	2 "5-95th percentiles estimates of placebo group estimates" ///
	) region(lstyle(none) lcolor(white))) ///
	xlabel(0 "Pre-election" 1 "Post-election", labsize(small))
}

if "`dep'" == "dist"{

twoway scatteri -75 -0.5 75 1 0 0.5 0 1.5, mcolor(white) msymbol(none) ///
|| rcap p95 p5 t if dep == "`dep'", color(gs12) ///
|| rcap p90 p10 t if dep == "`dep'", color(gs10) ///
|| rcap p75 p25 t if dep == "`dep'", color(gs8) ///
|| scatter gap_ t if dep == "`dep'", connect(direct) mcolor(black) lcolor(black) lpattern(solid) msize(large) msymbol(O) ///
|| scatter mean t if dep == "`dep'", msymbol(O) mcolor(black) mfcolor(white) ///
|| , yline(0, lcolor(black) lwidth(vthin)) xline(0.5, lcolor(black) lwidth(vthin)) ///
	ylabel(-60(30)60 0 "0", angle(0) nogrid) yscale(titlegap(0)) ///
	ytitle("Relative number of days between" "trades made by {it:Sarkozy associates}"  "and firm's next result announcement" " ") ///
	bgcolor(white) graphregion(color(white)) plotregion(margin(zero)) xsize(4) ysize(3) ///
	legend(col(1) order(5 "{it:Sarkozy associates} synthetic control method estimate" ///
	6 "Mean of placebo group estimates" ///
	4 "25-75th percentiles interval of placebo group estimates" ///
	3 "10-90th percentiles interval of placebo group estimates" ///
	2 "5-95th percentiles estimates of placebo group estimates" ///
	) region(lstyle(none) lcolor(white))) ///
	xlabel(0 "Pre-election" 1 "Post-election", labsize(small))
}

graph export "$graphs/scm_individual_`dep'_`text_limit'.png", replace
graph export "$graphs/scm_individual_`dep'_`text_limit'.eps", replace

} // End of if `limit' == 0{ // Draw only for limit == 0

} // End of quietly

********************************************************************************
* Table 5, bottom panel
********************************************************************************

di %9.3fc `post_gap' " p-value: (" %04.3fc  `p_post' ")"

} // End of foreach dep in abret comply dist{
}

