/* This file generates the summary_output text file that FEM needs to generate summary measures. It is designed to generate prevalence, incidence, total, mean, and percentile summary statistics. Measures can be reported for the full population ("all") or by age ranges, gender, or race. The user needs to: 1. Provide a name for their output file (the local is called "filename") 2. Decide which measure to include. Knowledge of the variable names in FEM is required. (the local is named "measures") 3. Decide what subpopulations to include. (the local is named "subpop") */ set more off quietly include ../fem_env.do * Name of your input and output files local scen bio * Summary output file name local filename summary_output_`scen'.txt * Measures and subpopulations are defined here include measures_subpop_`scen'.do * Setup the file, header, and required outcomes ... * Open the file file open sumfile using "`filename'", write replace * The header file write sumfile "| Label,Description,Variable,Summary Type,Factor,Weight,Condition" _n * Generate the length of the lists local measures_l : word count `measures' local subpop_l : word count `subpop' * Now add our measures and subpopulations forvalues x = 1/`measures_l' { local a : word `x' of `measures' * Deal with particulars of prefixes if substr("`a'",1,1) == "q" { local vname = substr("`a'",5,.) } else { local vname = substr("`a'",3,.) } * For subpopulation forvalues y = 1/`subpop_l' { local b : word `y' of `subpop' di "b is `b'" *Selection logic if "`b'" == "all" { local sel local samp "all" } else if "`b'" == "wht" { local sel "& black == 0 & hispan == 0" local samp "white" } else if "`b'" == "his" { local sel "& hispan == 1" local samp "hispanic" } else if "`b'" == "blk"{ local sel "& black == 1" local samp "black" } else if "`b'" == "m" { local sel "& male == 1" local samp "male" } else if "`b'" == "f" { local sel "& male == 0" local samp "female" } else if "`b'" == "5154" { local sel "& age >= 51 & age < 55" local samp "age 51 to 54" } else if "`b'" == "5559" { local sel "& age >= 55 & age < 60" local samp "age 55 to 59" } else if "`b'" == "6064" { local sel "& age >= 60 & age < 65" local samp "age 60 to 64" } else if "`b'" == "6569" { local sel "& age >= 65 & age < 70" local samp "age 65 to 69" } else if "`b'" == "7074" { local sel "& age >= 70 & age < 75" local samp "age 70 to 74" } else if "`b'" == "7579" { local sel "& age >= 75 & age < 80" local samp "age 75 to 79" } else if "`b'" == "8084" { local sel "& age >= 80 & age < 85" local samp "age 80 to 84" } else if "`b'" == "8589" { local sel "& age >= 85 & age < 90" local samp "age 85 to 89" } else if "`b'" == "90p" { local sel "& age >= 90" local samp "age 90 plus" } else if "`b'" == "85p" { local sel "& age >= 85" local samp "age 85 plus" } else if "`b'" == "65p" { local sel "& age >= 65" local samp "age 65 plus" } * Prevalence measures if substr("`a'",1,1) == "p" { file write sumfile "`a'_`b',Prevalence of `vname': Sample= `samp',`vname',mean,1,weight,l2died==0`sel'" _n } * Incidence measures else if substr("`a'",1,1) == "i" { file write sumfile "`a'_`b',Incidence of `vname': Sample= `samp',`vname',mean,1,weight,l2died==0&l2`vname'==0`sel'" _n } * Sum measures (counts) else if substr("`a'",1,1) == "n" { file write sumfile "`a'_`b',Sum of `vname': Sample= `samp',`vname',sum,1,weight,l2died==0`sel'" _n } * Sum measures (costs) else if substr("`a'",1,1) == "t" { file write sumfile "`a'_`b',Sum of `vname': Sample= `samp',`vname',sum,1,weight,l2died==0`sel'" _n } else if substr("`a'",1,1) == "a" { file write sumfile "`a'_`b',Average of `vname': Sample= `samp',`vname',mean,1,weight,l2died==0`sel'" _n } * Average age at death else if substr("`a'",1,1) == "d" { file write sumfile "`a'_`b',Average `vname' at death: Sample= `samp',`vname',mean,1,weight,l2died==0&died==1`sel'" _n } else if substr("`a'",1,1) == "q" { local pcnt = substr("`a'",2,2) file write sumfile "`a'_`b',`pcnt' percentile of `vname': Sample = `samp',`vname',quantile-.`pcnt',1,weight,l2died==0`sel'" _n } else if substr("`a'",1,1) == "m" { if "`vname'" == "startpop" { file write sumfile "`a'_`b',`vname' (millions): Sample = `samp',weight,sum,0.000001,1,l2died == 0`sel'" _n } else if "`vname'" == "endpop" { file write sumfile "`a'_`b',`vname' (millions): Sample = `samp',weight,sum,0.000001,1,died == 0`sel'" _n } } } } *** Biomarker variables by disease level - disease == 1 local bio hdl tchol ldl a1c sysbp foreach x of local bio { file write sumfile "a_`x'_hearte_all,Average of `x' among hearte: Sample= all,`x',mean,1,weight,l2died==0 & hearte == 1" _n file write sumfile "a_`x'_hearte_wht,Average of `x' among hearte: Sample= white,`x',mean,1,weight,l2died==0 & hearte == 1 & black == 0 & hispan == 0" _n file write sumfile "a_`x'_hearte_blk,Average of `x' among hearte: Sample= black,`x',mean,1,weight,l2died==0 & hearte == 1 & black == 1" _n file write sumfile "a_`x'_hearte_his,Average of `x' among hearte: Sample= hispanic,`x',mean,1,weight,l2died==0 & hearte == 1 & hispan == 1" _n } foreach x of local bio { file write sumfile "a_`x'_diabe_all,Average of `x' among diabe: Sample= all,`x',mean,1,weight,l2died==0 & diabe == 1" _n file write sumfile "a_`x'_diabe_wht,Average of `x' among diabe: Sample= white,`x',mean,1,weight,l2died==0 & diabe == 1 & black == 0 & hispan == 0" _n file write sumfile "a_`x'_diabe_blk,Average of `x' among diabe: Sample= black,`x',mean,1,weight,l2died==0 & diabe == 1 & black == 1" _n file write sumfile "a_`x'_diabe_his,Average of `x' among diabe: Sample= hispanic,`x',mean,1,weight,l2died==0 & diabe == 1 & hispan == 1" _n } foreach x of local bio { file write sumfile "a_`x'_stroke_all,Average of `x' among stroke: Sample= all,`x',mean,1,weight,l2died==0 & stroke == 1" _n file write sumfile "a_`x'_stroke_wht,Average of `x' among stroke: Sample= white,`x',mean,1,weight,l2died==0 & stroke == 1 & black == 0 & hispan == 0" _n file write sumfile "a_`x'_stroke_blk,Average of `x' among stroke: Sample= black,`x',mean,1,weight,l2died==0 & stroke == 1 & black == 1" _n file write sumfile "a_`x'_stroke_his,Average of `x' among stroke: Sample= hispanic,`x',mean,1,weight,l2died==0 & stroke == 1 & hispan == 1" _n } file write sumfile "a_sysbp_hibpe_all,Average of sysbp among hibpe: Sample= all,sysbp,mean,1,weight,l2died==0 & hibpe == 1" _n file write sumfile "a_sysbp_hibpe_wht,Average of sysbp among hibpe: Sample= white,sysbp,mean,1,weight,l2died==0 & hibpe == 1 & black == 0 & hispan == 0" _n file write sumfile "a_sysbp_hibpe_blk,Average of sysbp among hibpe: Sample= black,sysbp,mean,1,weight,l2died==0 & hibpe == 1 & black == 1" _n file write sumfile "a_sysbp_hibpe_his,Average of sysbp among hibpe: Sample= hispanic,sysbp,mean,1,weight,l2died==0 & hibpe == 1 & hispan == 1" _n file close sumfile capture log close