************************************ ************************************ ***SOCI 420: ADVANCED METHODS OF SOCIAL RESEARCH ***HYPOTHESIS TESTING IV: CHI SQUARE (chapter 11) ************************************ ************************************ ************************************ ***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\Stata11.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 Democrats vs. Republicans ***"Independents" will be missing tab partyid, m tab partyid, m nolabel gen democrat=. replace democrat=1 if partyid>=0 & partyid<=2 replace democrat=0 if partyid>=4 & partyid<=6 label variable democrat "Political party" label define party 1 "Democrats" 0 "Republicans" label values democrat party tab partyid democrat, m tab democrat ************************************ ***CHI SQUARE ************************************ ***It would be incorrect to use fweight, ***because you would get statistical significance ***by indicating to the test that you have ***more observations than what was actually collected ***Weights that preserve sample size (aweight, pweight) ***are not allowed in Stata to estimate chi square ***Thus, estimate chi square using the ***complex survey design command (svy) ************************************ ***Opinion about immigration by sex ***Use column percentages with weight tab letin1 sex [aweight=wtssnrps], col tab letin1 sex [aweight=wtssnrps], col nofreq // column percentage ***Observed frequencies (fo) tab letin1 sex // sample size ***Expected frequencies (fe) tab letin1 sex, exp nofreq ***Chi square option works only without weights tab letin1 sex, chi col tab letin1 sex, chi col nofreq ***Use the chi square estimated with complex survey design svy: tab letin1 sex, col // chi square test ***Use missing cases from this table tab letin1 sex, m // missing cases ************************************ ***Opinion about immigration by political party ***Use column percentages with weight tab letin1 democrat [aweight=wtssnrps], col tab letin1 democrat [aweight=wtssnrps], col nofreq // column percentage ***Observed frequencies (fo) tab letin1 democrat // sample size ***Expected frequencies (fe) tab letin1 democrat, exp nofreq ***Chi square option works only without weights tab letin1 democrat, chi col tab letin1 democrat, chi col nofreq ***Use the chi square estimated with complex survey design svy: tab letin1 democrat, col // chi square test ***Use missing cases from this table tab letin1 democrat, m // missing cases ************************************ ***CLOSING COMMANDS ************************************ ***Save data save "$data\Stata11.dta", replace ***Save log log close