Load necessary libraries

library(haven) library(dplyr)

Load the dataset

ESS11_unlabeled_0_10 <- read_sav(“Desktop/ESS11_unlabeled.0-10.sav”)

Define right-wing populist parties for each country

right_wing_parties <- list( AT = c(“FPÖ”), # Example for Austria BE = c(“Vlaams Belang”), # Example for Belgium DE = c(“AfD”), # Example for Germany FR = c(“Rassemblement National”), # Example for France IT = c(“Lega”), # Example for Italy NL = c(“PVV”) # Example for Netherlands # Omitted Poland )

Create the ‘vote’ variable

ESS11_unlabeled_0_10 <- ESS11_unlabeled_0_10 %>% mutate(vote = case_when( prtvtebe %in% right_wing_parties\(BE ~ 1, # Belgium prtvtdat %in% right_wing_parties\)AT ~ 1, # Austria prtvgde1 %in% right_wing_parties\(DE ~ 1, # Germany prtvteis %in% right_wing_parties\)IT ~ 1, # Italy prtvtinl %in% right_wing_parties$NL ~ 1, # Netherlands TRUE ~ 0 # Default case ))

Selecting relevant variables for the aggregated file

aggregated_data <- ESS11_unlabeled_0_10 %>% select(name, cntry, dweight, pspwght, pweight, anweight, nwspol, netusoft, ppltrst, polintr, vote)

Saving the aggregated file

write.csv(aggregated_data, “Desktop/aggregated_ess11_data.csv”, row.names = FALSE)