Question 1

Report the univariate distributions of ideology and partisanship, both as they’re found in the ANES, and as three part scales

library(plyr)
library(tidyverse)
library(magrittr)

d1 <- "https://github.com/thomasjwood/ps7160/raw/master/anes_cdf.RDS" %>% 
  url %>% 
  gzcon %>% 
  readRDS %>% 
  as_tibble

d1$pid_3 <- d1$VCF0301 %>% 
  plyr::mapvalues(
    c("0. DK; NA; other; refused to answer; no Pre IW",
      "1. Strong Democrat",
      "2. Weak Democrat",
      "3. Independent - Democrat",
      "4. Independent - Independent",
      "5. Independent - Republican",
      "6. Weak Republican",
      "7. Strong Republican"),
    c(NA, "dem", "ind", "rep") %>% 
      rep(c(1, 3, 1, 3))
    ) %>% 
  factor(
    c("dem", "ind", "rep")
  )

d1$ideo_3 <- d1$VCF0803  %>% 
  plyr::mapvalues(
    c("0. NA; no Post IW; form III,IV (1972); R not",
      "1. Extremely liberal",
      "2. Liberal",
      "3. Slightly liberal",
      "4. Moderate, middle of the road",
      "5. Slightly conservative",
      "6. Conservative",
      "7. Extremely conservative",
      "9. DK; haven't thought much about it"),
    c(NA, "lib", "mod", "con", "NA") %>% 
      rep(c(1, 3, 1, 3, 1))
    ) %>% 
  factor(
    c("lib", "mod", "con")
  )

Then we simply report the variables’ univariate distributions

d1 %>% 
  select(
    VCF0803, VCF0301, ends_with("_3")
  ) %>% 
  map(table)
## $VCF0803
## 
## 0. NA; no Post IW; form III,IV (1972); R not 
##                                         2379 
##                         1. Extremely liberal 
##                                          860 
##                                   2. Liberal 
##                                         3611 
##                          3. Slightly liberal 
##                                         4016 
##              4. Moderate, middle of the road 
##                                        10714 
##                     5. Slightly conservative 
##                                         5746 
##                              6. Conservative 
##                                         6031 
##                    7. Extremely conservative 
##                                         1113 
##         9. DK; haven't thought much about it 
##                                        10158 
## 
## $VCF0301
## 
## 0. DK; NA; other; refused to answer; no Pre IW 
##                                           1015 
##                             1. Strong Democrat 
##                                          11695 
##                               2. Weak Democrat 
##                                          11820 
##                      3. Independent - Democrat 
##                                           6886 
##                   4. Independent - Independent 
##                                           6988 
##                    5. Independent - Republican 
##                                           5882 
##                             6. Weak Republican 
##                                           7921 
##                           7. Strong Republican 
##                                           7075 
## 
## $pid_3
## 
##   dem   ind   rep 
## 30401  6988 20878 
## 
## $ideo_3
## 
##   lib   mod   con 
##  8487 10714 12890

Q2

Report the percentage of Americans who know the party which controls the US house, over time, among those who have a college degree or more, and among those with only a high school diploma or less

t1 <- d1 %>% 
  select(
    VCF0009x, VCF0004, VCF0729, VCF0110
  ) %>%
  mutate(
    educ_3 = VCF0110 %>% 
      mapvalues(
        c("0. DK; NA; no Pre IW; short-form 'new' Cross Section",
          "1. Grade school or less (0-8 grades)",
          "2. High school (12 grades or fewer, incl. non-college",
          "3. Some college (13 grades or more but no degree;",
          "4. College or advanced degree (no cases 1948)"),
        c(NA,
          "hsd or less", "hsd or less",
          NA,
          "ba or more"
          )
        ) %>% 
      factor(
        c("hsd or less", "ba or more")
      )
    ) %>% 
  filter(
    VCF0729 %>% 
      is_in(
        c("1. Incorrect party mentioned; DK; No",
          "2. Correct party mentioned")
        ) &
    educ_3 %>% 
      is.na %>% 
      not
    ) %>% 
  group_by(
    VCF0004, educ_3, VCF0729
    ) %>% 
  tally %>% 
  mutate(
    prop = n %>% 
      divide_by(
        n %>% 
          sum
      )
  ) %>% 
  filter(
    VCF0729 %>% 
      str_detect("1. ") %>% 
      not
  ) 

t1 %>% 
  ggplot(
    aes(
      VCF0004, color = educ_3, prop
      )
    ) +
  geom_line()

Q3

