Chapter 19 Issue: Ban on begging

if(!require("broom")){install.packages("broom");  library(broom)}
if(!require("haven")){install.packages("haven");  library(haven)}
if(!require("here")){install.packages("here");  library(here)}
if(!require("knitr")){install.packages("knitr");  library(knitr)}
if(!require("kableExtra")){install.packages("kableExtra");  library(kableExtra)}
if(!require("naniar")){install.packages("naniar");  library(naniar)}
if(!require("tidyverse")){install.packages("tidyverse");  library(tidyverse)}

set.seed(2016)

d <- read_sav("C:\\Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/Data/Goodloser-exp3.sav")

knitr::opts_chunk$set(echo = TRUE, knitr.kable.NA = "", cache = FALSE, warning = FALSE)

19.1 Main effects

19.1.1 Prepare data

main_01 <- d %>% 
  mutate(rsp_id = as.numeric(responseid),
         rsp_beg = case_when(r13pad1 == 1 ~ "In favour of ban on begging",
                             r13pad1 == 2 ~ "Against ban on begging"),
         rsp_beg_imp = case_when(r13pad2 %in% 1:2 ~ "Important",
                                  r13pad2 %in% 3:5 ~ "Not important"),
         rsp_toll = case_when(r13pad3 == 1 ~ "In favour of road toll increase of diesel cars",
                              r13pad3 == 2 ~ "Against road toll increase of diesel cars"),
         rsp_toll_imp = case_when(r13pad4 %in% 1:2 ~ "Important",
                                  r13pad4 %in% 3:5 ~ "Not important"),
         treat_issue = case_when(r13pad5_sak == 1 ~ "Ban on begging",
                               r13pad5_sak == 2 ~ "Road toll increase of diesel cars"),
         treat_outcome = case_when(r13pad5_utfall == 1 ~ "The Yes side won the vote",
                                 r13pad5_utfall == 2 ~ "The No side won the vote"),
          treat_outfav = case_when(r13pad5_sak == 1 & r13pad1 == 1 & r13pad5_utfall == 1 ~ "Favorable outcome",
                                  r13pad5_sak == 1 & r13pad1 == 2 & r13pad5_utfall == 2 ~ "Favorable outcome",
                                  r13pad5_sak == 1 & r13pad1 == 1 & r13pad5_utfall == 2 ~ "Unfavorable outcome",
                                  r13pad5_sak == 1 & r13pad1 == 2 & r13pad5_utfall == 1 ~ "Unfavorable outcome",
                                  r13pad5_sak == 2 & r13pad3 == 1 & r13pad5_utfall == 1 ~ "Favorable outcome",
                                  r13pad5_sak == 2 & r13pad3 == 2 & r13pad5_utfall == 2 ~ "Favorable outcome",
                                  r13pad5_sak == 2 & r13pad3 == 1 & r13pad5_utfall == 2 ~ "Unfavorable outcome",
                                  r13pad5_sak == 2 & r13pad3 == 2 & r13pad5_utfall == 1 ~ "Unfavorable outcome"),
         treat_winningmargin = case_when(r13pad5_vinnermargin == 1 ~ "Not shown",
                                       r13pad5_vinnermargin == 2 ~ "Slight majority",
                                       r13pad5_vinnermargin == 3 ~ "Large majority"),
         treat_winnergloat = case_when(r13pad5_vinner == 1 ~ "Not shown",
                                     r13pad5_vinner == 2 ~ "Winning politician gloats"),
        treat_prime = case_when(r13pad5_avsender == 1 ~ "Not shown",
                               r13pad5_avsender == 2  | r13pad5_avsender == 5 ~ "No prime",
                               r13pad5_avsender == 3  | r13pad5_avsender == 6 ~ "Specific prime",
                               r13pad5_avsender == 4 | r13pad5_avsender == 7 ~ "General prime"),
         treat_messenger = case_when(r13pad5_avsender %in% 3:4 ~ "Political leader",
                                   r13pad5_avsender %in% 6:7 ~ "Local newspaper"),
         post_fair = case_when(r13pad6a == 1 | r13pad6b == 1 ~ 5,
                          r13pad6a == 2 | r13pad6b == 2 ~ 4,
                          r13pad6a == 3 | r13pad6b == 3 ~ 3,
                          r13pad6a == 4 | r13pad6b == 4 ~ 2,
                          r13pad6a == 5 | r13pad6b == 5 ~ 1),
          post_reasonable = case_when(r13pad7a == 1 | r13pad7b == 1 ~ 5,
                          r13pad7a == 2 | r13pad7b == 2 ~ 4,
                          r13pad7a == 3 | r13pad7b == 3 ~ 3,
                          r13pad7a == 4 | r13pad7b == 4 ~ 2,
                          r13pad7a == 5 | r13pad7b == 5 ~ 1),
          post_accept = case_when(r13pad8a == 1 | r13pad8b == 1 ~ 5,
                          r13pad8a == 2 | r13pad8b == 2 ~ 4,
                          r13pad8a == 3 | r13pad8b == 3 ~ 3,
                          r13pad8a == 4 | r13pad8b == 4 ~ 2,
                          r13pad8a == 5 | r13pad8b == 5 ~ 1)

  ) %>% 

  replace_with_na_all(condition = ~.x == 98 )%>%  #Recode 98 (not asked) as missing
  filter(!is.na(r13pad6_ran)) %>%  #Remove NA's
