##Part A for Blais and Boyer: Assessing the impact of television debates: The case of the 1988 Canadian Election##

A.1 The Research Question:

The main research question of this paper is if television debates have an impact on election outcomes and the size of the impact (if there is one). The secondary research question of this paper pertains to the best methodological practices (cross sectional comparisons, panel analysis, panel reactions analysis, and time series analysis) of measuring the impact of debates on public opinion and vote intention, due to the endogenous nature of how information is disseminated.

A.2 The hypothesis:

Debate related hypotheses:

Past evidence has shown that debates can have an impact of vote intentions, with no indication that the 1988 election is any different. This means that Blais and Boyer expect effects from the debate. Blais and Boyer also discuss the likely indirect effects of the debate (the dissemination of information) which will lead to an underestimation of the effect size of the debate

Method related hypotheses: A time series analysis is the most reliable way to measure the direct and indirect effects of debates on vote intention. With the other methods having serious conceptual and practical flaws.

A.3 The data sources:

The data comes from the 1988 Canadian Elections Survey, including the campaign period telephone survey (N= 3609), the post-election telephone survey (N= 2922), and the self administered mail-back survey (N= 2114). With the campaign survey being a rolling cross section.

A.4 The main findings of the hypothesis:

Debates had a substantive and lasting impact on vote intentions with the liberals gaining on the two other parties post-debate. The initial impact was abrupt within the first three days. There was evidence for direct and indirect effects of the debate on those who watched and did not watch the debates. The impact of direct and indirect debate watching effects were found. Confirming the hypothesis that the debate had and effect on vote intentions.

From a methods standpoint, the panel reactions and time series were found to be better suited for measuring the impact of debates. The time-series produced strong evidence and large effects of the debate. The panel reactions likely underestimated the effect of the debate but still found results. Together these two methods allow for measuring of direct and indirect effects, making for stronger methodological measurements of debate effects.

##Part B for Blais and Boyer: Assessing the impact of telivides debates: The case of the 1988 Canadian Election##

#Recoding Vote intention dummys for Figures 1 and 2
CES88 <- CES88 %>% mutate(con = case_when(b2 == 1 | b3 == 1 ~ 1, 
                                          b2 == 2 | b2 == 3 |
                                          b2 == 4 | b3 == 2 | b3 == 3 |
                                          b3 == 4 ~ 0, TRUE ~ NA_real_))

CES88 <- CES88 %>% mutate(lib = case_when(b2 == 2 | b3 == 2 ~ 1, 
                                          b2 == 1 | b2 == 3 |
                                          b2 == 4 | b3 == 1 | b3 == 3 |
                                          b3 == 4 ~ 0, TRUE ~ NA_real_))
 
CES88 <- CES88 %>% mutate(ndp = case_when(b2 == 3 | b3 == 3 ~ 1, 
                                          b2 == 1 | b2 == 2 |
                                          b2 == 4 | b3 == 1 | b3 == 2 |
                                          b3 == 4 ~ 0, TRUE ~ NA_real_))

CES88 <- CES88 %>% mutate(weight1 = case_when(wt1 == wt1 ~ wt1))

CES88 <- CES88 %>% mutate(weight2 = case_when(wt2 == wt2 ~ wt2))


CES88$intdate <- as.Date(as.character(CES88$intdate), format = "%m%d%y")
#Creating 5 day rolling averages for vote intentions
CES88_tbl <- CES88 %>%
  group_by(intdate) %>% 
  summarise(con = weighted.mean(con, weight1, na.rm = TRUE),
            lib = weighted.mean(lib, weight1, na.rm = TRUE),
            ndp = weighted.mean(ndp, weight1, na.rm = TRUE))

CES88_tbl <- CES88_tbl %>% 
  mutate(con5d = zoo::rollmean(con, k = 5, fill = NA)) %>%
  mutate(lib5d = zoo::rollmean(lib, k = 5, fill = NA)) %>%
  mutate(ndp5d = zoo::rollmean(ndp, k = 5, fill = NA))

#creating custom 5 day averages for first and last days of the survey period

CES88_tbl$con5d[2] <- (CES88_tbl$con[1] + CES88_tbl$con[2] + CES88_tbl$con[3] + CES88_tbl$con[4]) / 4
CES88_tbl$lib5d[2] <- (CES88_tbl$lib[1] + CES88_tbl$lib[2] + CES88_tbl$lib[3] + CES88_tbl$lib[4]) / 4
CES88_tbl$ndp5d[2] <- (CES88_tbl$ndp[1] + CES88_tbl$ndp[2] + CES88_tbl$ndp[3] + CES88_tbl$ndp[4]) / 4

CES88_tbl$con5d[46] <- (CES88_tbl$con[44] + CES88_tbl$con[45] + CES88_tbl$con[46] + CES88_tbl$con[47]) / 4
CES88_tbl$lib5d[46] <- (CES88_tbl$lib[44] + CES88_tbl$lib[45] + CES88_tbl$lib[46] + CES88_tbl$lib[47]) / 4
CES88_tbl$ndp5d[46] <- (CES88_tbl$ndp[44] + CES88_tbl$ndp[45] + CES88_tbl$ndp[46] + CES88_tbl$ndp[47]) / 4

CES88_tbl$con5d[47] <- (CES88_tbl$con[45] + CES88_tbl$con[46] + CES88_tbl$con[47]) / 3
CES88_tbl$lib5d[47] <- (CES88_tbl$lib[45] + CES88_tbl$lib[46] + CES88_tbl$lib[47]) / 3
CES88_tbl$ndp5d[47] <- (CES88_tbl$ndp[45] + CES88_tbl$ndp[46] + CES88_tbl$ndp[47]) / 3

##Part B.1 Recreating Figure 1##

#recreating figure 1

ggplot(CES88_tbl, aes(x = intdate)) +
  geom_line(aes(y = con5d, linetype = "Conservative Party"), na.rm = TRUE) +
  geom_line(aes(y = lib5d, linetype = "Liberal Party"), na.rm = TRUE) +
  geom_line(aes(y = ndp5d, linetype = "NDP"), na.rm = TRUE) +
  geom_vline(xintercept = as.Date("1988-10-25"), linetype = "dotted") + 
  scale_x_date(date_breaks = "5 day", date_minor_breaks = "1 day", date_labels = "%b %d") +
  scale_y_continuous(labels = function(x) paste0(x * 100), limits = c(.05, .60), breaks = seq(.05, .60, by = .05)) +
  theme_bw() +
  theme(legend.title = element_blank()) +
  labs(x= "", y = "(%) Vote Intentions",
     title = "Figure 1 Vote Intenstions by Party")

#creating dummies for watching the debate. 
CES88 <- CES88 %>% 
  mutate(debate = case_when(xc5 == 1 ~ 1, xc5 == 5 | xc5 == 8 ~ 0))

CES88 <- CES88 %>% 
  mutate(labels1 = case_when(debate == 0 ~ "Did Not See Debate",
                             debate == 1 ~ "Saw Debate"))

