library("Zelig")
## Loading required package: boot
## Loading required package: MASS
## Loading required package: sandwich
## ZELIG (Versions 4.2-1, built: 2013-09-12)
##
## +----------------------------------------------------------------+
## | Please refer to http://gking.harvard.edu/zelig for full |
## | documentation or help.zelig() for help with commands and |
## | models support by Zelig. |
## | |
## | Zelig project citations: |
## | Kosuke Imai, Gary King, and Olivia Lau. (2009). |
## | ``Zelig: Everyone's Statistical Software,'' |
## | http://gking.harvard.edu/zelig |
## | and |
## | Kosuke Imai, Gary King, and Olivia Lau. (2008). |
## | ``Toward A Common Framework for Statistical Analysis |
## | and Development,'' Journal of Computational and |
## | Graphical Statistics, Vol. 17, No. 4 (December) |
## | pp. 892-913. |
## | |
## | To cite individual Zelig models, please use the citation |
## | format printed with each model run and in the documentation. |
## +----------------------------------------------------------------+
##
##
##
## Attaching package: 'Zelig'
##
## The following object is masked from 'package:utils':
##
## cite
library("car")
##
## Attaching package: 'car'
##
## The following object is masked from 'package:boot':
##
## logit
library("DescTools")
##
## Attaching package: 'DescTools'
##
## The following object is masked from 'package:car':
##
## Recode
##
## The following object is masked from 'package:Zelig':
##
## Mode
library("memisc")
## Warning: package 'memisc' was built under R version 3.1.3
## Loading required package: lattice
##
## Attaching package: 'lattice'
##
## The following object is masked from 'package:boot':
##
## melanoma
##
##
## Attaching package: 'memisc'
##
## The following object is masked from 'package:DescTools':
##
## %nin%
##
## The following object is masked from 'package:car':
##
## recode
##
## The following object is masked from 'package:Zelig':
##
## description
##
## The following objects are masked from 'package:stats':
##
## contr.sum, contr.treatment, contrasts
##
## The following object is masked from 'package:base':
##
## as.array
library("stargazer")
##
## Please cite as:
##
## Hlavac, Marek (2014). stargazer: LaTeX code and ASCII text for well-formatted regression and summary statistics tables.
## R package version 5.1. http://CRAN.R-project.org/package=stargazer
library("dplyr")
## Warning: package 'dplyr' was built under R version 3.1.3
##
## Attaching package: 'dplyr'
##
## The following objects are masked from 'package:memisc':
##
## collect, query, rename
##
## The following objects are masked from 'package:Zelig':
##
## combine, summarize
##
## The following object is masked from 'package:MASS':
##
## select
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library("foreign")
options(digits=3)
nes1948.por <- UnZip("anes/NES1948.ZIP","NES1948.POR", package="memisc")
library(foreign)
nes1948 <- read.spss(nes1948.por, to.data.frame=TRUE)
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
library(dplyr)
vote.48 <- select(nes1948, V480018, V480029, V480030, V480045, V480046,
V480047, V480048, V480049, V480050)
vote.48x <- select(vote.48, "vote" = V480018,"occupation.hh" = V480029,"unionized.hh" = V480030,
"gender" = V480045,"race" = V480046,"age" = V480047,"education" =V480048,
"total.income" =V480049,"religious.pref"=V480050)
str(vote.48x)
## 'data.frame': 662 obs. of 9 variables:
## $ vote : Factor w/ 6 levels "VOTED - FOR TRUMAN",..: 1 2 1 2 1 2 2 1 2 1 ...
## $ occupation.hh : Factor w/ 11 levels "PROFESSIONAL, SEMI-PROFESSIONAL",..: 6 3 4 1 1 2 7 7 4 4 ...
## $ unionized.hh : Factor w/ 2 levels "YES","NO": 1 2 2 2 2 2 2 2 1 1 ...
## $ gender : Factor w/ 2 levels "MALE","FEMALE": 1 2 2 2 1 2 1 2 1 1 ...
## $ race : Factor w/ 3 levels "WHITE","NEGRO",..: 1 1 1 1 1 1 1 1 1 1 ...
## $ age : Factor w/ 6 levels "18-24","25-34",..: 3 3 2 3 2 3 4 5 2 2 ...
## $ education : Factor w/ 3 levels "GRADE SCHOOL",..: 1 2 2 3 3 2 1 1 2 2 ...
## $ total.income : Factor w/ 7 levels "UNDER $500","$500-$999",..: 4 7 5 7 5 7 5 2 5 6 ...
## $ religious.pref: Factor w/ 5 levels "PROTESTANT","CATHOLIC",..: 1 1 2 1 2 1 1 1 1 2 ...
## - attr(*, "variable.labels")= Named chr "NES VERSION NUMBER" "NES DATASET NUMBER" "ICPSR ARCHIVE NUMBER" "INTERVIEW NUMBER" ...
## ..- attr(*, "names")= chr "VVERSION" "VDSETNO" "V480001" "V480002" ...
vote.48x$vote3[vote.48x$vote == "VOTED - FOR TRUMAN"] = "Truman"
vote.48x$vote3[vote.48x$vote == "VOTED - FOR DEWEY"] = "Dewey"
vote.48x$vote3[vote.48x$vote == "VOTED - FOR WALLACE" |
vote.48x$vote == "VOTED - FOR OTHER"] = "Other"
vote.48x$occup4[vote.48x$occupation.hh == "PROFESSIONAL, SEMI-PROFESSIONAL"|
vote.48x$occupation.hh == "SELF-EMPLOYED, MANAGERIAL, SUPERVISORY"] = "Upper white collar"
vote.48x$occup4[vote.48x$occupation.hh == "OTHER WHITE-COLLAR (CLERICAL, SALES, ET"] = "Other white collar"
vote.48x$occup4[vote.48x$occupation.hh == "SKILLED AND SEMI-SKILLED" |
vote.48x$occupation.hh == "PROTECTIVE SERVICE" |
vote.48x$occupation.hh == "UNSKILLED, INCLUDING FARM AND SERVICE W" ] = "Blue collar"
vote.48x$occup4[vote.48x$occupation.hh == "FARM OPERATORS AND MANAGERS"] = "Farmer"
vote.48x$relig3[vote.48x$religious.pref == "PROTESTANT"] = "Protestant"
vote.48x$relig3[vote.48x$religious.pref == "CATHOLIC"] = "Catholic"
vote.48x$relig3[vote.48x$religious.pref == "JEWISH" |vote.48x$religious.pref == "OTHER" | vote.48x$religious.pref == "NONE"] = "Other,none"
vote.48x$race2[vote.48x$race == "WHITE"] = "White"
vote.48x$race2[vote.48x$race == "NEGRO"] = "Black"
library(stargazer)
raceoccupation <- vote.48x
raceoccupation$uwc[raceoccupation$occup4 == "Upper white collar"] = 1
raceoccupation$owc[raceoccupation$occup4 == "Other white collar"] = 1
raceoccupation$bc[raceoccupation$occup4 == "Blue collar"] = 1
raceoccupation$farmer[raceoccupation$occup4 == "Farmer"] = 1
raceoccupationdf <- raceoccupation%>%
group_by(vote3) %>%
summarise(UpperWhiteCollar = sum(uwc, na.rm = TRUE),
OtherWhiteCollar=sum(owc, na.rm = TRUE),
BlueCollar=sum(bc, na.rm = TRUE),
Farmer=sum(farmer, na.rm = TRUE))
data.frame()%>%
stargazer(raceoccupationdf, summary=FALSE, type = "text", rownames = F)
##
## ==========================================================
## vote3 UpperWhiteCollar OtherWhiteCollar BlueCollar Farmer
## ----------------------------------------------------------
## Dewey 67 31 36 14
## Other 2 0 4 3
## Truman 17 30 114 26
## 31 18 101 62
## ----------------------------------------------------------
OccupationVote <- vote.48x
OccupationVote$Truman[OccupationVote$vote3 == "Truman"] = 1
OccupationVote$Dewey[OccupationVote$vote3 == "Dewey"] = 1
OccupationVote$Other[OccupationVote$vote3 == "Other"] = 1
OccupationVotedf <- OccupationVote%>%
group_by(occup4) %>%
summarise(TrumanSum = sum(Truman, na.rm = TRUE),
DeweySum = sum(Dewey, na.rm = TRUE),
OtherSum = sum(Other, na.rm = TRUE))%>%
mutate(N= TrumanSum + DeweySum + OtherSum)%>%
mutate(Truman = (TrumanSum*100) / N)%>%
mutate(Dewey = (DeweySum*100) / N)%>%
mutate(Other = (OtherSum*100) / N)%>%
data.frame()%>%
select(occup4, Truman, Dewey, Other, N)
stargazer(OccupationVotedf, digits=1,summary=FALSE, type = "text", rownames = F)
##
## =========================================
## occup4 Truman Dewey Other N
## -----------------------------------------
## Blue collar 74.0 23.4 2.6 154
## Farmer 60.5 32.6 7.0 43
## Other white collar 49.2 50.8 0 61
## Upper white collar 19.8 77.9 2.3 86
## 43.1 51.7 5.2 58
## -----------------------------------------
raceVotedf <- OccupationVote%>%
group_by(race2) %>%
summarise(TrumanSum = sum(Truman, na.rm = TRUE),
DeweySum=sum(Dewey, na.rm = TRUE),
OtherSum=sum(Other, na.rm = TRUE))%>%
mutate(N= TrumanSum + DeweySum + OtherSum)%>%
mutate(Truman = (TrumanSum*100) / N)%>%
mutate(Dewey = (DeweySum*100) / N)%>%
mutate(Other = (OtherSum*100) / N)%>%
data.frame()%>%
select(race2, Truman, Dewey, Other, N)
stargazer(raceVotedf, summary=FALSE, digits=1, type = "text", rownames = F)
##
## ============================
## race2 Truman Dewey Other N
## ----------------------------
## Black 64.7 35.3 0 17
## White 51.3 45.5 3.2 376
## 88.9 11.1 0 9
## ----------------------------