********************************************************************************
************************************
clear all
set more on 
set matsize 11000
#delimit ;

local I_d "I_m_61 I_m_60 I_m_59 I_m_58 I_m_57 I_m_56 I_m_55 I_m_54 I_m_53 I_m_52 I_m_51 I_m_50 I_m_49 I_m_48 I_m_47 I_m_46 I_m_45 I_m_44 I_m_43 I_m_42 I_m_41 I_m_1 I_m_39 I_m_38 I_m_37 I_m_36 I_m_1 I_m_0.8 I_m_33 I_m_32 I_m_31 I_m_30 I_m_29 I_m_28 I_m_27 I_m_26 I_m_25 I_m_24 I_m_23 I_m_22 I_m_21 I_m_20 I_m_19 I_m_18 I_m_17 I_m_16 I_m_15 I_m_14 I_m_13 I_m_12 I_m_11 I_m_10 I_m_9 I_m_8 I_m_7 I_m_6 I_m_5 I_m_4 I_m_3 I_m_2 I_m_1 I_p_0 I_p_1 I_p_2 I_p_3 I_p_4 I_p_5 I_p_6 I_p_7 I_p_8 I_p_9 I_p_10 I_p_11 I_p_12 I_p_13 I_p_14 I_p_15 I_p_16 I_p_17 I_p_18 I_p_19 I_p_20 I_p_21 I_p_22 I_p_23 I_p_24 I_p_25 I_p_26 I_p_27 I_p_28 I_p_29 I_p_30 I_p_31 I_p_32 I_p_33 I_p_0.8 I_p_1 I_p_36";
local I "I_m_l  I_m_30 I_m_29 I_m_28 I_m_27 I_m_26 I_m_25 I_m_24 I_m_23 I_m_22 I_m_21 I_m_20 A I_m_18 I_m_17 I_m_16 I_m_15 I_m_14 I_m_13 I_m_12 I_m_11 I_m_10 I_m_9 I_m_8 I_m_7 I_m_6 I_m_5 I_m_4 I_m_3 I_m_2 I_m_1 I_p_0 I_p_1 I_p_2 I_p_3 I_p_4 I_p_5 I_p_6 I_p_7 I_p_8 I_p_9 I_p_u";

local J "J_p_0 J_p_1 J_p_2 J_p_3 J_p_4 J_p_5 J_p_6 J_m_1 J_m_2 J_m_3 J_m_4 J_m_5 J_m_6 J_m_7 J_m_8 J_m_9 J_m_19 J_m_10 J_m_11 J_m_12 J_m_13 J_m_14 J_m_15 J_m_16 J_m_17 J_m_18  J_m_20 J_m_21 ";
local fe1 "i.bpl i.birth_cohort##i.ymcaid";
local bpl_med_cont "hpc bpc pcinc";
local bpl_byear_cont "female_sy sei_score_sy home_owner_sy  literate_sy flfpr_sy ";
local mom_cont "any_pren_visits is_mom_married";
local bpl_covars_trend "c.birth_cohort##c.tranpcfsp_s0 c.birth_cohort##c.hpc c.birth_cohort##c.bpc c.birth_cohort##c.pcinc";


local w "[w=birth_count]";
local cluster1 "cluster(bpl)";

local y "fetal_growth";

use .\..\..\data\output\natality_1969_2004_clean_collapsed_merged_cohort_var_def , clear ;

gen A=0;
label var A "-19" ;  



reghdfe    `y'  `I' 
`bpl_med_cont'  `bpl_byear_cont' `mom_cont' `bpl_covars_trend'
  if is_white==0
 `w' ,  absorb(`fe1') `cluster1' ;

coefplot  , keep( `I' ) xline(13,lcolor(dkgreen))  xline(32,lcolor(dkgreen) lwidth(thin))  yline(0) omitted  vertical 
	level(90) xlabel( ,  labsize(vsmall) angle(vertical)) 
	ylabel(,labsize(vsmall))
	msymbol(triangle) mcolor(black) msize(small) lcolor(black) lpattern(line) lwidth(vvthin)
    ciopts(recast(rcap) lcolor("153 0 102") )
	ylabel(-1(0.5)1 ,  labsize(vsmall)) 
	yscale(range(-1 1)) 
	text( 0.8 7 "Unexposed:""[-30,-19]",  size(small))
	text( 0.8 22 "Partially Exposed:" "[-18,-1]",  size(small))
	text( 0.8 37 "Fully Exposed:" "[0,+10]",  size(small))
	ytitle("Fetal Growth", size(small)) 
	xtitle("Birth Year - Year of Medicaid Implementation" , size(small))
	title("Nonwhites",size(small))
    name(first);
	graph save .\..\..\data\interwrk\\`y'_nw.gph , replace ;
	graph export .\..\..\data\interwrk\\`y'_nw.emf , replace ;
	
	  

reghdfe    `y'  `I' 
`bpl_med_cont'  `bpl_byear_cont' `mom_cont' `bpl_covars_trend'
  if is_white==1
 `w' ,  absorb(`fe1') `cluster1' ;

coefplot  , keep( `I' ) xline(13,lcolor(dkgreen))  xline(32,lcolor(dkgreen) lwidth(thin))  yline(0) omitted  vertical 
	level(90) xlabel( ,  labsize(vsmall) angle(vertical)) 
	ylabel(,labsize(vsmall))
	msymbol(triangle) mcolor(black) msize(small) lcolor(black) lpattern(line) lwidth(vvthin)
    ciopts(recast(rcap) lcolor("153 0 102") )
	ylabel(-1(0.5)1 ,  labsize(vsmall)) 
	yscale(range(-1 1)) 
	text( 0.8 7 "Unexposed:""[-30,-19]",  size(small))
	text( 0.8 22 "Partially Exposed:" "[-18,-1]",  size(small))
	text( 0.8 37 "Fully Exposed:" "[0,+10]",  size(small))
	ytitle("Fetal Growth", size(small)) 
	xtitle("Birth Year - Year of Medicaid Implementation" , size(small))
	title("Whites",size(small))
    name(second);
	graph save .\..\..\data\interwrk\\`y'_w.gph , replace ;
	graph export .\..\..\data\interwrk\\`y'_w.emf , replace ;
	
	
	#delimit;
	clear all ;
	foreach stub in `y' { ;
	graph combine  .\..\..\data\interwrk\\`stub'_nw.gph 
				   .\..\..\data\interwrk\\`stub'_w.gph 			   
	               , cols(1) ysize(12) xsize(10) ;
	graph save .\..\..\figs\figure_9.gph , replace;
	graph export .\..\..\figs\figure_9.emf, replace;
  } ;
  