#same process as figure 1, creating 5 day averages 
CES88_tbl.2 <- CES88 %>%
  group_by(intdate, debate, labels1) %>% 
  filter(is.na(debate) == FALSE) %>% 
  summarise(con = weighted.mean(con, weight1, na.rm = TRUE),
            lib = weighted.mean(lib, weight1, na.rm = TRUE),
            ndp = weighted.mean(ndp, weight1, na.rm = TRUE))
## `summarise()` has grouped output by 'intdate', 'debate'. You can override using
## the `.groups` argument.
CES88_tbl.2 <- CES88_tbl.2 %>% 
  group_by(debate, labels1) %>% 
  mutate(con5d = zoo::rollmean(con, k = 5, fill = NA)) %>%
  mutate(lib5d = zoo::rollmean(lib, k = 5, fill = NA)) %>%
  mutate(ndp5d = zoo::rollmean(ndp, k = 5, fill = NA))

#creating custom first and last 5 day averages
CES88_tbl.2$con5d[3] <- (CES88_tbl.2$con[1] + CES88_tbl.2$con[3] + CES88_tbl.2$con[7] + CES88_tbl.2$con[7]) / 4
CES88_tbl.2$lib5d[3] <- (CES88_tbl.2$lib[1] + CES88_tbl.2$lib[3] + CES88_tbl.2$lib[7] + CES88_tbl.2$lib[7]) / 4
CES88_tbl.2$ndp5d[3] <- (CES88_tbl.2$ndp[1] + CES88_tbl.2$ndp[3] + CES88_tbl.2$ndp[7] + CES88_tbl.2$ndp[7]) / 4
CES88_tbl.2$con5d[4] <- (CES88_tbl.2$con[2] + CES88_tbl.2$con[4] + CES88_tbl.2$con[6] + CES88_tbl.2$con[8]) / 4
CES88_tbl.2$lib5d[4] <- (CES88_tbl.2$lib[2] + CES88_tbl.2$lib[4] + CES88_tbl.2$lib[6] + CES88_tbl.2$lib[8]) / 4
CES88_tbl.2$ndp5d[4] <- (CES88_tbl.2$ndp[2] + CES88_tbl.2$ndp[4] + CES88_tbl.2$ndp[6] + CES88_tbl.2$ndp[8]) / 4

CES88_tbl.2$con5d[91] <- (CES88_tbl.2$con[87] + CES88_tbl.2$con[89] + CES88_tbl.2$con[91] + CES88_tbl.2$con[93]) / 4
CES88_tbl.2$lib5d[91] <- (CES88_tbl.2$lib[87] + CES88_tbl.2$lib[89] + CES88_tbl.2$lib[91] + CES88_tbl.2$lib[93]) / 4
CES88_tbl.2$ndp5d[91] <- (CES88_tbl.2$ndp[87] + CES88_tbl.2$ndp[89] + CES88_tbl.2$ndp[91] + CES88_tbl.2$ndp[93]) / 4
CES88_tbl.2$con5d[92] <- (CES88_tbl.2$con[88] + CES88_tbl.2$con[90] + CES88_tbl.2$con[92] + CES88_tbl.2$con[94]) / 4
CES88_tbl.2$lib5d[92] <- (CES88_tbl.2$lib[88] + CES88_tbl.2$lib[90] + CES88_tbl.2$lib[92] + CES88_tbl.2$lib[94]) / 4
CES88_tbl.2$ndp5d[92] <- (CES88_tbl.2$ndp[88] + CES88_tbl.2$ndp[90] + CES88_tbl.2$ndp[92] + CES88_tbl.2$ndp[94]) / 4

CES88_tbl.2$con5d[93] <- (CES88_tbl.2$con[89] + CES88_tbl.2$con[91] + CES88_tbl.2$con[93]) / 3
CES88_tbl.2$lib5d[93] <- (CES88_tbl.2$lib[89] + CES88_tbl.2$lib[91] + CES88_tbl.2$lib[93]) / 3
CES88_tbl.2$ndp5d[93] <- (CES88_tbl.2$ndp[89] + CES88_tbl.2$ndp[91] + CES88_tbl.2$ndp[93]) / 3
CES88_tbl.2$con5d[94] <- (CES88_tbl.2$con[90] + CES88_tbl.2$con[92] + CES88_tbl.2$con[94]) / 3
CES88_tbl.2$lib5d[94] <- (CES88_tbl.2$lib[90] + CES88_tbl.2$lib[92] + CES88_tbl.2$lib[94]) / 3
CES88_tbl.2$ndp5d[94] <- (CES88_tbl.2$ndp[90] + CES88_tbl.2$ndp[92] + CES88_tbl.2$ndp[94]) / 3

B.1 Recreating Figure 2

#recreating figure 2

ggplot(CES88_tbl.2, aes(x = intdate, y = con5d, group = labels1, linetype = labels1)) +
  geom_line(na.rm = TRUE) +
  geom_vline(xintercept = as.Date("1988-10-25"), linetype = "dotted") + 
  scale_x_date(date_breaks = "5 day", date_minor_breaks = "1 day", date_labels = "%b %d") +
  scale_y_continuous(labels = function(x) paste0(x * 100), limits = c(.20, .70), breaks = seq(.20, .70, by = .05)) +
  theme_bw() +
  theme(legend.title = element_blank()) +
  labs(x= "", y = "(%) Vote Intentions (Cons)"
       , title = "Figure 2 Debate Watchers Conservatives")

##B.1 Recreating Figure 3##

#recreating figure 3
ggplot(CES88_tbl.2, aes(x = intdate, y = lib5d, group = labels1, linetype = labels1)) +
  geom_line(na.rm = TRUE) +
  geom_vline(xintercept = as.Date("1988-10-25"), linetype = "dotted") + 
  scale_x_date(date_breaks = "5 day", date_minor_breaks = "1 day", date_labels = "%b %d") +
  scale_y_continuous(labels = function(x) paste0(x * 100), limits = c(.0, .50), breaks = seq(.0, .50, by = .05)) +
  theme_bw() +
  theme(legend.title = element_blank()) +
  labs(x= "", y = "(%) Vote Intentions (Cons)",
       title = "Figure 3. Debate Watchers Liberals")

##B.1 Recreating Table 2##

#recoding the dummy variables and control variables for Article 1 Tables 2 and 3

CES88 <- CES88 %>% mutate(conlib = case_when(xb2 == 1 ~ 1,
                                            xb2 == 2 ~ 0))

CES88 <- CES88 %>% mutate(libndp = case_when(xb2 == 2 ~ 1,
                                            xb2 == 3 ~ 0))

CES88 <- CES88 %>% mutate(conid = case_when(i1 == 2 | i4 == 2 | xl4 == 2 | xl7 == 2 ~ 1,
                          i1 == 1 | i4 == 1 | xl4 == 1 | xl7 == 1 ~ -1,
                          i1 == 3 | i4 == 3 | xl4 == 3 | xl7 == 3 |
                          i1 == 4 | i4 == 4 | xl4 == 4 | xl7 == 4 ~ 0)) 
  
  
CES88 <- CES88 %>% mutate(libid = case_when(i1 == 1 | i4 == 1 | xl4 == 1 | xl7 == 1 ~ 1,
                          i1 == 3 | i4 == 3 | xl4 == 3 | xl7 == 3 ~ -1,
                          i1 == 2 | i4 == 2 | xl4 == 2 | xl7 == 2 |
                          i1 == 4 | i4 == 4 | xl4 == 4 | xl7 == 4 ~ 0)) 

