************************************ ************************************ ***HYPOTHESIS TESTING IV: CHI SQUARE (chapter 11) ************************************ ************************************ ************************************ ***OPENING COMMANDS ************************************ ***Clear memory clear all ***Start saving results window log using "C:\course\progs\Stata11.log", replace text // Windows log using "/course/progs/Stata11.log", replace text // Macintosh ***Open 2016 GSS use "C:\course\data\GSS2016.dta", clear // Windows use "/course/data/GSS2016.dta", clear // Macintosh ************************************ ***Complex survey design ************************************ svyset [weight=wtssall], 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 ***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 ************************************ ************************************ ***Opinion about immigration by sex *Use chi square from these tables tab letin1 sex, chi col tab letin1 sex, chi col nofreq *Use column percentages from this table svy: tab letin1 sex, col ************************************ ***Opinion about immigration by ethnicity *Use chi square from these tables tab letin1 hisp, chi col tab letin1 hisp, chi col nofreq *Use column percentages from this table svy: tab letin1 hisp, col ************************************ ***Opinion about immigration by race/ethnicity *Use chi square from these tables tab letin1 raceeth, chi col tab letin1 raceeth, chi col nofreq *Use column percentages from this table svy: tab letin1 raceeth, col ************************************ ***Opinion about immigration by political party *Use chi square from these tables tab letin1 democrat, chi col tab letin1 democrat, chi col nofreq *Use column percentages from this table svy: tab letin1 democrat, col ************************************ ***CLOSING COMMANDS ************************************ ***Save data save "Stata11.dta", replace ***Save log log close