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_timeseries_cdf_spss_20220916.rds" %>% 
  url %>% 
  gzcon %>% 
  readRDS

# an old crummy way

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")
  )

# a nice tidy way

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

d1$ideo_3 <- d1$VCF0803  %>% 
  case_match(
  c("0. NA; no Post IW; form III,IV (1972); R not",
    "9. DK; haven't thought much about it") ~ NA,
  
  c("1. Extremely liberal",
    "2. Liberal",
    "3. Slightly liberal") ~ "lib",
    
    "4. Moderate, middle of the road" ~ "mod",
  
  c("5. Slightly conservative",
    "6. Conservative",
    "7. Extremely conservative") ~ "con"
  ) %>% 
  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 
##                                            0 
##                         1. Extremely liberal 
##                                         1229 
##                                   2. Liberal 
##                                         4821 
##                          3. Slightly liberal 
##                                         4934 
##              4. Moderate, middle of the road 
##                                        12532 
##                     5. Slightly conservative 
##                                         6567 
##                              6. Conservative 
##                                         7523 
##                    7. Extremely conservative 
##                                         1541 
##         9. DK; haven't thought much about it 
##                                        11361 
## 
## $VCF0301
## 
## 0. DK; NA; other; refused to answer; no Pre IW 
##                                              0 
##                             1. Strong Democrat 
##                                          13656 
##                               2. Weak Democrat 
##                                          12720 
##                      3. Independent - Democrat 
##                                           7861 
##                   4. Independent - Independent 
##                                           7956 
##                    5. Independent - Republican 
##                                           6761 
##                             6. Weak Republican 
##                                           8753 
##                           7. Strong Republican 
##                                           8805 
## 
## $pid_3
## 
##   dem   ind   rep 
## 34237  7956 24319 
## 
## $ideo_3
## 
##   lib   mod   con 
## 10984 12532 15631
# or more formulaically 

table(d1$VCF0803)
## 
## 0. NA; no Post IW; form III,IV (1972); R not 
##                                            0 
##                         1. Extremely liberal 
##                                         1229 
##                                   2. Liberal 
##                                         4821 
##                          3. Slightly liberal 
##                                         4934 
##              4. Moderate, middle of the road 
##                                        12532 
##                     5. Slightly conservative 
##                                         6567 
##                              6. Conservative 
##                                         7523 
##                    7. Extremely conservative 
##                                         1541 
##         9. DK; haven't thought much about it 
##                                        11361
table(d1$VCF0301)
## 
## 0. DK; NA; other; refused to answer; no Pre IW 
##                                              0 
##                             1. Strong Democrat 
##                                          13656 
##                               2. Weak Democrat 
##                                          12720 
##                      3. Independent - Democrat 
##                                           7861 
##                   4. Independent - Independent 
##                                           7956 
##                    5. Independent - Republican 
##                                           6761 
##                             6. Weak Republican 
##                                           8753 
##                           7. Strong Republican 
##                                           8805
table(d1$ideo_3)
## 
##   lib   mod   con 
## 10984 12532 15631
table(d1$pid_3)
## 
##   dem   ind   rep 
## 34237  7956 24319

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 %>% 
      as.character %>% 
      case_match(
        c("0. DK; NA; no Pre IW; short-form 'new' Cross Section",
          "3. Some college (13 grades or more but no degree;") ~ NA,
          
        c("1. Grade school or less (0-8 grades)",
          "2. High school (12 grades or fewer, incl. non-college") ~ "hsd or less",
          
        "4. College or advanced degree (no cases 1948)" ~ "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 %>% 
      case_match(
        "0. NA" ~ NA,
        "1. Better" ~ "better",
        c("3. Stayed same", "5. Worse", "8. DK") ~ "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 %>% 
      case_match(
        c("1. Weaker (1958,1960,1964,1968: less strong)",
          "3. Same",
          "8. DK") ~ "not better",
        "5. Stronger" ~ "better",
        "9. NA" ~ 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 × 4
## # Groups:   pres_party [2]
##   pres_party econ_better     n  prop
##   <chr>      <chr>       <int> <dbl>
## 1 in party   better       5541 0.361
## 2 out party  better       3381 0.149
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 × 4
## # Groups:   pres_party [2]
##   pres_party world_better     n  prop
##   <chr>      <chr>        <int> <dbl>
## 1 in party   better        3993 0.281
## 2 out party  better        4454 0.168