************************************ ************************************ ***HYPOTHESIS TESTING I: THE ONE-SAMPLE CASE (chapter 8) ***HYPOTHESIS TESTING II: THE TWO-SAMPLE CASE (chapter 9) ************************************ ************************************ ************************************ ***OPENING COMMANDS ************************************ ***Clear memory clear all ***Start saving results window log using "C:\course\progs\Stata06.log", replace text // Windows log using "/course/progs/Stata06.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) ************************************ ***ONE-SAMPLE Z-TEST AND t-TEST ************************************ ***Personal income ***of sample of adult population (18+) ***compared to population 15+ (U.S. Census Bureau) ***https://fred.stlouisfed.org/series/MEPAINUSA672N ***Mean personal income svy: mean conrinc mean conrinc ***Z-test ztest conrinc=31099 ***t-test ttest conrinc=31099 ************************************ ***ONE-SAMPLE TEST OF PROPORTIONS ************************************ ***Gender composition ***of sample of adult population (18+) ***compared to overall population (U.S. Census Bureau) ***https://www.census.gov/quickfacts/fact/table/US/PST045216 ***Generate dummy variable for female tab sex tab sex, nolabel generate female=. replace female=0 if sex==1 replace female=1 if sex==2 tab sex female, m tab female ***Proportion test prtest female=.508 ************************************ ***TWO-SAMPLE t-TEST ************************************ ***Mean of personal income by sex table sex, c(mean conrinc) ***t-test of personal income by sex ttest conrinc, by(sex) ************************************ ***TWO-SAMPLE TEST OF PROPORTIONS ************************************ ***Number of immigrants to America nowadays should be tab letin1, m tab letin1, m nolabel ***Create dummy variable for pro-immigrants vs. anti-immigrants ***"remain the same as it is" will be missing gen proimmig=. replace proimmig=1 if letin1==1 | letin1==2 replace proimmig=0 if letin1==4 | letin1==5 tab letin1 proimmig, m tab proimmig ***Create 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 ***Proportion of pro-immigrants by political party table democrat, c(mean proimmig) ***Test of proportions of pro-immigrants by political party prtest proimmig, by(democrat) ************************************ ***CLOSING COMMANDS ************************************ ***Save log log close