By which other variables than cntry
could one join further data to the ESS? Skim through the ESS codebook and discuss two to three examples in your breakout room group.
Use the "manifestoR" package to access the party manifeto data.
mp_setapikey("manifesto_apikey.txt")
(Manif <- mp_maindataset())
rile
, which is the left-right orientation of each manifesto. You can also skim through the Codebook of the Manifesto data to get a better impression. Get an estimate of the vote-share weighted left-right orientation of the parties for each country. Use only the most recent data for each country. Make a bar chart of the info: In which country are the parties the most left oriented? # Get country level estimates
(Manif_cntry <- Manif %>% # Use the Manifesto data, then
select(countryname, edate, per607, per608, rile, pervote) %>% # Select the vars we need, then
group_by(countryname) %>% # Group the data by country, then
filter(edate == max(edate)) %>% # Use only the most recent manifestos from each country, then
dplyr::summarize( # Calculate the average, vote-share weighted, left-right orientation of all parties.
party_rile = weighted.mean(rile, w = (pervote / 100), na.rm = TRUE)
) %>%
drop_na() %>%
mutate(
countryname = fct_drop(countryname)
))
# # A tibble: 48 × 2
# countryname party_rile
# <fct> <dbl>
# 1 Albania 1.16
# 2 Armenia -4.89
# 3 Australia -11.8
# 4 Austria -11.3
# 5 Azerbaijan 11.6
# 6 Belgium -8.23
# 7 Bosnia-Herzegovina -8.95
# 8 Bulgaria 8.62
# 9 Canada -1.70
# 10 Cyprus -1.24
# # … with 38 more rows
# Plot the result
ggplot(data = Manif_cntry) +
geom_bar(mapping = aes(y = party_rile, x = reorder(countryname, party_rile)), stat = "identity") +
labs(y = "Vote-share weighted left-right orientation",
x = "Country") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
(ESS_cntry <- ESS %>% # Pipe the ESS
transmute( # Create new variables and only keep these new ones
# Make the following variables factors:
cntry = as_factor(cntry),
# Make the following variables numeric:
pspwght = zap_labels(pspwght),
hmsacld = max(zap_labels(hmsacld), na.rm = TRUE) - zap_labels(hmsacld), #<<
) %>%
group_by(cntry) %>% # Group data by country, så
dplyr::summarize(
mean_hmsacld = weighted.mean(hmsacld, weights = pspwght, na.rm = TRUE),
) %>% # Now join the country-level manifesto estimates
inner_join(. , Manif_cntry %>%
transmute(cntry = countryname,
party_rile = party_rile)))
# # A tibble: 25 × 3
# cntry mean_hmsacld party_rile
# <fct> <dbl> <dbl>
# 1 Austria 2.31 -11.3
# 2 Belgium 2.79 -8.23
# 3 Bulgaria 1.11 8.62
# 4 Cyprus 1.15 -1.24
# 5 Germany 2.67 -8.40
# 6 Denmark 2.75 -14.3
# 7 Estonia 1.40 4.03
# 8 Spain 3.07 -11.2
# 9 Finland 2.43 -19.6
# 10 France 2.60 -4.75
# # … with 15 more rows
ggplot(data = ESS_cntry, aes(y = mean_hmsacld, x = party_rile)) +
# geom_errorbar(aes(ymin = min95, ymax = max95), alpha = 0.7) +
geom_smooth() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
geom_text(mapping = aes(label = cntry)) +
labs(y = "Gay women and men should be allowed \n to adopt children (scale 1 to 5)",
x = "Vote-share weighted left-right orientation") +
theme_minimal()