**Setup *Change working directory -- modify filepath to your directory cd "/Users/kristenaiemjoy/Box Sync/_Teaching/Biostat 212/Biostat212.2018/Assignments/Assignment 5" capture log close //close any open log files clear quietly log using biostat212_assignment5_name.smcl, replace //open a log file /*** #Biostat 212: Assignment 5 ##Your name here _38 pts + 5 extra credit_ --- The goal of this assignment is to learn how to do basic epidemiological analyses and create nice looking tables in Stata. We’ll analyze the NHANES dataset you used in Assignments 1, 2, 3 & 4. Turn in the DocX you create with MarkDoc. Remember to include the tables you create from the _tabout_ and _outreg2_ packages __We will focus on one research question for this assignment: "Do people living in rural areas of the US have a higher probability of having a heart attack compared to people living in non-rural areas?"__ _Remember to include both the command(s) and your answer for each question._ _Round to 2 decimal points_ _Report p-values of 0.0000 as <0.001_ --- ***/ /*** Load the nhanes2 data set from the web [+1] ***/ /*** Set the scheme for this assignment to make nicer looking graphs *your choice* [+1] ***/ /*** --- ##Part 1 Label the variables and values of "heartatk", "rural", and "race" [+6] ***/ /*** ##Part 2 [+4] Create a 2x2 table of the exposure ("rural") and the outcome ("heartatk") using the tabulate command. Include options so you can see what percent of people head a heart attack in each exposure group (add the col or row option, depending on how you set it up), and the chi2 test. __What percent of people in rural areas had a heart attack?__ _Answer: _ __What percent of people in non-rural areas had a heart attack?__ _Answer: _ __What is the p-value from the chi-squared test?__ _Answer: _ ***/ /*** ##Part 3 [+2] Visualize the difference in mean heart attack between rural and non-rural areas using a bar chart. Remember that because 'heartatk' is coded as 0 and 1, the mean will be the proportion who had a heart attack. Include the bar chart in your MarkDoc. ***/ /*** ##Part 4 [+5] Use the table1 command to create a summary cable of rural (categorical), race (categerical) and age (continuous) by heartatk. Save your table as a .xls and copy & paste into your final MarkDoc document before you turn in. ***/ /*** __Remember to copy and paste your table from excel .xls into the final MarkDoc .docx__ ***/ /*** ##Part 5 [+3] Let's use the _cs_ command to get a measure of association comparing heart attack between people living in rural and non-rural areas. _cs_ stands for cohort study. _cs outcomevar predictorvar_ __What is the risk ratio and 95% CIs for the risk of heart attack associated with living in a rural area?__ _Answer: _ __What is the p-value from the chi-squared test?__ _Answer: _ ***/ /*** ##Part 6 [+3] Let's calculate odds ratios instead of risk ratios. We can get odds ratios from the _cs_ command using the [, or] option: _cs outcomevar predictorvar, or_ alternatively, use the _cc_ command: _cc outcomevar predictorvar_ Try both. __What is the odds ratio?__ _Answer: _ ***/ /*** ##Part 7 [+3] We can also get the odds ratio using a logistic regression. Try: _logit outcomevar predictorvar, or_ __What is the odds ratio for the rural coefficient?__ _Answer: _ __What is the p-value for the rural coefficient?__ _Answer: _ ***/ /*** ##Part 8 [+4] Age could be a confounding variable for the relationship between "rural" and "heartatk" if it is independently associated with living in a rural area and with having a heart attack. Visualize an association between "age" and "rural" and "age" and "heartatk" using two box plots. Include both plots in your MarkDoc document with the _img_ command. ***/ /*** ##Part 9 [+3] Age is associated with both living in rural areas and with having a heart attack. Let's try adjusting for it using multivariate logistic regression _logit outcomevar predictorvar confoundingvar, or_ __What is the odds ratio for rural adjusted for age?__ _Answer: _ __What is the p-value for the rural coefficient?__ _Answer: _ ***/ /*** ##Part 10 [+3] Let's export our regression output into a nicely formatted table using the _outreg2_ command. This is an additional package that you need to install. If you use MyResearch, it will already be installed on the server. Otherwise, run the following command: ssc install outreg2 Run the following _outreg2_ command after your logistic regression. It will save the results in a .rtf and and .xml called "rural" in whatever working directory you are in. Open the .rtf document in word and copy & paste the table into your final MarkDoc before turning it in. ***/ outreg2 using rural, ci bdec(3) eform ctitle("Odds ratio (95% CI)") nocons /// word excel replace nonotes addnote("*** p<0.01, ** p<0.05, * p<0.1", /// "Data source: NHANES2") /*** __Remember to copy and paste your outreg table into the final MarkDoc__ ***/ /*** ##Extra credit [+5] Export the same regression table as a .tex file using the "pretty" option. See the help file for _outreg2_ for details. Open the .tex using your text editor. Copy & paste the .tex file contents to overleaf.com or open it with another LaTeX editer. Save as a pdf and turn it in with your assignment. ***/ qui log close //close log (quietly so it won't appear in markdown document /*The following command creates a word document from your log file. Make sure the name of the file after the word markdown matches the name of your log file*/ markdoc biostat212_assignment5_name, replace statax export(docx)