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

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 x " c.birth_cohort##c.tranpcret_s0 c.birth_cohort##c.tranpcmed_s0 c.birth_cohort##c.tranpcmcare1_s0 c.birth_cohort##c.tranpcpa_s0 c.birth_cohort##c.tranpcpa1_s0 c.birth_cohort##c.tranpcssi_s0  ";

local y " lbw very_lbw extreme_lbw tbw3742 sga fetal_growth gest_weeks preterm apgar_score_five_min" ;

local v1 "exp_age_0_before ";

local doc1 "keep(exp_age_0_before) nest label dec(4)"	;
local w "[w=birth_count]";
local cluster1 "vce(cluster bpl)";


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

/******************************************************************************/
foreach p of num 1 { ;
foreach q of num 0 { ;
reghdfe child_weight `v1' 
`bpl_med_cont'  `bpl_byear_cont' `mom_cont' `bpl_covars_trend'  if is_white==`q' & child_sex==`p'
 `w'  , absorb(`fe1') `cluster1'  keepsingletons ;
estadd ysumm;
local a : di %4.3f e(ymean);
local b=_b[exp_age_0_before] ;
local c : di %4.3f 100*`b'/`a' ;

asdoc reghdfe child_weight `v1' 
`bpl_med_cont'  `bpl_byear_cont' `mom_cont' `bpl_covars_trend' if is_white==`q' & child_sex==`p' `w'  ,
 absorb(`fe1') `cluster1'  keepsingletons 
 save(.\..\..\tables\table_5_girls.doc) add(Mean DV, `a', Pct. Effect, `c' ) replace `doc1'  ;

foreach stub in `y' { ;

reghdfe `stub' `v1' 
`bpl_med_cont'  `bpl_byear_cont' `mom_cont' `bpl_covars_trend' if is_white==`q' & child_sex==`p'
 `w'  , absorb(`fe1') `cluster1'  keepsingletons ;
estadd ysumm;
local a : di %4.3f e(ymean);
local b=_b[exp_age_0_before] ;
local c : di %4.3f 100*`b'/`a' ;

asdoc reghdfe `stub' `v1' 
`bpl_med_cont'  `bpl_byear_cont' `mom_cont' `bpl_covars_trend' if is_white==`q'  & child_sex==`p' `w'  ,
 absorb(`fe1') `cluster1'  keepsingletons 
 save(.\..\..\tables\table_5_girls.doc) add(Mean DV, `a', Pct. Effect, `c' ) append `doc1'  ;
};
};
} ;		