CES88 <- CES88 %>% mutate(union = case_when(n9 == 1 | xj1a == 1 ~ 1, 
                                           n9 == 5 | xj1a == 5 ~ 0,
                                          TRUE ~ NA_real_))

CES88 <- CES88 %>% mutate(woman = case_when(rsex == 5 | xrsex == 5 ~ 1,
                                    rsex == 1 | xrsex == 1 ~ 0, TRUE ~ NA_real_))

CES88 <- CES88 %>% mutate(Quebec = case_when(province == 4 | xprov == 4 ~ 1, TRUE ~ 0))

CES88 <- CES88 %>% mutate(West = case_when(province == 6 | province == 7 |
                                           province == 8 | province == 9 | xprov == 6 | xprov == 7 |
                                           xprov == 8 | xprov == 9 ~ 1, 
                                           TRUE ~ 0))

CES88 <- CES88 %>% mutate(Catholic = case_when(n11 == 2 ~ 1, TRUE ~ 0))

CES88 <- CES88 %>% mutate(Higheducation = case_when(n3 == 8 | n3 == 9 | n3 == 10 | n3 == 11 ~ 1, TRUE ~ 0))

#creating regressions for table 2 in article 1
model.conlib <- lm(conlib ~ debate + conid + union + woman + Quebec + West + Catholic + Higheducation, data = CES88)
model.libndp <- lm(libndp ~ debate + libid + union + woman + Quebec + West + Catholic + Higheducation, data = CES88)

#Visualizing regression outputs for table 2
table2 <- list(
  "Vote: PC versus Liberal" = model.conlib,
  "Vote: Liberal versus NDP" = model.libndp)

modelsummary(table2,
             fmt = 2,
             stars = TRUE,
             statistic = "std.error",
             coef_map = c("debate" = "Debate watching",
                          "conid" = "Party identification",
                          "libid" = "Party identification",
                          "union" = "Union",
                          "woman" = "Woman",
                          "Quebec" = "Quebec",
                          "West" = "West",
                          "Catholic" = "Catholic",
                          "Higheducation" = "High Education",
                          "(Intercept)" = "Constant"),
             gof_map = c("nobs", "adj.r.squared"),
             output = "huxtable")
Vote: PC versus LiberalVote: Liberal versus NDP
Debate watching-0.030.02
(0.02)(0.02)
Party identification0.36***0.36***
(0.01)(0.01)
Union0.02-0.06**
(0.02)(0.02)
Woman-0.05**0.02
(0.02)(0.02)
Quebec0.15***-0.05+
(0.02)(0.03)
West0.05*-0.15***
(0.02)(0.02)
Catholic-0.02-0.02
(0.02)(0.02)
High Education0.04*0.03
(0.02)(0.02)
Constant0.53***0.57***
(0.02)(0.03)
Num.Obs.17131116
R2 Adj.0.5110.515
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001

Some of the regression outputs from this model are slightly off. Including the direction of debate watching. My N’s are slightly off in both models which could be leading to the difference in coefficients or statistical significance. But overall I feel like this could also be a difference in statistical software.

##B.1 Recreating Table 3##

#Recreating table 3 for article 1 including leader evaluations