## We want the value labels in particular order for the tables and figures.
        mutate(treat_winningmargin = lvls_reorder(treat_winningmargin, c(2, 3, 1)), 
               treat_prime = lvls_reorder(treat_prime, c(3, 2, 4, 1)) 
        )
main_01 <- main_01 %>%   
      filter(treat_issue == "Ban on begging")

19.1.2 Reasonable decision

source("Functions/amce.R")

res_main <-  main_01 %>%
  amce(post_reasonable, treat_outfav, treat_winningmargin, treat_winnergloat, treat_prime, treat_messenger) 
  
res_main <- res_main %>% 
  mutate(
  treatment =  case_when(treatment == "treat_outfav" ~ "Outcome\nfavor-\nability",
            treatment == "treat_winningmargin" ~ "Winning\nmargin",
            treatment == "treat_winnergloat" ~ "Winner\ngloats",
            treatment == "treat_prime" ~ "Democratic\nprime",
            treatment == "treat_messenger" ~ "Primer")
)

#Figure
fig_amce <-
  res_main %>%
  ggplot(aes(x = estimate, y = value)) +
  facet_grid(
    treatment ~ .,
    scales = "free_y",
    space = "free_y") +
  geom_errorbarh(
    aes(xmin = estimate - (2 * std_error),
        xmax = estimate + (2 * std_error)),
    height = 0) +
  geom_point() +
  geom_vline(aes(xintercept = 0), linetype = "dotted") +
  scale_x_continuous(
    limits = c(-1, 1),
    breaks = round(seq(-1, 1, .1), 2),
    expand = c(0, 0)) +
   labs(
    x = "Marginal effect, reasonable decision",
    y = "Decision process attributes") +
  theme_bw() +
  theme(plot.margin = unit(c(2, 2, 2, 2), "mm")) +
  theme(panel.spacing = unit(0.5, "lines"))
fig_amce

