{smcl} {com}{sf}{ul off}{txt}{.-} name: {res} {txt}log: {res}/Users/eric/Work/MB/ATCR/200/Labs/lab 3.smcl {txt}log type: {res}smcl {txt}opened on: {res}20 Sep 2018, 11:12:27 {txt} {com}. . use class.dta, clear {txt} {com}. . describe {txt}Contains data from {res}class.dta {txt} obs:{res} 104 {txt} vars:{res} 9 11 Jul 2018 05:44 {txt} size:{res} 2,600 {txt}{hline} storage display value variable name type format label variable label {hline} {p 0 48}{res}{bind:apple_any }{txt}{bind: byte }{bind:{txt}%10.0g }{space 1}{bind: }{bind: }{res}{res}any apple devices{p_end} {p 0 48}{bind:apple_n }{txt}{bind: byte }{bind:{txt}%10.0g }{space 1}{bind: }{bind: }{res}{res}# apples devices{p_end} {p 0 48}{bind:children_any }{txt}{bind: byte }{bind:{txt}%10.0g }{space 1}{bind: }{bind: }{res}{res}any children{p_end} {p 0 48}{bind:children_n }{txt}{bind: byte }{bind:{txt}%10.0g }{space 1}{bind: }{bind: }{res}{res}# children{p_end} {p 0 48}{bind:coffee_n }{txt}{bind: double }{bind:{txt}%10.0g }{space 1}{bind: }{bind: }{res}{res}# cups coffee/day{p_end} {p 0 48}{bind:duration }{txt}{bind: int }{bind:{txt}%10.0g }{space 1}{bind: }{bind: }{res}{res}seconds to complete survey{p_end} {p 0 48}{bind:female }{txt}{bind: byte }{bind:{txt}%9.0g }{space 1}{bind:yesno }{bind: }{res}{res}female sex{p_end} {p 0 48}{bind:height }{txt}{bind: double }{bind:{txt}%14.2f }{space 1}{bind: }{bind: }{res}{res}height (inches){p_end} {p 0 48}{bind:year }{txt}{bind: int }{bind:{txt}%9.0g }{space 1}{bind: }{bind: }{res}{res}{p_end} {txt}{hline} Sorted by: {com}. . /* 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 {txt}{hline} -> year = 2016 Variable {c |} Obs Mean Std. Dev. Min Max {hline 13}{c +}{hline 57} {space 3}apple_any {c |}{res} 55 .9454545 .2291839 0 1 {txt}{space 5}apple_n {c |}{res} 55 3.090909 1.404658 0 6 {txt}children_any {c |}{res} 55 .1454545 .355808 0 1 {txt}{space 2}children_n {c |}{res} 55 .1818182 .4749623 0 2 {txt}{space 4}coffee_n {c |}{res} 55 1.581818 1.911863 0 11 {txt}{hline 13}{c +}{hline 57} {space 4}duration {c |}{res} 55 104.7636 207.3497 21 1581 {txt}{space 6}female {c |}{res} 55 .5272727 .5038572 0 1 {txt}{space 6}height {c |}{res} 55 67.58364 4.502006 57 75 {txt}{space 8}year {c |}{res} 55 2016 0 2016 2016 {txt}{hline} -> year = 2017 Variable {c |} Obs Mean Std. Dev. Min Max {hline 13}{c +}{hline 57} {space 3}apple_any {c |}{res} 49 .877551 .3312007 0 1 {txt}{space 5}apple_n {c |}{res} 49 3.367347 3.521919 0 22 {txt}children_any {c |}{res} 49 .1836735 .3912304 0 1 {txt}{space 2}children_n {c |}{res} 49 .3061224 .6832545 0 2 {txt}{space 4}coffee_n {c |}{res} 49 1.653061 1.169063 0 5 {txt}{hline 13}{c +}{hline 57} {space 4}duration {c |}{res} 49 96.55102 97.3683 1 520 {txt}{space 6}female {c |}{res} 49 .6530612 .4809288 0 1 {txt}{space 6}height {c |}{res} 48 75.54167 64.149 60 510 {txt}{space 8}year {c |}{res} 49 2017 0 2017 2017 {txt} {com}. . /* 2. Were there more females in 2016 or 2017? Should we use counts or > percentages to answer this question? */ . . tab year female, row {txt} {c TLC}{hline 16}{c TRC} {c |} Key{col 18}{c |} {c LT}{hline 16}{c RT} {c |}{space 3}{it:frequency}{col 18}{c |} {c |}{space 1}{it:row percentage}{col 18}{c |} {c BLC}{hline 16}{c BRC} {c |} female sex year {c |} no yes {c |} Total {hline 11}{c +}{hline 22}{c +}{hline 10} 2016 {c |}{res} 26 29 {txt}{c |}{res} 55 {txt}{c |}{res} 47.27 52.73 {txt}{c |}{res} 100.00 {txt}{hline 11}{c +}{hline 22}{c +}{hline 10} 2017 {c |}{res} 17 32 {txt}{c |}{res} 49 {txt}{c |}{res} 34.69 65.31 {txt}{c |}{res} 100.00 {txt}{hline 11}{c +}{hline 22}{c +}{hline 10} Total {c |}{res} 43 61 {txt}{c |}{res} 104 {txt}{c |}{res} 41.35 58.65 {txt}{c |}{res} 100.00 {txt} {com}. . /* 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 {c -(} {txt} 2{com}. qui sum female if year==`year' {txt} 3{com}. local pbf = round(binomialtail(`r(N)',`r(sum)',.5),.01) {txt} 4{com}. di as result "Probability of at least `r(sum)'/`r(N)' (`=round(`r(mean)'*100,.01)'%) women in `year' class: `pbf'" {txt} 5{com}. {c )-} {res}Probability of at least 29/55 (52.73%) women in 2016 class: .39 Probability of at least 32/49 (65.31%) women in 2017 class: .02 {txt} {com}. . /* 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 {txt} {com}. foreach x of varlist *_n duration height {c -(} {txt} 2{com}. graph box `x', over(year) name(box_`x', replace) {txt} 3{com}. {c )-} {res}{txt} {com}. set graphics on {txt} {com}. graph combine box_apple_n box_children_n box_coffee_n box_duration box_height, /// > name(boxplots_combined, replace) {res}{txt} {com}. . /* 5. What is the probability of having no children in 2016? In 2017? */ . tab year children_any, row {txt} {c TLC}{hline 16}{c TRC} {c |} Key{col 18}{c |} {c LT}{hline 16}{c RT} {c |}{space 3}{it:frequency}{col 18}{c |} {c |}{space 1}{it:row percentage}{col 18}{c |} {c BLC}{hline 16}{c BRC} {c |} any children year {c |} 0 1 {c |} Total {hline 11}{c +}{hline 22}{c +}{hline 10} 2016 {c |}{res} 47 8 {txt}{c |}{res} 55 {txt}{c |}{res} 85.45 14.55 {txt}{c |}{res} 100.00 {txt}{hline 11}{c +}{hline 22}{c +}{hline 10} 2017 {c |}{res} 40 9 {txt}{c |}{res} 49 {txt}{c |}{res} 81.63 18.37 {txt}{c |}{res} 100.00 {txt}{hline 11}{c +}{hline 22}{c +}{hline 10} Total {c |}{res} 87 17 {txt}{c |}{res} 104 {txt}{c |}{res} 83.65 16.35 {txt}{c |}{res} 100.00 {txt} {com}. . /* 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 {txt}{hline} -> year = 2016 # cups coffee/day {hline 61} Percentiles Smallest 1% {res} 0 0 {txt} 5% {res} 0 0 {txt}10% {res} 0 0 {txt}Obs {res} 55 {txt}25% {res} 0 0 {txt}Sum of Wgt. {res} 55 {txt}50% {res} 1 {txt}Mean {res} 1.581818 {txt}Largest Std. Dev. {res} 1.911863 {txt}75% {res} 3 4 {txt}90% {res} 3 4 {txt}Variance {res} 3.655219 {txt}95% {res} 4 6 {txt}Skewness {res} 2.44075 {txt}99% {res} 11 11 {txt}Kurtosis {res} 12.01207 {txt}{hline} -> year = 2017 # cups coffee/day {hline 61} Percentiles Smallest 1% {res} 0 0 {txt} 5% {res} 0 0 {txt}10% {res} 0 0 {txt}Obs {res} 49 {txt}25% {res} 1 0 {txt}Sum of Wgt. {res} 49 {txt}50% {res} 2 {txt}Mean {res} 1.653061 {txt}Largest Std. Dev. {res} 1.169063 {txt}75% {res} 2 3 {txt}90% {res} 3 4 {txt}Variance {res} 1.366709 {txt}95% {res} 4 4 {txt}Skewness {res} .4653882 {txt}99% {res} 5 5 {txt}Kurtosis {res} 3.14316 {txt} {com}. graph box coffee_n, over(year) name(box_cn, replace) {res}{txt} {com}. . /* 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) {res} {txt}Mean estimation{col 35}Number of obs{col 51}= {res} 104 {txt}2016: year = {res}2016 {txt}2017: year = {res}2017 {txt}{hline 13}{c TT}{hline 11}{hline 11}{hline 14}{hline 12} {col 1} Over{col 14}{c |} Mean{col 26} Std. Err.{col 38} [95% Con{col 51}f. Interval] {hline 13}{c +}{hline 11}{hline 11}{hline 14}{hline 12} {res}duration {txt}{c |} {space 8}2016 {c |}{col 14}{res}{space 2} 104.76{col 26}{space 2} 27.96{col 37}{space 5} 49.31{col 51}{space 3} 160.21 {txt}{space 8}2017 {c |}{col 14}{res}{space 2} 96.55{col 26}{space 2} 13.91{col 37}{space 5} 68.96{col 51}{space 3} 124.14 {txt}{hline 13}{c BT}{hline 11}{hline 11}{hline 14}{hline 12} {com}. mean duration, over(year) cformat(%8.2f) level(90) {res} {txt}Mean estimation{col 35}Number of obs{col 51}= {res} 104 {txt}2016: year = {res}2016 {txt}2017: year = {res}2017 {txt}{hline 13}{c TT}{hline 11}{hline 11}{hline 14}{hline 12} {col 1} Over{col 14}{c |} Mean{col 26} Std. Err.{col 38} [90% Con{col 51}f. Interval] {hline 13}{c +}{hline 11}{hline 11}{hline 14}{hline 12} {res}duration {txt}{c |} {space 8}2016 {c |}{col 14}{res}{space 2} 104.76{col 26}{space 2} 27.96{col 37}{space 5} 58.36{col 51}{space 3} 151.17 {txt}{space 8}2017 {c |}{col 14}{res}{space 2} 96.55{col 26}{space 2} 13.91{col 37}{space 5} 73.46{col 51}{space 3} 119.64 {txt}{hline 13}{c BT}{hline 11}{hline 11}{hline 14}{hline 12} {com}. graph box duration, over(year) name(box_dur) {res}{txt} {com}. * remove some big values . preserve {txt} {com}. replace duration = . if duration>250 {txt}(4 real changes made, 4 to missing) {com}. mean duration, over(year) cformat(%8.2f) {res} {txt}Mean estimation{col 35}Number of obs{col 51}= {res} 100 {txt}2016: year = {res}2016 {txt}2017: year = {res}2017 {txt}{hline 13}{c TT}{hline 11}{hline 11}{hline 14}{hline 12} {col 1} Over{col 14}{c |} Mean{col 26} Std. Err.{col 38} [95% Con{col 51}f. Interval] {hline 13}{c +}{hline 11}{hline 11}{hline 14}{hline 12} {res}duration {txt}{c |} {space 8}2016 {c |}{col 14}{res}{space 2} 77.43{col 26}{space 2} 5.97{col 37}{space 5} 65.58{col 51}{space 3} 89.27 {txt}{space 8}2017 {c |}{col 14}{res}{space 2} 75.24{col 26}{space 2} 6.54{col 37}{space 5} 62.26{col 51}{space 3} 88.22 {txt}{hline 13}{c BT}{hline 11}{hline 11}{hline 14}{hline 12} {com}. restore {txt} {com}. . /* 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 {c -(} {txt} 2{com}. histogram coffee_n if year==`year', bin(10) name(cn_`year', replace) {txt} 3{com}. {c )-} {txt}(bin={res}10{txt}, start={res}0{txt}, width={res}1.1{txt}) {res}{txt}(bin={res}10{txt}, start={res}0{txt}, width={res}.5{txt}) {res}{txt} {com}. . log close {txt}name: {res} {txt}log: {res}/Users/eric/Work/MB/ATCR/200/Labs/lab 3.smcl {txt}log type: {res}smcl {txt}closed on: {res}20 Sep 2018, 11:12:35 {txt}{.-} {smcl} {txt}{sf}{ul off}