* hansen2.do.  Covariate balance regressions and pictures.
use https://github.com/scunning1975/causal-inference-class/raw/master/hansen_dwi, clear

* Create treatment dummy for whether you were arrested for a DUI (bac1>=0.08 and you are arrested)
gen		dui = 0
replace dui = 1 if bac1>=0.08 & bac1~=.

* Recenter running variable
ren bac1 bac1_orig
label variable bac1_orig "BAC"
gen bac1=bac1_orig-0.08

* Checking for covariate balance
reg male dui##c.bac1 if bac1_orig>=0.03 & bac1_orig<=0.13, robust
reg white dui##c.bac1 if bac1_orig>=0.03 & bac1_orig<=0.13, robust
reg aged dui##c.bac1 if bac1_orig>=0.03 & bac1_orig<=0.13, robust
reg acc dui##c.bac1 if bac1_orig>=0.03 & bac1_orig<=0.13, robust

* Let's make a few nonparametric pictures using one of our graphing preferred commands
cmogram male bac1_orig if bac1_orig>=0.03 & bac1_orig<=0.13, scatter cut(0.08) line(0.08) lfit title(Male Driver)
graph save male_graph.gph, replace

cmogram white bac1_orig if bac1_orig>=0.03 & bac1_orig<=0.13, scatter cut(0.08) line(0.08) lfit title(White Driver)
graph save white_graph.gph, replace

cmogram aged bac1_orig if bac1_orig>=0.03 & bac1_orig<=0.13, scatter cut(0.08) line(0.08) lfit title(Age of Driver)
graph save aged_graph.gph, replace

cmogram acc bac1_orig if bac1_orig>=0.03 & bac1_orig<=0.13, scatter cut(0.08) line(0.08) lfit title(Driver in Accident)
graph save acc_graph.gph, replace

* Combine all four graphs
graph combine male_graph.gph white_graph.gph aged_graph.gph acc_graph.gph, ///
    title("Covariate Balance Across the BAC Running Variable")