* Table Creation Demo- * Eric Smith for Iannuzzi Lab Meeting 9/3/2021 webuse "nhanes2.dta",clear ssc install table1_mc help table1_mc // help file so you can learn the syntax ssc install esttab help esttab // help file for your reference /*codebook to see whats in here but for sake of time will skip */ * Goal: Demonstrate risk factors for Myocardial Infarction with nhanes dataset. *Creating and labeling variables of interest * MI lab def heartatk 1 "MI" 0 "No MI" lab val heartatk heartatk lab var heartatk "MI" * Anemia recode hgb (0/10=1) (10/20=0) ,gen (anemic10) lab def anemic10 1 "hgb <10" 0 "hgb >=10", modify lab val anemic10 anemic10 lab variable anemic10 "Anemia" * Hypertension recode bpsystol (0/140=0) (140/310=1), gen(htn) lab def htn 1 "Systolic BP >140" 0 "Systolic BP <=140", modify lab val htn htn lab var htn "Hypertension" * Hypoalbuinemia recode albumin (0/3.49=1) (3.5/6=0) , gen(lowalb) lab def lowalb 1 "Albumin <3.5 " 0 "Albumin >=3.5", modify lab val lowalb lowalb lab variable lowalb "Hypoalbuminemia" *Black lab def black 1 "Black" 0 "White/Other", modify lab val black black lab variable black "Black" * Rural lab def rural 1 "Rural" 0 "Non-Rural", modify lab val rural rural lab variable rural "Rural" * Female lab def female 1 "Female" 0 "Male" lab val female female label var female "Female" * BMI groups recode bmi (0/18.5=1) (18.5/30=0) (30/70=2), gen(bmi_g) lab def bmi_g 0 "Normal/Overweight" 1 "Underweight" 2 "Obese" lab val bmi_g bmi_g lab var bmi_g "BMI Groups" * obesity recode bmi (0/30=0) (30/70=1) ,gen(obese) lab def obese 1 "Obese" 0 "Normal or Underweight" lab val obese obese lab var obese "Obese" * male // because this group had MI risk and simpler to have this in model gen male=0 replace male=1 if female==0 lab def male 1 "Male" 0 "Female" lab val male male lab var male "Male" * defining variables that did not have definitions lab variable race "Race" lab variable region "Region" lab variable alb "Serum Albumin (g/dL)" lab variable hgb "Hemoglobin (g/dL)" lab variable age "Age (years)" lab variable agegrp "Age group" * Table 1 preserve /// must "preserve" when you run code to export to word doc (notice "clear" at row 99: this will delete everything unless you preserve) table1_mc, by (heartatk) /// dependent variable total(before) /// adds a totals column onecol /// stacks the different levels on same column as variable name - delete this to see what it looks like the other way sdleft("±") sdright("") /// shows SD with ± sign instead of within parentheses percsign("") /// can control how % sign is displayed. by using quotations with nothing inside them it says to omit format(%4.1f) /// 4 leading zeros with 1 sig fig catrowperc /// shows by row stats - default is column percents so drop this distinction to get column vars(age contn\ agegrp cat\ female cat\ region cat\ rural cat\ race cat\ /// variables black cat\ bmi contn\ bmi_g cat\ obese cat\ albumin contn\ lowalb cat\ hgb contn\ anemic10 cat\ ) /// saving(NHANES_Table1_example.xls, replace) clear // clear is important because you have to clear the way it was stored for the next step to work table1_mc_dta2docx using "C:\Users\Eric Smith\Desktop\Vascular Research\NHANES_Table1_example.docx", replace restore // restores everything back to the way it was after it was "cleared" * If you wanted to see what test statistics were done you just put "test" in syntax * unfortunately I dont think you can add a title to this from this point /* table1_mc, by (heartatk) /// test /// specifies which statistics done. overkill for the actual table but helpful for you to know total(before) /// onecol /// sdleft("±") sdright("") /// percsign("") /// format(%4.1f) /// catrowperc /// vars(age contn\ agegrp cat\ female cat\ region cat\ rural cat\ race cat\ /// black cat\ bmi contn\ bmi_g cat\ obese cat\ albumin contn\ lowalb cat\ hgb contn\ anemic10 cat\ ) /// saving(NHANES_Table1_example.xls, replace) */ /* You will learn about this in future TICR courses but to simplify what variables are put into the model you justify by: 1) DAG - conceptually based confounders 2) p-value based (entry criteria p<0.2 or p<0.1 with exit criteria which you should define a priori 3) some combination of the two 4) none of the above- theres a lot of ways to decide what goes in 2) Based on bivariate summary statistics p<0.1 agegrp sex rural obese albumin - lots of missingness here so model will be limited by this variable- consider imputation but i'm going to drop for simplicity region */ * logistic model begin: logistic heartatk i.agegrp male i.region rural obese lroc, nograph // gives the ROC curve or C statistic estimates store m1_NHANES_example // stores the point estimates from the model above in name "m1_NHANES_example" esttab // looks terrible- no odds ratios, theres one column, a random (1) and weird variable labeling esttab, eform // eform: exponentiates the point estimate which creates an odds ratio esttab, eform nonumber // nonumber: drops the weird (1) esttab, eform nonumber nodepvar // nodepvar: drops the header that says heartatk esttab, eform nonumber nodepvar noobs // noobs: drops the "N" row at bottom that shows the number the entire model was run with esttab, eform nonumber nodepvar noobs nonotes // nonotes: drops the legend of p-value significance - can keep if you want depending on journal but bolding may be sufficient esttab, eform nonumber nodepvar noobs nonotes nomtitle // nomtitle: drops the model name esttab, eform nonumber nodepvar noobs nonotes nomtitle addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") // addnotes:footnote fyi " " makes new line esttab, eform nonumber nodepvar noobs nonotes nomtitle addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// cell((b ci p)) // cell is what adds contents column: b= odds ratio; ci = conf interv; p =p-value esttab, eform nonumber nodepvar noobs nonotes nomtitle addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// cell((b (label(AOR)) ci (label(95% CI)) p (label(p-value)))) //within cells you use label(insert name here) next to the stat to name the columns esttab, eform nonumber nodepvar noobs nonotes nomtitle addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// cell((b (label(AOR) fmt(%9.1f)) ci (label(95% CI)fmt(%9.1f)) p (label(p-value)fmt(%9.2f)))) //fmt(%9._f): changes the sig figs shown esttab, eform nonumber nodepvar noobs nonotes nomtitle nobaselevels addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// cell((b (label(AOR) fmt(%9.1f)) ci (label(95% CI)fmt(%9.1f)) p (label(p-value)fmt(%9.2f)))) /// nobaselevels: drops the reference groups esttab, eform nonumber nodepvar noobs nonotes nomtitle nobaselevels addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// cell((b (label(AOR) fmt(%9.1f)) ci (label(95% CI)fmt(%9.1f)) p (label(p-value)fmt(%9.2f)))) // add parentheses to the CI intervals esttab, eform nonumber nodepvar noobs nonotes nomtitle nobaselevels label /// label: change the variables to be presented as a label you created addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// cell((b (label(AOR) fmt(%9.1f)) ci (par("(" "-" ")") label(95% CI)fmt(%9.1f)) p (label(p-value)fmt(%9.2f)))) /* Since there are many multi-level variables here it is sort of annoying to label each level - i also dont know how yet. since we did so much work earlier labeling them lets just use the version that makes use of the "label" command and we will mannually add a row in the word document below is how you would change the name of the way the variable label is displayed if in this model we only had binary categorical variables it would work perfectly see below is me swapping age for agegrp */ logistic heartatk age male i.region rural obese estimates store m2 esttab, eform nonumber nodepvar noobs nonotes nomtitle nobaselevels label /// label: change the variables to be presented as a label you created addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// cell((b (label(AOR) fmt(%9.1f)) ci (par("(" "-" ")") label(95% CI)fmt(%9.1f)) p (label(p-value)fmt(%9.2f)))) * return to original model logistic heartatk i.agegrp male i.region rural obese esttab, eform nonumber nodepvar noobs nonotes nomtitle main(name) nobaselevels /// coeflabel(agegrp "Age group" male "Male" region "Region" rural "Rural" obese "Obese") /// addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// change the variable labels cell((b (label(AOR) fmt(%9.1f)) ci (par("(" "-" ")") label(95% CI)fmt(%9.1f)) p (label(p-value)fmt(%9.2f)))) // changed var label but now levels shown esttab, eform nonumber nodepvar noobs nonotes nomtitle nobaselevels label /// title("Table. Factors Associated with Myocardial Infarction") /// added title addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// cell((b (label(AOR) fmt(%9.1f)) ci (par("(" "-" ")") label(95% CI)fmt(%9.1f)) p (label(p-value)fmt(%9.2f)))) * Table we are happy with- lets export to word document. esttab using "C:\Users\Eric Smith\Desktop\Vascular Research\NHANES_model_example.rtf", /// file directory to where it saves but you can click hyperlink in output eform nonumber nodepvar noobs nonotes nomtitle nobaselevels label /// title("Table. Factors Associated with Myocardial Infarction") /// addnotes ("Can say what you adjusted for here" " " "C statistic= 0.82") /// cell((b (label(AOR) fmt(%9.1f)) ci (par("(" "-" ")") label(95% CI)fmt(%9.1f)) p (label(p-value)fmt(%9.2f)))) replace