Codes
#install.packages("readr")
#install.packages("dplyr")
library(readr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
VoterData <- read_csv("~/Tsukasa/NY/CUNY/Class/Spring 2019/Programming for Social Research/VoterData2017(1).csv")
## Parsed with column specification:
## cols(
## .default = col_double(),
## redovote2016_t_2017 = col_character(),
## job_title_t_2017 = col_character(),
## izip_2016 = col_character(),
## presvote16post_t_2016 = col_character(),
## second_chance_t_2016 = col_character(),
## race_other_2016 = col_character(),
## healthcov_t_2016 = col_character(),
## employ_t_2016 = col_character(),
## pid3_t_2016 = col_character(),
## religpew_t_2016 = col_character(),
## votemeth16_rnd_2016 = col_character(),
## presvote16post_rnd_2016 = col_character(),
## vote2016_cand2_rnd_2016 = col_character(),
## Clinton_Rubio_rnd_2016 = col_character(),
## Clinton_Cruz_rnd_2016 = col_character(),
## Sanders_Trump_rnd_2016 = col_character(),
## Sanders_Rubio_rnd_2016 = col_character(),
## second_chance_rnd_2016 = col_character(),
## obamaapp_rnd_2016 = col_character(),
## fav_grid_row_rnd_2016 = col_character()
## # ... with 121 more columns
## )
## See spec(...) for full column specifications.
## Warning: 13 parsing failures.
## row col expected actual file
## 1418 religpew_muslim_baseline 1/0/T/F/TRUE/FALSE 90 '~/Tsukasa/NY/CUNY/Class/Spring 2019/Programming for Social Research/VoterData2017(1).csv'
## 1531 child_age7_1_baseline 1/0/T/F/TRUE/FALSE 6 '~/Tsukasa/NY/CUNY/Class/Spring 2019/Programming for Social Research/VoterData2017(1).csv'
## 1531 child_age8_1_baseline 1/0/T/F/TRUE/FALSE 4 '~/Tsukasa/NY/CUNY/Class/Spring 2019/Programming for Social Research/VoterData2017(1).csv'
## 1531 child_age9_1_baseline 1/0/T/F/TRUE/FALSE 2 '~/Tsukasa/NY/CUNY/Class/Spring 2019/Programming for Social Research/VoterData2017(1).csv'
## 2947 religpew_muslim_baseline 1/0/T/F/TRUE/FALSE 2 '~/Tsukasa/NY/CUNY/Class/Spring 2019/Programming for Social Research/VoterData2017(1).csv'
## .... ........................ .................. ...... ..........................................................................................
## See problems(...) for more details.
NewVoterData <- VoterData%>%
select(presvote16post_2016,
post_ideo5_2012,
abortview3_2016,
region_baseline,
religpew_baseline)%>%
rename("Vote2016" = presvote16post_2016,
"Ideology" = post_ideo5_2012,
"Abortion" = abortview3_2016,
"Region" = region_baseline,
"Religion" = religpew_baseline)%>%
mutate(Vote2016=ifelse(Vote2016==1,"Hillary Clinton",
ifelse(Vote2016==2,"Donald Trump",
ifelse(Vote2016==3,"Gary Johnson",
ifelse(Vote2016==4,"Jill Stein",
ifelse(Vote2016==5, "Evan McMullin",
ifelse(Vote2016==6,"Other",
ifelse(Vote2016==7,"Did not vote for President",NA))))))),
Ideology=ifelse(Ideology==1,"Very liberal",
ifelse(Ideology==2,"Liberal",
ifelse(Ideology==3,"Moderate",
ifelse(Ideology==4,"Conservative",
ifelse(Ideology==5,"Very conservative",
ifelse(Ideology==6,"Not sure",NA)))))),
Abortion=ifelse(Abortion==1, "Legal in all cases",
ifelse(Abortion==2,"Legal in some cases and illegal in others",
ifelse(Abortion==3,"Illegal in all cases",
ifelse(Abortion==8,"Not sure",NA)))),
Region = ifelse(Region==1,"Northeast",
ifelse(Region==2,"Midwest",
ifelse(Region==3,"South",
ifelse(Region==4,"West",
ifelse(Region==9,"Not in U.S.",NA))))),
Religion = ifelse(Religion==1,"Protestant",
ifelse(Religion==2,"Roman Catholic",
ifelse(Religion==3,"Mormon",
ifelse(Religion==4,"Eastern or Greek Orthodox",
ifelse(Religion==5,"Jewish",
ifelse(Religion==6,"Muslim",
ifelse(Religion==7,"Buddhist",
ifelse(Religion==8,"Hindu",
ifelse(Religion==9,"Atheist",
ifelse(Religion==10,"Agnostic",
ifelse(Religion==11,"Nothing in Particular",
ifelse(Religion==12,"Something else",NA)))))))))))))
Summaries
table(NewVoterData$Ideology,NewVoterData$Vote2016)
##
## Did not vote for President Donald Trump Evan McMullin
## Conservative 5 1711 14
## Liberal 6 73 0
## Moderate 10 875 4
## Not sure 3 110 0
## Very conservative 7 691 6
## Very liberal 2 19 0
##
## Gary Johnson Hillary Clinton Jill Stein Other
## Conservative 68 178 7 59
## Liberal 7 1214 33 16
## Moderate 125 1503 43 64
## Not sure 10 129 2 6
## Very conservative 16 28 1 28
## Very liberal 5 493 26 9
prop.table(table(NewVoterData$Ideology,NewVoterData$Vote2016),2)%>%round(3)
##
## Did not vote for President Donald Trump Evan McMullin
## Conservative 0.152 0.492 0.583
## Liberal 0.182 0.021 0.000
## Moderate 0.303 0.252 0.167
## Not sure 0.091 0.032 0.000
## Very conservative 0.212 0.199 0.250
## Very liberal 0.061 0.005 0.000
##
## Gary Johnson Hillary Clinton Jill Stein Other
## Conservative 0.294 0.050 0.062 0.324
## Liberal 0.030 0.342 0.295 0.088
## Moderate 0.541 0.424 0.384 0.352
## Not sure 0.043 0.036 0.018 0.033
## Very conservative 0.069 0.008 0.009 0.154
## Very liberal 0.022 0.139 0.232 0.049
- About fifty percent of the people who vote for Trump in 2016 identify themselves as a conservative while only about two percent of them answer they are liberal.
- “Moderate” is the largest ideological group(42.4%) and “Liberal” is the second largest one(34.2%) among the people who vote for Hillary.
- Moderate people are more likely to decide not to vote for the 2016 election than other groups.
table(NewVoterData$Abortion,NewVoterData$Region)%>%
prop.table(2)%>%round(3)
##
## Midwest Northeast Not in U.S.
## Illegal in all cases 0.149 0.100 0.167
## Legal in all cases 0.330 0.373 0.241
## Legal in some cases and illegal in others 0.481 0.477 0.593
## Not sure 0.040 0.050 0.000
##
## South West
## Illegal in all cases 0.146 0.106
## Legal in all cases 0.309 0.385
## Legal in some cases and illegal in others 0.503 0.475
## Not sure 0.043 0.033
- In all regions, the number of people who believe that abortion is illegal in all cases is smaller than that of pro-choice people.
- In all regions, the most common response is that whether the government should prohibit abortion depends on the case.
table(NewVoterData$Religion,NewVoterData$Vote2016)
##
## Did not vote for President Donald Trump
## Agnostic 2 100
## Atheist 0 48
## Buddhist 1 12
## Eastern or Greek Orthodox 0 15
## Hindu 0 1
## Jewish 0 88
## Mormon 0 71
## Muslim 0 3
## Nothing in Particular 4 403
## Protestant 15 1646
## Roman Catholic 7 906
## Something else 4 166
##
## Evan McMullin Gary Johnson Hillary Clinton
## Agnostic 0 14 314
## Atheist 0 12 288
## Buddhist 0 0 48
## Eastern or Greek Orthodox 0 1 12
## Hindu 0 0 7
## Jewish 0 2 164
## Mormon 13 8 34
## Muslim 0 0 16
## Nothing in Particular 2 43 614
## Protestant 6 81 1146
## Roman Catholic 1 54 649
## Something else 2 16 233
##
## Jill Stein Other
## Agnostic 19 6
## Atheist 13 8
## Buddhist 4 1
## Eastern or Greek Orthodox 0 0
## Hindu 0 0
## Jewish 0 4
## Mormon 2 4
## Muslim 0 1
## Nothing in Particular 28 21
## Protestant 15 84
## Roman Catholic 16 42
## Something else 14 11
table(NewVoterData$Religion,NewVoterData$Vote2016)%>%
prop.table(1)%>%round(3)
##
## Did not vote for President Donald Trump
## Agnostic 0.004 0.220
## Atheist 0.000 0.130
## Buddhist 0.015 0.182
## Eastern or Greek Orthodox 0.000 0.536
## Hindu 0.000 0.125
## Jewish 0.000 0.341
## Mormon 0.000 0.538
## Muslim 0.000 0.150
## Nothing in Particular 0.004 0.361
## Protestant 0.005 0.550
## Roman Catholic 0.004 0.541
## Something else 0.009 0.372
##
## Evan McMullin Gary Johnson Hillary Clinton
## Agnostic 0.000 0.031 0.690
## Atheist 0.000 0.033 0.780
## Buddhist 0.000 0.000 0.727
## Eastern or Greek Orthodox 0.000 0.036 0.429
## Hindu 0.000 0.000 0.875
## Jewish 0.000 0.008 0.636
## Mormon 0.098 0.061 0.258
## Muslim 0.000 0.000 0.800
## Nothing in Particular 0.002 0.039 0.551
## Protestant 0.002 0.027 0.383
## Roman Catholic 0.001 0.032 0.387
## Something else 0.004 0.036 0.522
##
## Jill Stein Other
## Agnostic 0.042 0.013
## Atheist 0.035 0.022
## Buddhist 0.061 0.015
## Eastern or Greek Orthodox 0.000 0.000
## Hindu 0.000 0.000
## Jewish 0.000 0.016
## Mormon 0.015 0.030
## Muslim 0.000 0.050
## Nothing in Particular 0.025 0.019
## Protestant 0.005 0.028
## Roman Catholic 0.010 0.025
## Something else 0.031 0.025
- Among the most largest religios group in the dataset, Protestants, Trump is the most popular candidate in the 2016 election.
- Hillary gains 72.7% of Buddhist’ votes, 87.5% of Hindu’s votes, and 80% of Muslim’s votes.