* Biostat 200 Lab 3 cd "~/work/mb/atcr/200/labs" capture log close log using "lab 3", replace use class.dta, clear describe /* 1. Summarize the variables, by year. Which variables are categorical and which are continuous? Can we tell whether categorical variables are ordinal from the descriptive statistics? */ bysort year: sum /* 2. Were there more females in 2016 or 2017? Should we use counts or percentages to answer this question? */ tab year female, row /* 3. Assuming that there should be an even split of 50% males & 50% females, calculate the probability of seeing the number of females in each of the 2 years using the binomial distribution. */ forvalues year = 2016/2017 { qui sum female if year==`year' local pbf = round(binomialtail(`r(N)',`r(sum)',.5),.01) di as result "Probability of at least `r(sum)'/`r(N)' (`=round(`r(mean)'*100,.01)'%) women in `year' class: `pbf'" } /* 4. Look at boxplots of the continuous variables. Are there any outliers? What error could account for the maximum value of height? */ set graphics off foreach x of varlist *_n duration height { graph box `x', over(year) name(box_`x', replace) } set graphics on graph combine box_apple_n box_children_n box_coffee_n box_duration box_height, /// name(boxplots_combined, replace) /* 5. What is the probability of having no children in 2016? In 2017? */ tab year children_any, row /* 6. What is the mean number of cups of coffee/day for each year? Is the mean estimator here? What might make more sense? How would you describe the distribution of this variable? */ bysort year: sum coffee_n, detail graph box coffee_n, over(year) name(box_cn, replace) /* 7. Calculate 95% confidence intervals for the mean duration (in seconds) that it took to complete the survey, by year. Which year appeared to take longer? Do the confidence bounds overlap for the 2 years? Calculate 90% confidence bounds. Do these confidence intervals overlap? Also examine boxplots of these data, again stratified by year. Are there outliers? Which group of students took longer? If you remove any outliers do the results look different? Are the confidence intervals similar? */ mean duration, over(year) cformat(%8.2f) mean duration, over(year) cformat(%8.2f) level(90) graph box duration, over(year) name(box_dur) * remove some big values preserve replace duration = . if duration>250 mean duration, over(year) cformat(%8.2f) restore /* 8. Create histograms of cups of coffee yesterday for each year, describe the distribution of the data. What would you expect to see if you took 40 samples of size 20 from the data for each year. Why? */ forvalues year = 2016/2017 { histogram coffee_n if year==`year', bin(10) name(cn_`year', replace) } log close