*Thyne, Clayton *Intro to Stats, Chapter 10 examples clear set mem 80m *cd [your directory] * NOTE: the above command asks you to change the directory. The directory will depend on how you've set up * the folders on your computer. For example, my command is... * cd F:\teaching\Fall_2008\PS572-401-baby_stats\do_file_directories\chapter10 * This is necessary so you know where stata is saving things. ****Part 1: t test and one-way anova use http://www.uky.edu/~clthyn2/intro_stats/machines_example.dta drop if machine==3 ttest outputs, by(machine) oneway outputs machine, tab *Note the P value for the t test is identical to that for the anova ****Part 1b: you can also seperate them to make the analagous to previous do files gen var1=. replace var1=47 in 1 replace var1=53 in 2 replace var1=49 in 3 replace var1=50 in 4 replace var1=46 in 5 rename var1 machine1 gen var2=. replace var2=55 in 1 replace var2=54 in 2 replace var2=58 in 3 replace var2=61 in 4 replace var2=52 in 5 rename var2 machine2 ttest machine1=machine2, unpaired ****Part 2: examining summary stats for each group (school) clear use "http://www.uky.edu/~clthyn2/intro_stats/GPAs_example.dta" sort school by school:sum GPA ****Part 3: examining "explained" versus "unexplained" variance clear use "http://www.uky.edu/~clthyn2/intro_stats/GPAs_example.dta" *compare graph hbar (mean) GPA, over(school) *, which doesn't tell us much, so... graph hbox GPA, over(school) ****Part 4: using anova clear use "http://www.uky.edu/~clthyn2/intro_stats/GPAs_example.dta" oneway GPA school, tab ****Part 5: using anova with sample sizes of different N clear use "http://www.uky.edu/~clthyn2/intro_stats/GPAs_example.dta" *first, we add in 4 new observations for UK (IA and TN stay at 4) set obs 16 replace school = 2 in 13 replace school = 2 in 14 replace school = 2 in 15 replace school = 2 in 16 replace GPA=2.1 in 13 replace GPA=2.3 in 14 replace GPA=2.4 in 15 replace GPA=2.2 in 16 oneway GPA school, tab ****Part 6: using the Scheffe test clear use "http://www.uky.edu/~clthyn2/intro_stats/GPAs_example.dta" *recreate the same sample as before, then test... oneway GPA school, scheffe *So, we can see that IA/TN are significantly different. IA and UK are close, but not sig. *This seems pretty obvious by just looking at the means... sort school by school: sum(GPA) ****Part 7: two-way anova; also looking at interactions clear use "http://www.uky.edu/~clthyn2/intro_stats/GPAs_example.dta" gen race=. replace race = 1 in 1 replace race = 2 in 2 replace race = 3 in 3 replace race = 4 in 4 replace race = 1 in 5 replace race = 2 in 6 replace race = 3 in 7 replace race = 4 in 8 replace race = 1 in 9 replace race = 2 in 10 replace race = 3 in 11 replace race = 4 in 12 label define race 1 "white" 2 "black" 3 "hispanic" 4 "other" label values race race oneway GPA school, tab anova GPA school race anova GPA school race school*race *the interaction above says that races may be doing better/worse at different schools ****Part 8: anova and regression clear use "http://www.uky.edu/~clthyn2/intro_stats/GPAs_example.dta" gen race=. replace race = 1 in 1 replace race = 2 in 2 replace race = 3 in 3 replace race = 2 in 4 replace race = 2 in 5 replace race = 2 in 6 replace race = 2 in 7 replace race = 1 in 8 replace race = 1 in 9 replace race = 3 in 10 replace race = 2 in 11 replace race = 1 in 12 label define race 1 "white" 2 "black" 3 "hispanic" label values race race anova GPA school race school*race oneway GPA school gen UK=1 if school==2 replace UK=0 if UK==. gen IA=1 if school==1 replace IA=0 if IA==. regress GPA UK IA race *Note some of the same info from ANOVA to Regress, such as the total SS