global program "EEREV-D-21-00004_FigureB5"

cap log close
cap log using "$log\log_$program$today", replace

**** REPLICATION OF FIGURE B5 ****

clear all
set mem 2g
set more off

/*	
	OUTLINE
	1. DESCRIPTIVE GRAPHS
*/

*********************************
***** 1. DESCRIPTIVE GRAPHS *****
*********************************

// Import candidate data

use $data\EEREV-D-21-00004_Data_Candidates.dta, clear

// Change years to have more space

tostring annee, g(annee_str)
recode annee (1969=1971) (1974=1977) (1995=1991) (2002=1999) (2007=2005) (2012=2011), g(annee_tmp)
labmask annee_tmp, values(annee_str)

sort annee

// Left-hand-side graph

twoway (scatter neg_D annee_tmp, mcolor(navy) msize(small)) ///
	(scatter neg_D annee_tmp [w=poll], msymbol(Oh) mcolor(maroon) mlwidth(thin)) /// mlstyle(dotmark) ///
	, yline(0, lpattern(..-) lcolor(gs8)) graphregion(color(white)) ///
	legend(label(1 "Position") label(2 "Polls") order(1 2) cols(1) symx(*0.5) region(col(white)) pos(10) ring(0)) ///   
	ytitle("Difference from election weighted average", margin(vsmall)) ///
	xtitle("Election year", margin(medium)) name(posneg, replace) ///
	ylabel(-.2 0 .2 .4, angle(0) format(%5.1f)) yscale(r(-.26 .46)) ///
	xlabel(1965 1971 "1969" 1977 "1974" 1991 "1995" 1999 "2002" 2005 "2007" 2011 "2012" 2017) xscale(r(1960 2022)) //

// Right-hand-side graph

twoway (scatter neg_P annee_tmp, c(l) lpattern(dash) lcolor(maroon) mcolor(navy)) /// msymbol(S)
	, yline(0, lpattern(..-) lcolor(gs8)) graphregion(color(white)) ///
	legend(label(1 "Polarization") order(1) cols(1) symx(*0.5) region(col(white))) ///  pos(2) ring(0) 
	ytitle("Dalton (2008)'s polarization index", margin(vsmall)) ///
	xtitle("Election year", margin(medium)) name(dalton, replace) ///
	ylabel(0 .05 .1 .15, angle(0) format(%5.2f)) yscale(r(-.015 .165)) ///
	xlabel(1965 1971 "1969" 1977 "1974" 1991 "1995" 1999 "2002" 2005 "2007" 2011 "2012" 2017) xscale(r(1960 2022)) //

// Combine graphs

graph combine posneg dalton ///
	, c(2) graphregion(color(white)) imargin(vsmall) //ycommon
graph export "$results\\$program.png", replace width(7200) height(3000)

cap log close