ggsave(
  here("output", "figs", "pngs", "fig_begging_reasonable.png"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::png(..., res = dpi, units = "in"): unable to start png() device
ggsave(
  here("output", "figs", "pdfs", "fig_begging_reasonable.pdf"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::pdf(file = filename, ..., version = version): cannot open file 'C:/Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/output/figs/pdfs/fig_begging_reasonable.pdf'
#Table
res_main <- res_main %>% 
  select(value, estimate, std_error, statistic, p_value)

kable(res_main, booktabs = TRUE, caption = "Average Marginal Component Effects", col.names = linebreak(c("Treatment value", "Estimate", "Std. Error", "t-statistic", "p value"))) %>% 
  kable_styling(bootstrap_options = c("striped", "hover", "responsive")) %>% 
 group_rows(index = c("Outcome favorability" = 2, "Winning margin" = 3, "Winner gloating" = 2, "Good loser prime" = 4, "Primer" = 2))
(#tab:308_begging_post_reasonable)Average Marginal Component Effects
Treatment value Estimate Std. Error t-statistic p value
Outcome favorability
Favorable outcome 0.0000000 0.0000000 NA NA
Unfavorable outcome -0.6950006 0.0545962 -12.7298292 0.0000000
Winning margin
Not shown 0.0000000 0.0000000 NA NA
Slight majority 0.0047645 0.0707352 0.0673563 0.9463079
Large majority 0.0986145 0.0690618 1.4279168 0.1535437
Winner gloating
Not shown 0.0000000 0.0000000 NA NA
Winning politician gloats 0.0502226 0.0573953 0.8750304 0.3817106
Good loser prime
Not shown 0.0000000 0.0000000 NA NA
No prime 0.1665841 0.0979535 1.7006451 0.0892368
Specific prime 0.0934601 0.0976342 0.9572479 0.3386112
General prime 0.1741029 0.0979535 1.7774039 0.0757238
Primer
Local newspaper 0.0000000 0.0000000 NA NA
Political leader 0.0185887 0.0747615 0.2486398 0.8037028

19.1.3 Willingnes to accept

source("Functions/amce.R")

res_main <-  main_01 %>%
  amce(post_accept, treat_outfav, treat_winningmargin, treat_winnergloat, treat_prime, treat_messenger) 
  
res_main <- res_main %>% 
  mutate(
  treatment =  case_when(treatment == "treat_outfav" ~ "Outcome\nfavor-\nability",
            treatment == "treat_winningmargin" ~ "Winning\nmargin",
            treatment == "treat_winnergloat" ~ "Winner\ngloats",
            treatment == "treat_prime" ~ "Democratic\nprime",
            treatment == "treat_messenger" ~ "Primer")
)

#Figure
fig_amce <-
  res_main %>%
  ggplot(aes(x = estimate, y = value)) +
  facet_grid(
    treatment ~ .,
    scales = "free_y",
    space = "free_y") +
  geom_errorbarh(
    aes(xmin = estimate - (2 * std_error),
        xmax = estimate + (2 * std_error)),
    height = 0) +
  geom_point() +
  geom_vline(aes(xintercept = 0), linetype = "dotted") +
  scale_x_continuous(
    limits = c(-1, 1),
    breaks = round(seq(-1, 1, .1), 2),
    expand = c(0, 0)) +
   labs(
    x = "Marginal effect, willingnes to accept decision",
    y = "Decision process attributes") +
  theme_bw() +
  theme(plot.margin = unit(c(2, 2, 2, 2), "mm"))
fig_amce

ggsave(
  here("output", "figs", "pngs", "fig_begging_accept.png"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::png(..., res = dpi, units = "in"): unable to start png() device
ggsave(
  here("output", "figs", "pdfs", "fig_begging_accept.pdf"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::pdf(file = filename, ..., version = version): cannot open file 'C:/Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/output/figs/pdfs/fig_begging_accept.pdf'
#table
res_main <- res_main %>% 
  select(value, estimate, std_error, statistic, p_value)


kable(res_main, booktabs = TRUE, caption = "Average Marginal Component Effects", col.names = linebreak(c("Treatment value", "Estimate", "Std. Error", "t-statistic", "p value"))) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "responsive")) %>% 
 group_rows(index = c("Outcome favorability" = 2, "Winning margin" = 3, "Winner gloating" = 2, "Good loser prime" = 4, "Primer" = 2))
(#tab:308_begging_post_accept)Average Marginal Component Effects
Treatment value Estimate Std. Error t-statistic p value
Outcome favorability
Favorable outcome 0.0000000 0.0000000 NA NA
Unfavorable outcome -0.5607543 0.0505138 -11.1010139 0.0000000
Winning margin
Not shown 0.0000000 0.0000000 NA NA
Slight majority -0.0575432 0.0644710 -0.8925433 0.3722581
Large majority 0.0303792 0.0629807 0.4823569 0.6296292
Winner gloating
Not shown 0.0000000 0.0000000 NA NA
Winning politician gloats 0.0886157 0.0522929 1.6946036 0.0903771
Good loser prime
Not shown 0.0000000 0.0000000 NA NA
No prime 0.0513835 0.0894853 0.5742116 0.5659187
Specific prime -0.0029428 0.0892277 -0.0329805 0.9736950
General prime 0.0364521 0.0895182 0.4072031 0.6839223
Primer
Local newspaper 0.0000000 0.0000000 NA NA
Political leader 0.0153846 0.0681877 0.2256214 0.8215530

19.1.4 Fairness perceptions

source("Functions/amce.R")

res_main <-  main_01 %>%
  amce(post_fair, treat_outfav, treat_winningmargin, treat_winnergloat, treat_prime, treat_messenger)
  
res_main <- res_main %>% 
  mutate(
  treatment =  case_when(treatment == "treat_outfav" ~ "Outcome\nfavor-\nability",
            treatment == "treat_winningmargin" ~ "Winning\nmargin",
            treatment == "treat_winnergloat" ~ "Winner\ngloats",
            treatment == "treat_prime" ~ "Democratic\nprime",
            treatment == "treat_messenger" ~ "Primer")
)

#Figure
fig_amce <-
  res_main %>%
  ggplot(aes(x = estimate, y = value)) +
  facet_grid(
    treatment ~ .,
    scales = "free_y",
    space = "free_y") +
  geom_errorbarh(
    aes(xmin = estimate - (2 * std_error),
        xmax = estimate + (2 * std_error)),
    height = 0) +
  geom_point() +
  geom_vline(aes(xintercept = 0), linetype = "dotted") +
  scale_x_continuous(
    limits = c(-1, 1),
    breaks = round(seq(-1, 1, .1), 2),
    expand = c(0, 0)) +
   labs(
    x = "Marginal effect, perceived fairness of decision",
    y = "Decision process attributes") +
  theme_bw() +
  theme(plot.margin = unit(c(2, 2, 2, 2), "mm"))
fig_amce

ggsave(
  here("output", "figs", "pngs", "fig_begging_fair.png"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::png(..., res = dpi, units = "in"): unable to start png() device
ggsave(
  here("output", "figs", "pdfs", "fig_begging_fair.pdf"),
  plot = fig_amce,
  width = 5.5, height = 2.75
)
## Error in grDevices::pdf(file = filename, ..., version = version): cannot open file 'C:/Users/Sveinung/OneDrive/NORCE 2018-/goodloser/Conjoint/Bookdown-goodloser/output/figs/pdfs/fig_begging_fair.pdf'
#table
res_main <- res_main %>% 
  select(value, estimate, std_error, statistic, p_value)


kable(res_main, booktabs = TRUE, caption = "Average Marginal Component Effects", col.names = linebreak(c("Treatment value", "Estimate", "Std. Error", "t-statistic", "p value"))) %>%
  kable_styling(bootstrap_options = c("striped", "hover", "responsive")) %>% 
 group_rows(index = c("Outcome favorability" = 2, "Winning margin" = 3, "Winner gloating" = 2, "Good loser prime" = 4, "Primer" = 2))
(#tab:308_begging_post_fair)Average Marginal Component Effects
Treatment value Estimate Std. Error t-statistic p value
Outcome favorability
Favorable outcome 0.0000000 0.0000000 NA NA
Unfavorable outcome -0.1505083 0.0467927 -3.2164911 0.0013283
Winning margin
Not shown 0.0000000 0.0000000 NA NA
Slight majority -0.0360970 0.0577627 -0.6249189 0.5321280
Large majority 0.0329985 0.0563966 0.5851153 0.5585662
Winner gloating
Not shown 0.0000000 0.0000000 NA NA
Winning politician gloats -0.0191828 0.0468725 -0.4092549 0.6824163
Good loser prime
Not shown 0.0000000 0.0000000 NA NA
No prime 0.2067358 0.0799312 2.5864201 0.0097999
Specific prime 0.1654301 0.0797020 2.0756070 0.0381160
General prime 0.2026023 0.0800194 2.5319152 0.0114548
Primer
Local newspaper 0.0000000 0.0000000 NA NA
Political leader 0.0715650 0.0615763 1.1622162 0.2454912