**************************************************** **************************************************** * These commands tell STATA how to interpret things * 1. cd tells STATA what computer directory you are working in * 2. "set more off" tells STATA's results screen to scroll nicely * 3. the log commands tell the computer to save an output file with results **************************************************** **************************************************** cd [PATH ON YOUR COMPUTER] * For example: * cd I:\ set more off log using "sample-log.log", replace log on **************************************************** **************************************************** * These commands read the raw data into STATA **************************************************** **************************************************** infix age 1-2 educ 3-4 health 5-6 partyid 7-8 sex 9-10 using "sample_data.dat" **************************************************** **************************************************** * These commands labels the variables **************************************************** **************************************************** label variable age "Person's Age (in Years)" label variable educ "Person's Years of School Completed" label variable health "Person's Self-Rated Health" label variable partyid "Person's Party Affiliation" label variable sex "Person's Sex" **************************************************** **************************************************** * These commands label each variable's values **************************************************** **************************************************** label define lab_health 1 "Excellent" 2 "Good" 3 "Fair" 4 "Poor" label values health lab_health label define lab_partyid 0 "Strong Democrat" 1 "Not Strong Democrat" 2 "Independent, Near Democrat" 3 "Independent" 4 "Independent, Near Republican" 5 "Not Strong Republican" 6 "Strong Republican" 7 "Other Party" label values partyid lab_partyid label define lab_sex 1 "Male" 2 "Female" label values sex lab_sex **************************************************** **************************************************** * These commands decalre some values to represent missing data **************************************************** **************************************************** replace age=. if age==-9 replace educ=. if educ==-9 replace health=. if health==-9 replace partyid=. if partyid==-9 replace sex=. if sex==-9 ****************************************************************************************************************** ****************************************************************************************************************** * These commands produce frequency distributions for the entire sample ****************************************************************************************************************** ****************************************************************************************************************** tab age tab educ tab health tab partyid tab sex ****************************************************************************************************************** ****************************************************************************************************************** * These commands produce frequency distributions separately for Democrats, Independents, and Republicans ****************************************************************************************************************** ****************************************************************************************************************** * For Democrats tab age if partyid>=0 & partyid<=1 tab educ if partyid>=0 & partyid<=1 tab health if partyid>=0 & partyid<=1 tab sex if partyid>=0 & partyid<=1 * For Independents tab age if partyid>=2 & partyid<=4 tab educ if partyid>=2 & partyid<=4 tab health if partyid>=2 & partyid<=4 tab sex if partyid>=2 & partyid<=4 * For Republicans tab age if partyid>=5 & partyid<=6 tab educ if partyid>=5 & partyid<=6 tab health if partyid>=5 & partyid<=6 tab sex if partyid>=5 & partyid<=6 ****************************************************************************************************************** ****************************************************************************************************************** * These commands produce histograms for the entire sample for continuous variables ****************************************************************************************************************** ****************************************************************************************************************** hist age graph export "age_graph.png", as(png) replace hist educ graph export "educ_graph.png", as(png) replace ****************************************************************************************************************** ****************************************************************************************************************** * These commands produce measures of central tendency and spread for the entire sample for continuous variables ****************************************************************************************************************** ****************************************************************************************************************** tabstat age, stat(mean sd min p25 median p75 max n) tabstat educ, stat(mean sd min p25 median p75 max n) ****************************************************************************************************************** ****************************************************************************************************************** * These commands produce measures of central tendency and spread for continuous variables separately by sex ****************************************************************************************************************** ****************************************************************************************************************** *For Men tabstat age if sex==1, stat(mean sd min p25 median p75 max n) tabstat educ if sex==1, stat(mean sd min p25 median p75 max n) *For Women tabstat age if sex==2, stat(mean sd min p25 median p75 max n) tabstat educ if sex==2, stat(mean sd min p25 median p75 max n) log off log close