******************************************************************************* * Assignment 4 * BE SURE TO TYPE ALL COMMANDS YOU USE IN THIS DO FILE FOR FULL * CREDIT. * Write the answers to the questions in the commented-out space as indicated * Submit your do-file and word document (no log file needed) that includes * your final tables on the CLE by 1 pm on 9/8/20 * There are a total of 25 points in this assignment * _Your Name_ ******************************************************************************* /* Set your working directory and load the data */ version 16.1 clear capture log close *Set your working directory here: cd "Your/working/directory" *Open a new log here: log using "assignment4_log", replace *Load the nhanes2 dataset: webuse nhanes2 /* 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?" We will practice making nice-looking tables in Stata and Word. Remember to include both the command(s) and your answer for each question. */ /* Question 1 (3 pts) Label the values of "heartatk", "rural" according to their variable labels, and relabel the variables to a simple description (i.e., "Heart attack" and "Rural", or similar) Hint: check tab or codebook to see how the variables are labeled */ label define heartatk_label 0 "No heart attack" 1 "Heart attack" label values heartatk heartatk_label label define rural_label 0 "Urban" 1 "Rural" label values rural rural_label label variable heartatk "Heart attack" label variable rural "Rural" /* Question 2 (3 pts) 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) __What percent of people in rural areas had a heart attack?__ _Answer: 5.29% __What percent of people in urban areas had a heart attack?__ _Answer: 4.20% */ *Put your command here: tab rural heartatk, row // or tab heartatk rural, col /* Question 3 (7 pts) Create a summary table of the mean values of the following variables for each category of the rural variable: age, bmi, systolic blood pressure, diastolic blood pressure, and heart attack. Have the variables in rows and the statistics in columns as shown in class. Use putdocx to have STATA export the table directly into Word. Make sure the rows and columns are labeled. */ *Put your commands here: tabstat age bmi bpsystol bpdiast heartatk, /// by(rural) stat(mean) nototal save // also fine to include "total" return list // not required for full credit matrix combined_res = r(Stat1)', r(Stat2)' // can do this in separate steps; combining matrix with \ instead of , also fine putdocx clear putdocx begin putdocx table combined_2 = matrix(combined_res), rownames colnames layout(autofitcontents) nformat(%9.2f) title("Summary statistics") // rownames & colnames required for full credit; layout, nformat, & title are not required putdocx save "Last_name_assignment4.docx", replace // also fine to use collapse: collapse (mean) meanage=age meanbmi=bmi meanbpsystol=bpsystol meanbpdiast=bpdiast meanheartatk=heartatk, by(rural) putdocx clear putdocx begin putdocx table summarytable = data(*), title("Summary statistics") varnames putdocx save "Output/Last_name_assignment4.docx" /* Question 4 (11 pts) Create a regression output table with 3 models: 1) Outcome: heartatk; Predictors: rural 2) Outcome: heartatk; Predictors: rural, age 3) Outcome: heartatk; Predictors: rural, age, bmi Use estimates table. Export the table directly to your Word document using putdocx. Don't forget to make sure all the variables are labeled properly. HINT: use 'logistic' instead of 'regress' for your regressions. See extra slides for details. */ *Put your commands here: logistic heartatk rural estimates store model1 logistic heartatk rural age estimates store model2 logistic heartatk rural age bmi estimates store model3 estimates table model1 model2 model3, b(%10.2f) star stats(N) varlabel allbaselevels estimates table model1 model2 model3 // a more basic table is fine for full credit putdocx begin putdocx table regoutput = etable putdocx save "Last_name_assignment4.docx", append /* Wrapping up and turning in the assignment (1 pt) */ *Turn in 2 files on the CLE: your do-file and your Word document *Close log here: log close