CES88 <- CES88 %>% 
  mutate(conlead = case_when(d2a >= 0 &
                             d2a <= 100 ~ d2a/100,
                             TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(liblead = case_when(d2b >= 0 &
                             d2b <= 100 ~ d2b/100,
                             TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(ndplead = case_when(d2c >= 0 &
                             d2c <= 100 ~ d2c/100,
                             TRUE ~ NA_real_))

CES88 <- CES88 %>% mutate(thermconlib = conlead - liblead)

CES88 <- CES88 %>% mutate(thermlibndp = liblead - ndplead)

CES88 <- CES88 %>% mutate(voteintcon = case_when(b2 == 1 ~ 1, 
                                      b2 == 2 ~ -1,
                                      b2 == 3 | b2 == 4 ~ 0))

CES88 <- CES88 %>% mutate(voteintlib = case_when(b2 == 2 ~ 1, 
                                      b2 == 3 ~ -1,
                                      b2 == 1 | b2 == 4  ~ 0))
#adding leader evaluations to the previous regressions
model.conlib2 <- lm(conlib ~ debate + thermconlib + conid + union + woman + Quebec + West + Catholic + Higheducation + voteintcon, data = subset(CES88, intype == 3))
model.libndp2 <- lm(libndp ~ debate + thermlibndp + libid + union + woman + Quebec + West + Catholic + Higheducation + voteintlib, data = subset(CES88, intype == 3))

#displaying regressions in a table format
table3 <- list(
  "Vote: PC versus Liberal" = model.conlib2,
  "Vote: Liberal versus NDP" = model.libndp2)

modelsummary(table3,
             fmt = 2,
             stars = TRUE,
             statistic = "std.error",
             coef_map = c("debate" = "Debate watching",
                          "thermconlib" = "Leader Evaluation",
                          "thermlibndp" = "Leader Evaluation",
                          "conid" = "Party identification",
                          "libid" = "Party identification",
                          "union" = "Union",
                          "woman" = "Woman",
                          "Quebec" = "Quebec",
                          "West" = "West",
                          "Catholic" = "Catholic",
                          "Higheducation" = "High Education",
                          "voteintcon" = "Voting intention",
                          "voteintlib" = "Voting intention",
                          "(Intercept)" = "Constant"),
             gof_map = c("nobs", "adj.r.squared"),
             output = "huxtable")
Vote: PC versus LiberalVote: Liberal versus NDP
Debate watching-0.010.01
(0.02)(0.03)
Leader Evaluation0.19***0.15*
(0.04)(0.06)
Party identification0.15***0.18***
(0.02)(0.02)
Union0.02-0.01
(0.02)(0.03)
Woman-0.04+0.03
(0.02)(0.03)
Quebec0.06*-0.02
(0.03)(0.04)
West0.01-0.16***
(0.02)(0.03)
Catholic-0.01-0.05+
(0.02)(0.03)
High Education0.020.04
(0.02)(0.03)
Voting intention0.25***0.22***
(0.02)(0.02)
Constant0.52***0.59***
(0.03)(0.04)
Num.Obs.683406
R2 Adj.0.7230.669
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001

For Table 3, the coefficients are once again close but not exact. My N in both models is around 200 higher which is likely the cause in the difference. Interestingly, the R Squared is much higher in my models as well, which is a tell that some of the control variables are coded differently.

##Part A for Banducci and Karp: Gender, Leadership and Choice in Multi-Party Systems##

A.1 The Research Question

What is the effect of women party leaders in parliamentary elections on leadership evaluations and voting behavior? More specifically, to what extent do female leaders act as ques for vote choice and how much do leader evaluations modify this process?

A.2 The hypothesis

H1 The paper expects gender effects regardless of ideological leaning and the effect to be stronger in cases where the candidates gender or gender issues were made salient throughout the campaign. Additionally, women who view women leaders more favorable will be more willing to vote for them. This means that women are more likely to support parties led by women even after accounting for controls.

H2 The gender identity hypothesis will apply to parliamentary elections with female party leaders due to their increased visibility compared to candidates. In addition to the gender identity of the leader impacting voting behavior, gender should also impact leadership evaluations as well.

H3: Women leadership effects will be stronger in New Zealand than in single member district systems like Canada, Australia, and Britain.

A.3 The data sources:

The Data used in this study includes the 1993 Canadian Election Survey, the 1979 and 1987 British Election Survey, and the 1996 Australian and New Zealand election surveys.

A.4 The main findings of the hypothesis:

  1. Gender impacts vote choice when a woman is the leader, even after controlling for partisanship. This means that women voters are more likely to vote for women on average.

  2. The effects of gender are not conditioned by leadership evaluations in most cases, even though women evaluated women leaders higher. Additionally, gender is not the major factor determining vote choice for women leaders, with economic and demographic effects also mattering.

  3. The hypothesis that New Zealand would have a stronger woman effect due to not having single member district ended up with null findings.

  4. The gender effects apply to leaders on the right and the left (with a few out liar cases) and are stronger in Canada and New Zealand.

  5. Leadership evaluations have a larger impact on women vote choice than on male vote choice.

#Loading datasets for Banducci and Karp
CES93 <- read.csv("CES-E-1993_F1.csv")
AES96 <- read_sav("Australian Election Study 1996.sav")

##Part B.2 Recreating Table 1##

#recoding variables gender and leader evals for figure 1

CES93 <- CES93 %>% 
  mutate(gender93 = case_when(PESRGEN == 5 ~ "Women",
                              PESRGEN == 1 ~ "Men")) %>% 
                              filter(is.na(gender93) == FALSE)

CES93 <- CES93 %>% 
  mutate(vote93 = case_when(PESA4 == 1 ~ "Conservatives",
                             PESA4 == 2 ~ "Liberal",
                             PESA4 == 3 ~ "NDP",
                             PESA4 == 4 ~ "Reform",
                             PESA4 == 5 ~ "Bloq Quebecois")) %>%
                              filter(is.na(vote93) == FALSE)

CES93 <- CES93 %>% 
  mutate(campbelltherm = case_when(PESD2A >= 0 & PESD2A <= 100 ~ PESD2A/10, TRUE ~ NA_real_)) %>% 
  mutate(chretientherm = case_when(PESD2B >= 0 & PESD2B <= 100 ~ PESD2B/10, TRUE ~ NA_real_)) %>% 
  mutate(mclaughlintherm = case_when(PESD2C >= 0 & PESD2C <= 100 ~ PESD2C/10, TRUE ~ NA_real_)) %>% 
  mutate(manningtherm = case_when(PESD2D >= 0 & PESD2D <= 100 ~ PESD2C/10, TRUE ~ NA_real_))


AES96 <- AES96 %>% 
  mutate(gender96 = case_when(j1 == 2 ~ "Women",
                              j1== 1 ~ "Men")) %>% 
                              filter(is.na(gender96) == FALSE)

AES96 <- AES96 %>% 
  mutate(vote96 = case_when(b9reps == 1 | b9reps == 3 ~ "Liberal National Coalition",
                             b9reps == 2 ~ "Labout",
                             b9reps == 4 ~ "Australian Democrats",
                             b9reps == 5 ~ "Greens")) %>% 
                            filter(is.na(vote96) == FALSE)

AES96 <- AES96 %>% 
  mutate(keatingtherm = case_when(c1keat >= 0 & c1keat <= 10 ~ c1keat, TRUE ~ NA_real_)) %>% 
  mutate(howardtherm = case_when(c1how >= 0 & c1how <= 10 ~ c1how, TRUE ~ NA_real_)) %>% 
  mutate(fischertherm = case_when(c1fisch >= 0 & c1fisch <= 10 ~ c1fisch, TRUE ~ NA_real_)) %>% 
  mutate(kernottherm = case_when(c1kern >= 0 & c1kern <= 10 ~ c1kern, TRUE ~ NA_real_))

Table93 <- tbl_cross(CES93, row = vote93, col = gender93, percent = "column", margin = "row",
                     label = list(gender93 ~ "Canada 1993", vote93 ~ "Party ID"), digits = c(0,1)) %>% 
  add_p() %>% 
  add_significance_stars() %>% 
  modify_header(statistic ~ "Chi-square")
## Warning: There was 1 warning in `mutate()`.
## ℹ In argument: `vote93 = (structure(function (..., .x = ..1, .y = ..2, . = ..1)
##   ...`.
## Caused by warning:
## ! `fct_explicit_na()` was deprecated in forcats 1.0.0.
## ℹ Please use `fct_na_value_to_level()` instead.
## ℹ The deprecated feature was likely used in the dplyr package.
##   Please report the issue at <]8;;https://github.com/tidyverse/dplyr/issueshttps://github.com/tidyverse/dplyr/issues]8;;>.
Table96 <- tbl_cross(AES96, row = vote96, col = gender96, percent = "column", margin = "row",
                     label = list(gender96 ~ "Australia 1996", vote96 ~ "Party ID"), digits = c(0,1)) %>% 
  add_p() %>% 
  add_significance_stars() %>% 
  modify_header(statistic ~ "Chi-square")

Table93
Canada 1993 Chi-square p-value1
Men Women
Party ID 20.09783 <0.001***
    Bloq Quebecois 206 (15.0%) 169 (13.6%)
    Conservatives 188 (13.7%) 197 (15.8%)
    Liberal 574 (41.8%) 570 (45.8%)
    NDP 88 (6.4%) 98 (7.9%)
    Reform 318 (23.1%) 210 (16.9%)
Total 1,374 (100.0%) 1,244 (100.0%)
1 *p<0.05; **p<0.01; ***p<0.001
Table96
Australia 1996 Chi-square p-value1
Men Women
Party ID 10.53212 0.015*
    Australian Democrats 42 (5.2%) 71 (8.2%)
    Greens 16 (2.0%) 26 (3.0%)
    Labout 322 (40.0%) 300 (34.7%)
    Liberal National Coalition 424 (52.7%) 467 (54.1%)
Total 804 (100.0%) 864 (100.0%)
1 *p<0.05; **p<0.01; ***p<0.001

##Part B.2 Recreating Table 2##

#creating a new data frame for Mean leader evals by gender
  
CES93_leadereval <- CES93 %>% 
  filter(is.na(gender93) == FALSE) %>% 
  group_by(gender93) %>% 
  summarize(campbelltherm = mean(campbelltherm, na.rm = TRUE),
            chretientherm = mean(chretientherm, na.rm = TRUE),
            mclaughlintherm = mean(mclaughlintherm, na.rm = TRUE),
            manningtherm = mean(manningtherm, na.rm = TRUE))

CES93_leadereval <- as.data.frame(t(CES93_leadereval))
colnames(CES93_leadereval) <- c("Men", "Women")
CES93_leadereval <- CES93_leadereval %>% filter(Men != "Men") %>%  filter(Women != "Women")

sdcampbellmen <- (sd(subset(CES93$campbelltherm, CES93$gender93 == "Men"), na.rm = TRUE))
sdcampbellwomen <- (sd(subset(CES93$campbelltherm, CES93$gender93 == "Women"), na.rm = TRUE))
sdchretienwomen <- (sd(subset(CES93$chretientherm, CES93$gender93 == "Women"), na.rm = TRUE))
sdchretienmen <- (sd(subset(CES93$chretientherm, CES93$gender93 == "Men"), na.rm = TRUE))
sdmclaughlinmen <- (sd(subset(CES93$mclaughlintherm, CES93$gender93 == "Men"), na.rm = TRUE))
sdmclaughlinwomen <- (sd(subset(CES93$mclaughlintherm, CES93$gender93 == "Women"), na.rm = TRUE))
sdmanningmen <- (sd(subset(CES93$manningtherm, CES93$gender93 == "Men"), na.rm = TRUE))
sdmanningwomen <- (sd(subset(CES93$manningtherm, CES93$gender93 == "Women"), na.rm = TRUE))

CES93_leadereval$mensd <- c(sdcampbellmen, sdchretienmen, sdmclaughlinmen, sdmanningmen)
CES93_leadereval$womansd <- c(sdcampbellwomen, sdchretienwomen, sdmclaughlinwomen, sdmanningwomen)

rownames(CES93_leadereval) <- c("Campbell(Conservative)", "Chretien(Liberal)", "McLaughlin(NDP)", "Manning(Reform)")
colnames(CES93_leadereval) <- c("Men", "Women", "Men SD", "Women SD")

kable(CES93_leadereval, format = "html",
      caption = "Table 2. Gender and Party Leadership Evaluations: Canada")
Table 2. Gender and Party Leadership Evaluations: Canada
Men Women Men SD Women SD
Campbell(Conservative) 4.142693 4.500000 2.112110 2.112822
Chretien(Liberal) 6.411350 6.523777 1.861344 1.820453
McLaughlin(NDP) 4.203704 4.810000 1.929882 1.844126
Manning(Reform) 4.646831 4.905991 6.840365 3.711000
AES96_leadereval <- AES96 %>% 
  filter(is.na(gender96) == FALSE) %>% 
  group_by(gender96) %>% 
  summarize(keatingtherm = mean(keatingtherm, na.rm = TRUE),
            howardtherm = mean(howardtherm, na.rm = TRUE),
            fischertherm = mean(fischertherm, na.rm = TRUE),
            kernottherm = mean(kernottherm, na.rm = TRUE))

AES96_leadereval <- as.data.frame(t(AES96_leadereval))
colnames(AES96_leadereval) <- c("Men", "Women")
AES96_leadereval <- AES96_leadereval %>% filter(Men != "Men") %>%  filter(Women != "Women")

sdkeatingmen <- (sd(subset(AES96$keatingtherm, AES96$gender96 == "Men"), na.rm = TRUE))
sdkeatingwomen <- (sd(subset(AES96$keatingtherm, AES96$gender96 == "Women"), na.rm = TRUE))
sdhowardwomen <- (sd(subset(AES96$howardtherm, AES96$gender96 == "Women"), na.rm = TRUE))
sdhowardmen <- (sd(subset(AES96$howardtherm, AES96$gender96 == "Men"), na.rm = TRUE))
sdfischermen <- (sd(subset(AES96$fischertherm, AES96$gender96 == "Men"), na.rm = TRUE))
sdfischerwomen <- (sd(subset(AES96$fischertherm, AES96$gender96 == "Women"), na.rm = TRUE))
sdkernottmen <- (sd(subset(AES96$kernottherm, AES96$gender96 == "Men"), na.rm = TRUE))
sdkernottwomen <- (sd(subset(AES96$kernottherm, AES96$gender96 == "Women"), na.rm = TRUE))

AES96_leadereval$mensd <- c(sdkeatingmen, sdhowardmen, sdfischermen, sdkernottmen)
AES96_leadereval$womansd <- c(sdkeatingwomen, sdhowardwomen, sdfischerwomen, sdkernottwomen)

rownames(AES96_leadereval) <- c("Keating", "Howard", "Fischer", "Kernott")
colnames(AES96_leadereval) <- c("Men", "Women", "Men SD", "Women SD")

kable(AES96_leadereval, format = "html",
      caption = "Table 2. Gender and Party Leadership Evaluations: Australia")
Table 2. Gender and Party Leadership Evaluations: Australia
Men Women Men SD Women SD
Keating 4.396419 4.061758 3.605216 3.550349
Howard 5.632316 5.898082 2.999095 2.991051
Fischer 4.631990 4.902439 2.712061 2.602290
Kernott 5.209909 5.579781 2.476839 2.325895

For table 2 I was unable to figure out proper formatting for the charts. As for the means, some of them are slightly off. For this table I am unsure where I went wrong, considering the coding is very straightforward, maybe a weight needs to be used differently. Overall a very simular output.

##Part A for Belanger and Nadeau: Political Trust and the Vote in Multiparty Elections: The Canadian Case##

A.1 The Research Question:

What impact does political trust have on party support and electoral participation? More specifically how do distrustful Canadians vote differently from trustful ones with regards to party choice and turnout.

What impact might political trust have in the case of a multiparty systems, in terms of supporting “old-line” parties and “non-traditional party alternative”, how does lack of trust create alienated voters?

A.2 The hypothesis:

H1: People with low political trust are more likely to vote for non-traditional party alternatives compared to “old-line” parties. Suggesting a willingness to disrupt the status quo. (The reverse being true for high trust individuals)

H2: Low political trust and confidence will impact turnout negatively. Despite evidence contrary in the American case.

A.3 The data sources:

This article used the 1984, 1988, and 1993 Canadian Election Surveys

A.4 The main findings of the hypothesis:

  1. Political trust has a significant effect on vote choice in Canada, regardless of party identification. High confidence, all else being equal, results in a higher likelihood of supporting the incumbent party. In the 1993 election distrustful voters were most likely to go for the newer parties: The Reform Party and the Bloq.

  2. The negative impact of trust is always stronger for third parties than the traditional opposition party. But not all third parties benefit equally from distrustful voters.

  3. A sizable portion of distrustful voters choose to abstain. Distrust is most strongly linked with the choice to abstain compared to vote for the incumbent parties. This rejects previous American findings on alienation and turnout.

#opening 80s CES data
setwd(dirname(rstudioapi::getSourceEditorContext()$path))
CES84 <- read.csv("CES-E-1984_F1.csv")
CES88 <- read.csv("CES-E-1988_F1.csv")
CES93 <- read.csv("CES-E-1993_F1.csv")
#creating new variables + dummy variables for 3rd article including trust indexs

CES84 <- CES84 %>% 
  mutate(trust84.1 = case_when(var036 == 1 | var036 == 2 ~ 1,
                               var036 == 3 | var036 == 4 ~ -1,
                               var036 == 7 ~ 0, TRUE ~ NA_real_))

CES84 <- CES84 %>% 
  mutate(trust84.2 = case_when(var035 == 1 | var035 == 2 ~ -1,
                               var035 == 3 | var035 == 4 ~ 1,
                               var035 == 7 ~ 0, TRUE ~ NA_real_))

CES84 <- CES84 %>% 
  mutate(trust84.3 = case_when(var034 == 1 | var034 == 2 ~ -1,
                               var034 == 3 | var034 == 4 ~ 1,
                               var034 == 7 ~ 0, TRUE ~ NA_real_))
 
CES84 <- CES84 %>% 
  mutate(trust84.4 = case_when(var037 == 1 | var037 == 2 ~ 1,
                               var037 == 3 | var037 == 4 ~ -1,
                               var037 == 7 ~ 0, TRUE ~ NA_real_))

CES84 <- CES84 %>% 
  mutate(trustindex84 = (trust84.1+trust84.2+trust84.3+trust84.4)/4)

CES88 <- CES88 %>% 
  mutate(trust88.1 = case_when(qg3 == 1 ~ 1, qg3 == 2 ~ 0,
                               qg3 == 3 ~ -1, TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(trust88.2 = case_when(qg2 == 1 ~ -1, qg2 == 2 ~ 0,
                               qg2 == 3 ~ 1, TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(trust88.3 = case_when(qg1 == 1 ~ -1, qg1 == 2 ~ 0,
                               qg1 == 3 ~ 1, TRUE ~ NA_real_))
 
CES88 <- CES88 %>% 
  mutate(trust88.4 = case_when(qg4 == 1 ~ 1, qg4 == 2 ~ -1, TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(trustindex88 = (trust88.1+trust88.2+trust88.3+trust88.4)/4)

CES93 <- CES93 %>% 
  mutate(trust93.1 = case_when(MBSH3 == 1 ~ 1, MBSH3 == 2 ~ 0,
                               MBSH3 == 3 ~ -1))

CES93 <- CES93 %>% 
  mutate(trust93.2 = case_when(MBSH2 == 1 ~ -1, MBSH2 == 2 ~ 0,
                               MBSH2 == 3 ~ 1))

CES93 <- CES93 %>% 
  mutate(trust93.3 = case_when(MBSH1 == 1 ~ -1, MBSH1 == 2 ~ 0,
                               MBSH1 == 3 ~ 1))
 
CES93 <- CES93 %>% 
  mutate(trust93.4 = case_when(MBSH4 == 1 ~ 1, MBSH4 == 2 ~ -1, MBSH4 == 8 ~ 0))

CES93 <- CES93 %>% 
  mutate(trustindex93 = (trust93.1+trust93.2+trust93.3+trust93.4)/4)

#Recoding Control variables
CES84 <- CES84 %>% 
  mutate(age = case_when(var437 == var437 ~ (var437-min(var437))/(max(var437)-min(var437)), TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(birthyear88 = case_when(n1 >= 1892 & n1 <= 1975  ~ (n1-1988)*-1, TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(age = normalize(birthyear88))

CES93 <- CES93 %>% 
  mutate(birthyear93 = case_when(CPSAGE >= 1897 & CPSAGE <= 1975  ~ (1993 - CPSAGE),
                                 PESAGE >= 1897 & PESAGE <= 1975  ~ (1993 - PESAGE),
                                 MBSAGE >= 1897 & MBSAGE <= 1975  ~ (1993 - MBSAGE),
                                 REFN1 >= 1897 & REFN1 <= 1975  ~ (1993 - REFN1),
                                 PRF3 >= 1897 & PRF3 <= 1975  ~ (1993 - PRF3)))

CES93 <- CES93 %>% 
  mutate(age = normalize(birthyear93))

CES84 <- CES84 %>% 
  mutate(Male = case_when(var456 == 1 ~ 1, var456 == 2 ~ 0, TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(Male = case_when(rsex == 1 ~ 1, rsex == 5 ~ 0, TRUE ~ NA_real_))

CES93 <- CES93 %>% 
  mutate(Male = case_when(CPSRGEN == 1 | PESRGEN == 1 | MBSRGEN == 1 | REFRGEN == 1 ~ 1, 
                          CPSRGEN == 5 | PESRGEN == 5 | MBSRGEN == 5 | REFRGEN == 5 ~ 0))

CES84 <- CES84 %>% 
  mutate(var362 = case_when(var362 == 9 ~ 1,
                            var362 == 1 ~ 2,
                            var362 == 2 ~ 3,
                            var362 == 3 ~ 4,
                            var362 == 4 ~ 5,
                            var362 == 5 | var362 == 7 ~ 6,
                            var362 == 6 | var363 == 1 ~ 7,
                            var362 == 2 ~ 8,
                            var363 == 3 | var363 == 4 | var363 == 5 ~ 9, 
                            TRUE ~ NA_real_))

CES84 <- CES84 %>% 
  mutate(School = normalize(var362))

CES88 <- CES88 %>% 
  mutate(School = case_when(n3 == 1 ~ 1,
                              n3 == 2 ~ 2,
                              n3 == 3 ~ 3,
                              n3 == 4 ~ 4,
                              n3 == 5 ~ 5,
                              n3 == 6 | n3 == 8 ~ 6,
                              n3 == 7 | n3 == 9 ~ 7,
                              n3 == 10 ~ 8,
                              n3 == 11 ~ 9,
                              TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(School = normalize(n3))

CES93 <- CES93 %>%
  mutate(CPSO3 = case_when(CPSO3 == 1 | REFN2 == 1 ~ 1,
                          CPSO3 == 2 | REFN2 == 2 ~ 2,
                          CPSO3 == 3 | REFN2 == 3 ~ 3,
                          CPSO3 == 4 | REFN2 == 4 ~ 4,
                          CPSO3 == 5 | REFN2 == 5 ~ 5,
                          CPSO3 == 6 | REFN2 == 6 |
                          CPSO3 == 8 | REFN2 == 8 ~ 6,
                          CPSO3 == 7 | REFN2 == 7 |
                          CPSO3 == 9 | REFN2 == 9 ~ 7,
                          CPSO3 == 10 | REFN2 == 10 ~ 8,
                          CPSO3 == 11 | REFN2 == 11 ~ 9))

CES93 <- CES93 %>% 
  mutate(School = normalize(CPSO3))

CES84 <- CES84 %>% 
  mutate(Income = case_when(var442 >= 1 &  var442 <= 11 ~ var442, is.na(var442) == TRUE &
                                var443 <= 11 ~ var442))
                              
CES84 <- CES84 %>% mutate(Income = normalize(Income))

CES88 <- CES88 %>% 
  mutate(Income = normalize(n19))     

CES93 <- CES93 %>% 
  mutate(Income = case_when(CPSO18 <= 19 | REFN18 <= 19 | CPSO18A == 1 | REFN19 == 1 ~ 1,
                  (CPSO18 >= 20 & CPSO18 <= 29) | (REFN18 >= 20 & REFN18 <= 29) | CPSO18A == 2 | REFN19 == 2 ~ 2,
                  (CPSO18 >= 30 & CPSO18 <= 39) | (REFN18 >= 30 & REFN18 <= 39) | CPSO18A == 3 | REFN19 == 3 ~ 3,
                  (CPSO18 >= 40 & CPSO18 <= 49) | (REFN18 >= 40 & REFN18 <= 49) | CPSO18A == 4 | REFN19 == 4 ~ 4,
                  (CPSO18 >= 50 & CPSO18 <= 59) | (REFN18 >= 50 & REFN18 <= 59) | CPSO18A == 5 | REFN19 == 5 ~ 5,
                  (CPSO18 >= 60 & CPSO18 <= 69) | (REFN18 >= 60 & REFN18 <= 69) | CPSO18A == 6 | REFN19 == 6 ~ 6,
                  (CPSO18 >= 70 & CPSO18 <= 79) | (REFN18 >= 70 & REFN18 <= 79) | CPSO18A == 7 | REFN19 == 7 ~ 7,
                  (CPSO18 >= 80 & CPSO18 <= 89) | (REFN18 >= 80 & REFN18 <= 89) | CPSO18A == 8 | REFN19 == 8 ~ 8,
                  (CPSO18 >= 90 & CPSO18 <= 100) | (REFN18 >= 90 & REFN18 <= 100) | CPSO18A == 9 | REFN19 == 9 ~ 9,
                  (CPSO18 >= 101 & CPSO18 <= 997) | (REFN18 >= 101 & REFN18 <= 997) | CPSO18A == 10 | REFN19 == 10 ~ 10))

CES93 <- CES93 %>% mutate(Income = normalize(Income))

CES84 <- CES84 %>% 
  mutate(Catholic = case_when(var371 == 1 | var371 == 7 ~ 1, var371 == 0 | 
                                (var371 >= 2 & var371 <= 6) | (var371 >= 8 & var371 <= 35) ~ 0, 
                                TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(Catholic = case_when(n11 == 2 ~ 1, n11 == 1 | (n11 >= 3 & n11 <= 8) ~ 0, 
                                TRUE ~ NA_real_))

CES93 <- CES93 %>% 
  mutate(Catholic = case_when(CPSO9 == 2 | REFN9 == 2 ~ 1 ,
                          (CPSO9 != 2 & CPSO9 != 99)| (REFN9 != 2 & REFN9 != 99) ~ 0))

CES84 <- CES84 %>% 
  mutate(Atlantic = case_when(var003 == 0 | var003 == 1 | 
                                var003 == 2 | var003 == 3 ~ 1, var003 >= 4 & var003 <= 9 ~ 0, 
                                TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(Atlantic = case_when(province == 0 | province == 1 | 
                                province == 2 | province == 3 ~ 1, province >= 4 & province <= 9 ~ 0, 
                                TRUE ~ NA_real_))

CES93 <- CES93 %>% 
  mutate(Atlantic = case_when(CPSPROV == 0 | CPSPROV == 1 | 
                                CPSPROV == 2 | CPSPROV == 3 | PESPROV == 0 | PESPROV == 1 | 
                                PESPROV == 2 | PESPROV == 3 | MBSPROV == 0 | MBSPROV == 1 | 
                                MBSPROV == 2 | MBSPROV == 3 | REFPROV == 0 | REFPROV == 1 | 
                                REFPROV == 2 | REFPROV == 3 | PRPROV == 0 | PRPROV == 1 | 
                                PRPROV == 2 | PRPROV == 3 ~ 1, TRUE ~ 0))

CES84 <- CES84 %>% 
  mutate(West = case_when(var003 == 9 | var003 == 8 | 
                                var003 == 7 | var003 == 6 ~ 1, var003 >= 0 & var003 <= 5 ~ 0, 
                                TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(West = case_when(province == 9 | province == 8 | 
                                province == 7 | province == 6 ~ 1, province >= 0 & province <= 5 ~ 0, 
                                TRUE ~ NA_real_))

CES93 <- CES93 %>% 
  mutate(West = case_when(CPSPROV >= 6 | PESPROV >= 6 | MBSPROV >= 6 | REFPROV >= 6 | PRPROV >= 6 ~ 1,
                          TRUE ~ 0))

CES84 <- CES84 %>% 
  mutate(Quebec = case_when(var003 == 4 ~ 1, var003 != 4 ~ 0, 
                                TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(Quebec = case_when(province == 4 ~ 1, province != 4 ~ 0, 
                                TRUE ~ NA_real_))

CES93 <- CES93 %>% 
  mutate(Quebec = case_when(CPSPROV == 4 | PESPROV == 4 | MBSPROV == 4 | REFPROV == 4 | PRPROV == 4 ~ 1,
                            TRUE ~ 0))

CES84 <- CES84 %>% 
  mutate(egoret = case_when(var026 == 1 ~ 1, var026 == 2 | var026 == 8 ~ 0, var026 == 3 ~ -1,
                                TRUE ~ NA_real_))

CES88 <- CES88 %>% 
  mutate(egoret = case_when(c1 == 1 ~ 1, c1 == 3 | c1 == 8 ~ 0, c1 == 5 ~ -1,
                                TRUE ~ NA_real_))

CES93 <- CES93 %>% 
  mutate(egoret = case_when(PRF1 == 1 | CPSC1 == 1 ~ 1, PRF1 == 5 | CPSC1 == 5 | PRF1 == 8 | CPSC1 == 8 ~ 0, PRF1 == 3 | CPSC1 == 3 ~ -1))

CES84 <- CES84 %>% 
  mutate(conpid = case_when(var081 == 2 & var082 <= 2 ~ 1,
                         var081 != 2 & var081 != 8 &
                         var081 != 9 & var081 != 10 &
                         var082 != 12 & var082 <= 2 ~ -1,
                        (var082 != 1 & var082 != 2) | 
                        (var085 >= 1 & var085 <= 8) ~ 0))

CES84 <- CES84 %>% 
  mutate(libpid = case_when(var081 == 1 & var082 <= 2 ~ 1,
                         var081 != 1 & var081 != 8 &
                         var081 != 9 & var081 != 10 &
                         var082 != 12 & var082 <= 2 ~ -1,
                        (var082 != 1 & var082 != 2) | 
                        (var085 >= 1 & var085 <= 8) ~ 0))

CES84 <- CES84 %>% 
  mutate(ndppid = case_when(var081 == 3 & var082 <= 2 ~ 1,
                         var081 != 3 & var081 != 8 &
                         var081 != 9 & var081 != 10 &
                         var082 != 12 & var082 <= 2 ~ -1,
                        (var082 != 1 & var082 != 2) | 
                        (var085 >= 1 & var085 <= 8) ~ 0))

CES88 <- CES88 %>% 
  mutate(conpid = case_when(i1 == 2 & i2 <= 3 ~ 1,
                         i1 != 2 & i2 <= 3 ~ -1,
                         i2 == 5 | i2 == 8 | i3 <= 8 ~ 0))

CES88 <- CES88 %>% 
  mutate(libpid = case_when(i1 == 1 & i2 <= 3 ~ 1,
                         i1 != 1 & i2 <= 3 ~ -1,
                         i2 == 5 | i2 == 8 | i3 <= 8 ~ 0))

CES88 <- CES88 %>% 
  mutate(ndppid = case_when(i1 == 3 & i2 <= 3 ~ 1,
                         i1 != 3 & i2 <= 3 ~ -1,
                         i2 == 5 | i2 == 8 | i3 <= 8 ~ 0))

CES93 <- CES93 %>% 
  mutate(conpid = case_when((CPSM1 == 2 & CPSM2 <= 3) |
                         (PESL1 == 2 & PESL2 <= 3) ~ 1,
                         (CPSM1 != 2 & CPSM2 <= 3) |
                         (PESL1 != 2 & PESL2 <= 3) ~ -1,
                          CPSM2 == 5 | CPSM2 == 8 |
                          PESL2 == 5 | PESL2 == 8 |
                          CPSM3 <= 8 | PESL3 <= 8 ~ 0))

CES93 <- CES93 %>% 
  mutate(libpid = case_when((CPSM1 == 1 & CPSM2 <= 3) |
                         (PESL1 == 1 & PESL2 <= 3) ~ 1,
                         (CPSM1 != 1 & CPSM2 <= 3) |
                         (PESL1 != 1 & PESL2 <= 3) ~ -1,
                          CPSM2 == 5 | CPSM2 == 8 |
                          PESL2 == 5 | PESL2 == 8 |
                          CPSM3 <= 8 | PESL3 <= 8 ~ 0))

CES93 <- CES93 %>% 
  mutate(ndppid = case_when((CPSM1 == 3 & CPSM2 <= 3) |
                         (PESL1 == 3 & PESL2 <= 3) ~ 1,
                         (CPSM1 != 3 & CPSM2 <= 3) |
                         (PESL1 != 3 & PESL2 <= 3) ~ -1,
                          CPSM2 == 5 | CPSM2 == 8 |
                          PESL2 == 5 | PESL2 == 8 |
                          CPSM3 <= 8 | PESL3 <= 8 ~ 0))

CES93 <- CES93 %>% 
  mutate(refpid = case_when((CPSM1 == 4 & CPSM2 <= 3) |
                         (PESL1 == 4 & PESL2 <= 3) ~ 1,
                         (CPSM1 != 4 & CPSM2 <= 3) |
                         (PESL1 != 4 & PESL2 <= 3) ~ -1,
                          CPSM2 == 5 | CPSM2 == 8 |
                          PESL2 == 5 | PESL2 == 8 |
                          CPSM3 <= 8 | PESL3 <= 8 ~ 0))

CES93 <- CES93 %>% 
  mutate(bqpid = case_when((CPSM1 == 5 & CPSM2 <= 3) |
                         (PESL1 == 5 & PESL2 <= 3) ~ 1,
                         (CPSM1 != 5 & CPSM2 <= 3) |
                         (PESL1 != 5 & PESL2 <= 3) ~ -1,
                          CPSM2 == 5 | CPSM2 == 8 |
                          PESL2 == 5 | PESL2 == 8 |
                          CPSM3 <= 8 | PESL3 <= 8 ~ 0))

##Part B.3 Recreating Figure 1##

#recreating figure 1 article 3 by using weighted means of trust indexs
mean84 <- round(weighted.mean(CES84$trustindex84, CES84$wtfactor, na.rm = TRUE), digits = 2)
mean88 <- round(weighted.mean(CES88$trustindex88, CES88$wt5, na.rm = TRUE), digits = 2)
mean93 <- round(weighted.mean(CES93$trustindex93, CES93$CPSNWGT2, na.rm = TRUE), digits = 2)

#creating new data frame with mean values
Figure1 <- c(mean84, mean88, mean93)
Figure1 <- as.data.frame(Figure1)
Figure1$year <- c(1984, 1988, 1993)


#graphing figure 1
ggplot(Figure1, aes(x = as.factor(year), y = Figure1, group = 1)) +
  geom_point()+
  geom_hline(yintercept = 0) +
  scale_y_continuous(limits = c(-1, 0.25), breaks = seq(-1, 0.25, by = 0.25)) +
  stat_summary(fun.y = sum, geom = "line") + 
  theme_bw() +
  theme(legend.title = element_blank()) +
  labs(x= "Election", y = "Mean (Trust Index)",
       title = "Institutional Trust by Election Year")
## Warning: The `fun.y` argument of `stat_summary()` is deprecated as of ggplot2 3.3.0.
## ℹ Please use the `fun` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

##Part B.3 Recreating Table 2##

#recreating table 2 from Article 3, starting with regressions for each CES
trustmodel84 <- lm(trustindex84 ~ age + Male + School + Income + Catholic + Atlantic + West + Quebec + egoret + libpid + conpid + ndppid, data = CES84)

trustmodel88 <- lm(trustindex88 ~ age + Male + School + Income + Catholic + Atlantic + West + Quebec + egoret + libpid + conpid + ndppid, data = CES88)

trustmodel93 <- lm(trustindex93 ~ age + Male + School + Income + Catholic + Atlantic + West + Quebec + egoret + libpid + conpid + ndppid + refpid + bqpid, data = CES93)

#building a model summary with the previous regressions

trustmodel <- list(
  "1984 Election" = trustmodel84,
  "1988 Election" = trustmodel88,
  "1993 Election" = trustmodel93)

modelsummary(trustmodel,
             fmt = 2,
             stars = TRUE,
             statistic = "std.error",
             coef_map = c("age" = "Age",
                          "Male" = "Male",
                          "School" = "School",
                          "Income" = "Income",
                          "Catholic" = "Catholic",
                          "Atlantic" = "Altantic",
                          "Quebec" = "Quebec",
                          "West" = "West",
                          "egoret" = "Economy",
                          "conpid" = "Conservative",
                          "libpid" = "Liberal",
                          "ndppid" = "NDP",
                          "refpid" = "Reform",
                          "bqpid" = "Bloc Quebecois",
                          "(Intercept)" = "Constant"),
             gof_map = c("nobs", "adj.r.squared"),
             title = "Table 2. Some correlates of politcal trust",
             output = "huxtable")
Table 2. Some correlates of politcal trust
1984 Election1988 Election1993 Election
Age0.18**0.090.10*
(0.07)(0.06)(0.05)
Male0.04+0.040.04*
(0.02)(0.02)(0.02)
School0.17*0.160.28***
(0.06)(0.38)(0.06)
Income0.10*-0.040.06
(0.05)(0.05)(0.04)
Catholic0.020.020.01
(0.03)(0.03)(0.02)
Altantic0.09*-0.020.07*
(0.04)(0.04)(0.04)
Quebec0.13***0.10**0.07*
(0.04)(0.04)(0.03)
West-0.02-0.010.00
(0.03)(0.03)(0.03)
Economy0.10***0.06***0.05***
(0.02)(0.02)(0.01)
Conservative0.010.000.05***
(0.02)(0.03)(0.01)
Liberal0.02-0.05+0.04**
(0.02)(0.03)(0.01)
NDP-0.05**-0.11***0.03*
(0.02)(0.03)(0.02)
Reform-0.07***
(0.02)
Bloc Quebecois-0.06***
(0.02)
Constant-0.31***-0.59***-0.86***
(0.06)(0.05)(0.05)
Num.Obs.221416091816
R2 Adj.0.0460.0380.067
+ p < 0.1, * p < 0.05, ** p < 0.01, *** p < 0.001

Some of the coefficients and statistical significance are quite far off in this model. The N’s are quite far off in model 1 and 3, but the R squared similar in all three models. The largest difference is finding statistical significance for Liberal and Conservatives in models 1 and 2, considering they are some of the central findings. This is likely how I coded partisanship, considering it was quite confusing based on the appendix info. Additionally the multiple waves and panels further complicated things. I would guess that is where my issues arrived.