**Setup cd "/Users/kristenaiemjoy/Box Sync/_Teaching/Biostat 212/Biostat212.2018/Assignments/Assignment 2" //modify filepath to your directory capture log close //close any open log files quietly log using biostat212_assignment2_name.smcl, replace //using "quietly" will stop print out in your smcl file making a nicer looking .pdf when you use markdown /*** #Biostat 212: 2018 #Assignment 2: Data cleaning ## Your Name --- #Instructions In this assignment we will be cleaning a subset of the NHANES data set "nhanes_raw.csv" We will import the data from a .csv file and export a clean data set. * Download "nhanes_raw.csv" and "nhanes_vegan.dta" from the course website and save in your working directory * Fill in the answer and include the command in the space below the question * Turn in the PDF, docX or html you generate from this .do file using MarkDoc * Round numeric answers to 2 decimal points ###43 points total --- ***/ /*** ###1. Import the "nhanes_raw.csv" file from the course website ***/ /*** ###2. How many observations are there? __Answer=XX__ ***/ /*** ###3. How many variables are there? __Answer=XX__ ***/ /*** #DUPLICATES ###4. List and drop duplicate observations ***/ /*** #REFORMAT VARIABLES ###5. What format is age? (string(character), numerical, categorical) __Answer=XX__ hint: try the describe command ***/ /*** ###6. Replace the value of age that is currently "sixty one" with 61. hint: try [replace varname = "value", if varname == "value"] (you will need to use the person's id) ***/ /*** ###7. Transform age into a numeric variable. hint: "help destring" ***/ /*** ###8. What is the mean age? __Answer=XX__ ***/ /*** #REMOVE OUTLIERS ###9. Use the spikeplot command to visualize outliers for age remember to use "img" after the command to include the plot in your markdoc ***/ /*** ###10. What is the highest age in this dataset? __Answer=XX__ ***/ /*** ###11. Replace any values of age greater than 100 as missing ("."). ***/ /*** ###12. Now what is the mean age? __Answer=XX__ ***/ /*** #MISSING DATA ###13. Use the mvdecode command to change -99 values to missing age, height and weight all have "-99" values ***/ /*** ###14. Now what is the mean age? __Answer=XX__ ***/ /*** #LABELS ###15. Create value labels for the variable sex. 0=female 1=male ***/ /*** ###16. How many males in this sample? __Answer=XX__ ***/ /*** #GENERATING NEW VARIABLES ###17. Generate a categorical variable for race hint: "help encode" ***/ /*** ####18. What percentage of the population is "other"? __Answer=XX__ ***/ /*** ###19. Create variable for bmi, from weight and height hint: bmi = weight/((height/100)^2) ***/ /*** ###20. What is the mean bmi? __Answer=XX__ ***/ /*** ###21. Create a categorical variable for hypertension from systolic blood pressure (sbp) (0/119=no hypertension & 120/max=1) hint: "help recode" ***/ /*** ###22. How many people have hypertension? __Answer=XX__ ***/ /*** ###23. Create a new variable that is quintiles of hdl. hint: "help xtile" ***/ /*** ###24. How many people are in the second quintile? __Answer=XX__ ***/ /*** #DATES ###25. Reformat "dob" as a date format ***/ /*** #MERGE You sent out a nutritional survey to study participants and want to merge it with this data set. ###26. Merge this data set with "nhanes_vegan.dta" on the course website hint: merge 1:1 idvariable using "dataset name", update replace ***/ /*** ###27. What percent of study participants are vegan? __Answer=XX__ ***/ /*** ###28. What is the mean BMI among participants who are vegan and those who are not vegan? __Answer=XX__ ***/ /*** #SAVE CLEAN DATA ###29. Save the clean data set as nhanes_clean.dta ***/ qui log close //close log (quietly so it wont appear in markdown document *Generate MarkDoc markdoc biostat212_assignment2_name, replace statax export(html) markdoc biostat212_assignment2_name, replace statax export(docx)