************************************ ************************************ ***SOCI 420: ADVANCED METHODS OF SOCIAL RESEARCH ***HYPOTHESIS TESTING III: THE ANALYSIS OF VARIANCE (chapter 10) ************************************ ************************************ ************************************ ***CLEAR MEMORY ************************************ clear all ************************************ ***CREATE SHORTCUTS AND LOG FILE ************************************ ***Shortcut for folders global codes = "H:\course\codes" global data = "H:\course\data" global output = "H:\course\output" ***Start saving results window log using "$codes\Stata10.log", replace text ************************************ ***OPENING COMMANDS ************************************ ***Tell Stata to not pause for "more" messages set more off ***Open 2021 GSS use "$data\GSS2021.dta", clear ***Complex survey design svyset [weight=wtssnrps], strata(vstrat) psu(vpsu) singleunit(scaled) ************************************ ***GENERATING VARIABLES ************************************ ***Generate dummy variable for hispanic tab hispanic, m tab hispanic, m nolabel gen hisp=. replace hisp=0 if hispanic==1 replace hisp=1 if hispanic>=2 & hispanic<=50 tab hispanic hisp, m ***Generate race/ethnicity variable tab race, m tab race, m nolabel gen raceeth=. replace raceeth=1 if race==1 & hisp==0 //non-hispanic white replace raceeth=2 if race==2 & hisp==0 //non-hispanic black replace raceeth=3 if hisp==1 //hispanic replace raceeth=4 if race==3 & hisp==0 //other label variable raceeth "Race/Ethnicity" label define race 1 "White" 2 "Black" 3 "Hispanic" 4 "Other" label values raceeth race tab raceeth race, m tab raceeth hisp, m ************************************ ***ANOVA - Income by race/ethnicity ************************************ ***Descriptive table ***"tabstat" command by race/ethnicity does not accept complex survey design tabstat conrinc if conrinc!=0 & conrinc!=.i [aweight=wtssnrps], by(raceeth) stat(mean sd n) ***"mean" command by race/ethnicity accepts complex survey design (correct estimation of standard deviation) svy, subpop(if conrinc!=0 & conrinc!=.i): mean conrinc, over(raceeth) estat sd ***"mean" command for overall sample accepts complex survey design (correct estimation of standard deviation) svy, subpop(if conrinc!=0 & conrinc!=.i & raceeth!=.): mean conrinc estat sd ***Sample distribution by race/ethnicity and missing cases (no weights) tab raceeth if conrinc!=0 & conrinc!=.i, m ***Sample distribution by race/ethnicity (with weight) tab raceeth if conrinc!=0 & conrinc!=.i [aweight=wtssnrps] ***One-way ANOVA does not accept complex survey design oneway conrinc raceeth if conrinc!=0 & conrinc!=.i [aweight=wtssnrps] anova conrinc raceeth if conrinc!=0 & conrinc!=.i [aweight=wtssnrps] ************************************ ***CLOSING COMMANDS ************************************ ***Save data save "$data\Stata10.dta", replace ***Save log log close