**Setup cd "/Users/..." //modify filepath to your directory capture log close //close any open log files set linesize 120 // for formatting the Markdown document clear quietly log using biostat212_assignment5_name.smcl, replace //open a log file /*** #Biostat 212: Assignment 5 ##Your name here _50 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 ***/ webuse nhanes2, clear /*** Temporarily set the scheme for this assignment to make nicer looking graphs ***/ set scheme s1mono /*** --- ##Part 1 Label the variables and values of "heartatk", "rural", and "race" ***/ /*** ##Part 2 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 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 Use the following _tabout_ command to create a summary table of "heartatk" "race" and "rural." open the .csv file it creates in your working directory and copy & paste into your final document before you turn in. You will need to install the tabout package first if you haven't done so already. If you use MyResearch, tabout is already installed on the server. If not, run the following command: ssc install tabout There is a newer version of tabout out that allows you to export directly to excel or docX with formatting, but it is currently in beta. If you are feeling adventurous, you can download from here: http://tabout.net.au/docs/home.php PS You can also create nice looking summary tables in the _outreg2_ package we will use in Part 10. Check out _help outreg2_ for more info. ***/ tabout heartatk race rural using tabl1.csv /// , replace style(csv) c(freq col) /*** __Remember to copy and paste your tabout .csv into the final MarkDoc__ ***/ /*** ##Part 5 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 Now, manually calculate the risk ratio using the _di_ command (divide the percent with heart attack in rural areas by the percent with heart attack in non-rural areas. __What is the risk ratio using the _di_ command?__ _Answer: _ Try the csi immediate command using the cell frequencies you calculated in Part 2. _csi stands for “cohort study, immediate”._ csi #a #b #c #d a = heart attack, rural b = heart attack, not rural c = no heart attack, rural d = no heart attack, not rural __What is the risk ratio using the _csi_ command?__ _Answer: _ ***/ /*** ##Part 7 Let's calculate odds ratios instead of risk ratios. try the immediate command _cci_ (_case-control immediate_) cci #a #b #c #d a = heart attack, rural b = heart attack, not rural c = no heart attack, rural d = no heart attack, not rural __What is the odds ratio?__ _Answer: _ 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: _ 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?__ _Anser: _ ***/ /*** ##Part 8 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 It looks like 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 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 using the "pretty" option. See the help file for _outreg2_ for details. Open the .tex using your text editor (TextEdit on Mac). 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 export(docx) date