* Adapted from programs found here https://www.hsph.harvard.edu/miguel-hernan/causal-inference-book/ ; /******************************************************************* PROGRAM 15.1 Estimating the average causal effect within levels of confounders under the assumption of effect-measure modification by smoking intensity ONLY Data from NHEFS ********************************************************************/; libname causinf "C:\dropbox\ci\data"; * ods html close; * use this option for output as text rather than html; /* some preprocessing of the data */ data nhefs; set causinf.nhefs_book; if . 0)) noprint ; var mean ; by interv ; output out=diffstd (keep = interv std) std = std ; run; * for bootstrap find std of each mean for bsample > 0 ; proc means data = results (where = (bsample > 0)) noprint ; class interv ; var mean; types interv ; output out = stderrs (keep = interv std ) std = std ; run; data sample0; set results (where = (bsample = 0)) for_diff (where = (bsample = 0)) ; drop bsample ; run; data stderrs ; set stderrs diffstd ; run; data finalres; merge sample0 stderrs ; by interv ; lb = mean - 1.96 * std ; ub = mean + 1.96 * std ; label lb="95% Lower bound" ub="95% Upper bound" std="Standard Error" ; run; proc print data = finalres label noobs ; title1 "Parametric g-formula"; title2 "Bootstrap results using &nboot samples" ; format interv interv. ; var interv mean std lb ub ; run;