#Libraries used library(haven) library(tidyverse) library(ggplot2) library(epiR) # The following lines of code constitute the operationalisation of the # working class # Removing years prior to 2002 opryear <- subset(supersomstata, year > 2001) # Removing observations where respondents do not subjectively see themselves # as working class oprclass <- subset(opryear, subclh < 2) # Removing observations where respondents are not working, unemployed # or enrolled in a labuor market program oprocc <- subset(oprclass, lmsit < 4) # Removing observations where respondents have a household income above # 500,000 SEK/year oprinc <- subset(oprocc, hinc5rel < 4) #Working class party preference oprincvoting <- subset(oprinc, cb10 < 11) oprincvote <- table(oprincvoting$cb10, oprincvoting$year) prop.table(oprincvote, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Left Party', 'Sweden Democrats', 'Social Democrats', 'Centre Party', 'Liberal Party', 'Moderate Party', 'Christian Democrats', 'Green Party'))+ labs(title="Working class: Party preference", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions cb10 prop.table(table(oprincvoting$year, oprincvoting$cb10), 1) #Subjective working class party preference subpartypreferencesubset <- subset(oprclass, cb10 < 11) subpartypreference <- table(subpartypreferencesubset$cb10, subpartypreferencesubset$year) prop.table(subpartypreference, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Left Party', 'Sweden Democrats', 'Social Democrats', 'Centre Party', 'Liberal Party', 'Moderate Party', 'Christian Democrats', 'Green Party'))+ labs(title="Subjective working class: Party preference", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions cb10 prop.table(subpartypreference, 1) #General population party preference genpartypreferencesubset <- subset(opryear, cb10 < 11) genpartypreference <- table(genpartypreferencesubset$cb10, genpartypreferencesubset$year) prop.table(genpartypreference, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Left Party', 'Sweden Democrats', 'Social Democrats', 'Centre Party', 'Liberal Party', 'Moderate Party', 'Christian Democrats', 'Green Party'))+ labs(title="General population: Party preference", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions cb10 prop.table(genpartypreference, 1) #Working class trust in government oprgovsubset <- subset(oprincvoting, aa10a < 6) oprgov <- table(oprgovsubset$aa10a, oprgovsubset$year) prop.table(oprgov, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -"Group") %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, color=Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very high trust', 'Quite high trust', 'Neither high nor low trust', 'Quite low trust', 'very low trust'))+ labs(title="Working class: Trust in government", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions aa10a prop.table(oprgov, 1) #Subjective working class trust in government subgovsubset <- subset(oprclass, aa10a < 6) subgov <- table(subgovsubset$aa10a, subgovsubset$year) prop.table(subgov, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very high trust', 'Quite high trust', 'Neither high nor low trust', 'Quite low trust', 'very low trust'))+ labs(title="Subjective working class: Trust in government", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions aa10a prop.table(table(subgovsubset$year, subgovsubset$aa10a),1) #General population trust in government gengovsubset <- subset(opryear, aa10a < 6) gengov <- table(gengovsubset$aa10a, gengovsubset$year) prop.table(gengov, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very high trust', 'Quite high trust', 'Neither high nor low trust', 'Quite low trust', 'very low trust'))+ labs(title="General population: Trust in government", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions aa10a prop.table(table(gengovsubset$year, gengovsubset$aa10a),1) oprtaxsubset <- subset(oprincvoting, dc900b < 6) oprtax <- table(oprtaxsubset$dc900b, oprtaxsubset$year) prop.table(oprtax, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="Working class: Proposal, lower taxes", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions dc900b prop.table(table(oprtaxsubset$year,oprtaxsubset$dc900b),1) oprpublicsubset <- subset(oprincvoting, ea900a < 6) oprpublic <- table(oprpublicsubset$ea900a, oprpublicsubset$year) prop.table(oprpublic, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="Working class: Proposal, reduce the public sector", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions ea900a prop.table(table(oprpublicsubset$year, oprpublicsubset$ea900a),1) #Working class attitudes increase privatisation of healthcare oprsjuksubset <- subset(oprincvoting, ed900a < 6) oprsjuk <- table(oprsjuksubset$ed900a, oprsjuksubset$year) prop.table(oprsjuk, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="Working class: Proposal, increase the privatisation of healthcare", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions ed900a prop.table(table(oprsjuksubset$year, oprsjuksubset$ed900a),1) #Working class attitudes accept fewer refugees into Sweden oprimsubset <- subset(oprincvoting, fc900b < 6) oprim <- table(oprimsubset$fc900b, oprimsubset$year) prop.table(oprim, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="Working class: Proposal, accept fewer refugees into Sweden", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions fc900b prop.table(table(oprimsubset$year, oprimsubset$fc900b),1) #Working class trust in the daily press oprmediatrustsubset <- subset(oprincvoting, aa10g< 6) oprmediatrust <- table(oprmediatrustsubset$aa10g, oprmediatrustsubset$year) prop.table(oprmediatrust, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very high trust', 'Quite high trust', 'Neither high nor low trust', 'Quite low trust', 'Very low trust'))+ labs(title="Working class: Trust in the daily press", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions aa10g prop.table(table(oprmediatrustsubset$year, oprmediatrustsubset$aa10g),1) #Subjective working class attitudes towards lowering taxes subtaxsubset <- subset(oprclass, dc900b < 6) subtax <- table(subtaxsubset$dc900b, subtaxsubset$year) prop.table(subtax, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="Subjective working class: Proposal, lower taxes", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions dc900b prop.table(table(subtaxsubset$year, subtaxsubset$dc900b),1) #Subjective working class attitudes towards reducing the public sector subpublicsubset <- subset(oprclass, ea900a < 6) subpublic <- table(subpublicsubset$ea900a, subpublicsubset$year) prop.table(subpublic, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="Subjective working class: Proposal, reduce the public sector", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions ea900a prop.table(table(subpublicsubset$year, subpublicsubset$ea900a),1) #Subjective working class attitudes towards increasing privatisation of healthcare subsjuksubset <- subset(oprclass, ed900a < 6) subsjuk <- table(subsjuksubset$ed900a, subsjuksubset$year) prop.table(subsjuk, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="Subjective working class: Proposal, increase the privatisation of healthcare", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions ed900a prop.table(table(subsjuksubset$year, subsjuksubset$ed900a),1) #Subjective working class attitudes towards accepting fewer refugees into Sweden subimsubset <- subset(oprclass, fc900b < 6) subim <- table(subimsubset$fc900b, subimsubset$year) prop.table(subim, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="Subjective working class: Proposal, accept fewer refugees into Sweden", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions fc900b prop.table(table(subimsubset$year, subimsubset$fc900b),1) #Subjective working class trust in the daily press submediatrustsubset <- subset(oprclass, aa10g < 6) submedia <- table(submediatrustsubset$aa10g, submediatrustsubset$year) prop.table(submedia, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very high trust', 'Quite high trust', 'Neither high nor low trust', 'Quite high trust', 'Very low trust'))+ labs(title="Subjective working class: Trust in the daily press", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions aa10g prop.table(table(submediatrustsubset$year, submediatrustsubset$aa10g),1) #General population attitudes towards lowering taxation gentaxsubset <- subset(opryear, dc900b < 6) gentax <- table(gentaxsubset$dc900b, gentaxsubset$year) prop.table(gentax, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="General population: Proposal, lower taxation", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions dc900b prop.table(table(gentaxsubset$year, gentaxsubset$dc900b),1) #General population attitudes towards reducing the public sector genpublicsubset <- subset(opryear, ea900a < 6) genpublic <- table(genpublicsubset$ea900a, genpublicsubset$year) prop.table(genpublic, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="General population: Proposal, reduce the public sector", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions ea900a prop.table(table(genpublicsubset$year, genpublicsubset$ea900a),1) #General population attitudes towards increasing the privatisation of healthcare gensjuksubset <- subset(opryear, ed900a < 6) gensjuk <- table(gensjuksubset$ed900a, gensjuksubset$year) prop.table(gensjuk, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="General population: Proposal, increase the privatisation of healthcare", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions ed900a prop.table(table(gensjuksubset$year, gensjuksubset$ed900a),1) #General population: Proposal accept fewer refugees into Sweden genimsubset <- subset(opryear, fc900b < 6) genim <- table(genimsubset$fc900b, genimsubset$year) prop.table(genim, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very good proposal', 'Rather good proposal', 'Neither good nor bad proposal', 'Rather bad proposal', 'Very bad proposal'))+ labs(title="General population: Proposal accept fewer refugees into Sweden", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportionsfc900b prop.table(table(genimsubset$year, genimsubset$fc900b),1) #General population: Trust in the daily press genmediatrustsubset <- subset(opryear, aa10g < 6) genmedia <- table(genmediatrustsubset$aa10g, genmediatrustsubset$year) prop.table(genmedia, 2) %>% as.data.frame.matrix() %>% rownames_to_column("Group") %>% gather(x, y, -Group) %>% mutate(x = as.Date(gsub("X", "", x), format = "%Y")) %>% ggplot(aes(x, y, colour = Group)) + geom_line(size = 0.75)+ scale_y_continuous(labels=scales::percent) + scale_color_discrete(name = 'Response alternatives', labels = c('Very high trust', 'Quite high trust', 'Neither high nor low trust', 'Quite low trust', 'Very low trust'))+ labs(title="General population: Trust in the daily press", x="Years 2002-2021", y="Share of answers (%)")+ theme_bw() # Table of proportions aa10g table(genmediatrustsubset$year, genmediatrustsubset$aa10g) # Extraction of data, operationalisation of the working class and the creation # of a binary working class variable and votes for the Sweden Democrats #variable. # Creating a binary variable in which being working class = 1 and # not being working class = 2 and a binary variable for voting for # the Sweden Democrats = 1 and not voting for the Sweden Democrats = 2 som <- supersomstata %>% select(year, subclh, lmsit, hinc5rel, cb10, fb10, ea900a, ed900a, dc900b, fc900b, aa10a, aa10g) %>% filter(year > 2001) %>% filter(subclh < 5) %>% filter(lmsit < 8) %>% filter(hinc5rel < 6) %>% filter(cb10 < 11) %>% mutate(arbetarklass = subclh < 2 & lmsit < 4 & hinc5rel < 4, arbetarklass = if_else(arbetarklass == TRUE, 1, 0)) %>% mutate(SD = cb10 > 9, SD = if_else(SD == TRUE, 1, 2)) # Checking the new data frame in order to see if the new variables # were created view(som) # Odds ratio calculation: being working class and voting for the # Sweden Democrats TAB <- table(som$arbetarklass, som$SD) TAB barplot(TAB, beside=TRUE, legend=TRUE) epi.2by2(TAB, method="cohort.count", conf.level=0.95) TAB2 <- matrix(c(1936, 10868, 8065, 76221), nrow=2, byrow=TRUE) TAB2 epi.2by2(TAB2, method="cohort.count", conf.level=0.95) #chi-squared test of independence reduce the public sector minska_offentlig_sektor <- som %>% filter(ea900a < 6) table(minska_offentlig_sektor$arbetarklass, minska_offentlig_sektor$ea900a) %>% chisq.test() #chi-squared test of independence increase privatization of healthcare öka_privatisering_av_sjukvård <- som %>% filter(ed900a < 6) table(öka_privatisering_av_sjukvård$arbetarklass, öka_privatisering_av_sjukvård$ed900a) %>% chisq.test() #chi-squared test of independence lower taxes sänk_skatterna <- som %>% filter(dc900b < 6) table(sänk_skatterna$arbetarklass, sänk_skatterna$dc900b) %>% chisq.test() #chi-squared test of independence accept fewer refugees ta_emot_färre_flyktingar <- som %>% filter(fc900b < 6) table(ta_emot_färre_flyktingar$arbetarklass, ta_emot_färre_flyktingar$fc900b) %>% chisq.test() #chi-squared test of independence trust in daily press tillit_till_dagspressen <- som %>% filter(aa10g < 6) table(tillit_till_dagspressen$arbetarklass, tillit_till_dagspressen$aa10g) %>% chisq.test() #chi-squared test of independence trust in government tillit_till_regeringen <- som %>% filter(aa10a < 6) table(tillit_till_regeringen$arbetarklass, tillit_till_regeringen$aa10a) %>% chisq.test()