* Biostat 212 Lecture 7 * Code from practice slides use "acupuncture.dta" **** *practice #1 slide 8 * What is the 95% CI around the mean post-study headache score in the intervention group? ci mean posths if group==1 * What is the 95% CI around the mean post-study headache score in the control group? ci mean posths if group==0 **** *practice #2 slide 14 * Check how the categorical variables sex, migraine, group, and response are coded using a local macro. local catvar "sex migraine group response" codebook `catvar' * Side note * Tempting to use tab but it won't work--> have to use a loop (more to come!) * Also need to run local macro with each separate "do"! foreach var of local catvar { tab `var' } foreach var of local catvar { di "`var'" tab `var' } * Compare 2 regression models for the continuous outcome “posths” on group and age in one model, and group, age, and sex in the second. Create local macros for the 2 sets of covariates and run linear regression models using the macros. local model1var "group age" regress posths `model1var' local model2var "group age sex" regress posths `model2var' **** * practice #3 slide 19 * What percentage of study participants are female, report migraines, and showed >35% improvement in headache score by intervention group? foreach var of varlist sex migraine response { di "group x `var'" tab group `var', row } * What are the 95% CIs around the mean baseline headache score, post-study headache score, and one-year headache score in the intervention and control groups? foreach var of varlist basehs posths oneyrhs { ci mean `var' if group==1 ci mean `var' if group==0 } **** * slide 18 example webuse nhanes2 ** Foreach loop example foreach var of varlist age height weight bpsystol { sum `var' if region==1 histogram `var' if region==1 } * This is equivalent to: sum age if region==1 histogram age if region==1 sum height if region==1 histogram height if region==1 sum weight if region==1 histogram weight if region==1 sum bpsystol if region==1 histogram bpsystol if region==1 ***************** /* KD curse example */ **** practice slide 30 use "KDcurse_data.dta", clear * Giants win probability by year* tabstat win, by(year) stat(mean) *Giants win probability by era * tabstat win, by(era) stat(mean) *Giants win probabililty by home vs away* tabstat win, by(home) stat(mean) **** practice slide 32 *Risk ratio* cs win KD **** practice slide 38 *Odds ratio* cc win KD mhodds win KD *Odds ratio adjusting for home vs away* cc win KD, by(home) mhodds win KD, by(home) **** practice slide 41 *logistic regression* logistic win KD *adjust for day vs night * logit win KD daygame, or ******* extra code /* Graph Giants win loss over era */ graph bar win, over(era) graph export "output/KDcursegraph.png", replace putdocx clear putdocx begin putdocx paragraph, halign(center) putdocx image "output/KDcursegraph.png" putdocx save "output/thecurseisreal.docx", replace /* Confidence interval */ ci means attendance /* For loop example: run CC win by: year, KD, era, day of week (dow) */ *encode dow* codebook dow encode dow, gen(dow_cat) codebook dow_cat foreach var in home dow_cat { display "`var'" cc win KD, by(`var') }