Make a table showing the percentage of Americans who think the economy has improved over the last year, and the US standing in the world has improved, by year, and by respondents’ partisanship (measured on a three point scale).

t2 <- d1 %>% 
  select(
    VCF0009x, VCF0004, VCF0870, pid_3
  ) %>%
  mutate(
    econ_better =VCF0870 %>% 
      plyr::mapvalues(
        c("0. NA", "1. Better", "3. Stayed same", "5. Worse", "8. DK"),
        c(NA, "better", "not better", "not better", "not better")
        )
    ) %>% 
  filter(
    pid_3 %>% 
      is.na %>% 
      not &
    econ_better %>% 
      is.na %>%
      not
    ) %>% 
  group_by(
    VCF0004, pid_3, econ_better
    ) %>% 
  tally %>% 
  mutate(
    prop = n %>% 
      divide_by(
        n %>% 
          sum
      )
  ) 


t2 %>% 
  filter(
    econ_better == "better"
  ) %>% 
  ggplot(
    aes(VCF0004, prop, color = pid_3)
  ) +
  geom_line()

t2_1 <- d1 %>% 
  select(
    VCF0009x, VCF0004, VCF9045, pid_3
  ) %>%
  mutate(
    world_better =VCF9045 %>% 
      plyr::mapvalues(
        c("1. Weaker (1958,1960,1964,1968: less strong)",
          "3. Same",
          "5. Stronger",
          "8. DK", "9. NA"),
        c("not better", "not better", "better", "not better", NA)
        )
    ) %>% 
  filter(
    pid_3 %>% 
      is.na %>% 
      not &
    world_better %>% 
      is.na %>%
      not
    ) %>% 
  group_by(
    VCF0004, pid_3, world_better
    ) %>% 
  tally %>% 
  mutate(
    prop = n %>% 
      divide_by(
        n %>% 
          sum
      )
  ) 


t2_1 %>% 
  filter(
    world_better == "better"
  ) %>% 
  ggplot(
    aes(VCF0004, prop, color = pid_3)
  ) +
  geom_line()

Question 4

Take the tables you made for Q.3 and discard the independents. Now, instead of reporting these quantities by year, report them when a respondent’s copartisan is the incumbent president, or when a respondent’s copartisan is not the incumbent president.

t3 <- t2 %>% 
  filter(
    pid_3 %>% 
      equals(
        "ind"
      ) %>% 
      not
    ) %>% 
  mutate(
    pres_party = ifelse(
      (
        pid_3 %>%
          equals("dem") &
        VCF0004 %>%
          is_in(
            c(1980, 1994, 1996, 1998, 2000, 2012, 2016)
            )
        ) | (
        pid_3 %>%
          equals("dem") %>% 
          not &
        VCF0004 %>%
          is_in(
            c(1982, 1984, 1986, 1988, 1990, 1992, 2002, 2004, 2008)
            )
        ),
      "in party",
      "out party"
      )
    ) %>% 
  group_by(
    pres_party, econ_better 
  ) %>% 
  tally(n) %>% 
  mutate(
    prop = n %>% 
      divide_by(n %>% 
                  sum)
  ) %>% 
  filter(
    econ_better == "better"
  )

t3
## # A tibble: 2 x 4
## # Groups:   pres_party [2]
##   pres_party econ_better     n  prop
##   <chr>      <fct>       <int> <dbl>
## 1 in party   better       5541 0.357
## 2 out party  better       1972 0.127
t2_1_1 <- t2_1 %>% 
  filter(
    pid_3 %>% 
      equals(
        "ind"
      ) %>% 
      not
    ) %>% 
  mutate(
    pres_party = ifelse(
      (
        pid_3 %>%
          equals("dem") &
        VCF0004 %>%
          is_in(
            c(1980, 1994, 1996, 1998, 2000, 2012, 2016)
            )
        ) | (
        pid_3 %>%
          equals("dem") %>% 
          not &
        VCF0004 %>%
          is_in(
            c(1982, 1984, 1986, 1988, 1990, 1992, 2002, 2004, 2008)
            )
        ),
      "in party",
      "out party"
      )
    ) %>% 
  group_by(
    pres_party, world_better 
  ) %>% 
  tally(n) %>% 
  mutate(
    prop = n %>% 
      divide_by(n %>% 
                  sum)
  ) %>% 
  filter(
    world_better == "better"
  )


t2_1_1
## # A tibble: 2 x 4
## # Groups:   pres_party [2]
##   pres_party world_better     n  prop
##   <chr>      <fct>        <int> <dbl>
## 1 in party   better        3993 0.281
## 2 out party  better        2767 0.143