Homework 5 (2.5%) due Oct. 16

Important: Must post link to your markdown on the discussion board (file and “knit” html), along with post detailing your general takeaways from exploring variables of interest, comparing to other countries, and looking into socio-demographics. You must also attach your R markdown file.

In your post, please link to the ESS website for the three variables you considered, as well as highlight the country you wish to focus on and for what main reason. Finally, please attach (or provide a screenshot) the visual that you produced while doing the tasks that is most interesting to you and explain why (just one visual not all).

lapply(packages, library, character.only = TRUE)-

ess <- read_fst(“All-ESS-Data.fst”)

table(ess$essround)

ess\(year <- NA replacements <- c(2002, 2004, 2006, 2008, 2010, 2012, 2014, 2016, 2018, 2020) for(i in 1:10){ ess\)year[ess$essround == i] <- replacements[i] }

Task 1

Do a data summary table of three variables of interest. Discuss briefly what you note (i.e., add text in your markdown after the Task 1 code).

france_data <- ess %>% filter(cntry == “FR”) %>% mutate( pplcure = ifelse(pplcure %in% c(7, 8, 9), NA, pplcure), imwbcrm = ifelse(imwbcrm %in% c(77, 88, 99), NA, imwbcrm), lwdscwp = ifelse(lwdscwp %in% c(77, 88, 99), NA, lwdscwp), )

table(france_data$pplcure)

table(france_data$imwbcrm)

table(france_data$lwdscwp)

datasummary_skim(france_data %>% select(pplcure, imwbcrm, lwdscwp))

This summary table indicates that people living in France agree they can cure themselves from the common cold, that immigrants make crime rates better and laws prohibiting racial discrimination in the workplace are beneficial for the country.

Task 2

Choose one of the three variables you just summarized in the table. This will be your current main outcome of interest.

Produce a visual that showcases the mean (average) for your outcome of interest by survey year (can be, e.g., point + line plot or ridge plot, depending on your variable). Discuss briefly what you note (i.e., add text in your markdown after the Task 2 code).

immigrant_crime <- france_data %>% group_by(year) %>% summarize(mean_stfdem = mean(stfdem, na.rm = TRUE)) immigrant_crime

ggplot(imwbcrm, aes(x = year, y = mean_stfdem)) + geom_line(color = “green”, size = 1) + # Line to show the trend geom_point(color = “red”, size = 3) + # Points to highlight each year’s value labs(title = “Immigrants Make Crime Rates Better (2002-2020)”, x = “Survey Year”, y = “Agreement (0-10)”) + ylim(0, 10) + # Setting the y-axis limits from 0 to 10 theme_minimal()

Task 3

Provide a comparison visual of your outcome of interest with two other countries. You can choose the geom() you prefer. Discuss briefly what you note (i.e., add text in your markdown after the Task 3 code).

ess_selected <- ess %>% filter(cntry %in% c(“FR”, “DE”, “RU”)) %>% mutate(stfdem = ifelse(stfdem %in% c(77, 88, 99), NA, stfdem))

task3plot <- ggplot(ess_selected, aes(x = reorder(cntry, -stfdem, FUN=median), y = stfdem, fill = cntry)) + geom_boxplot() + theme_minimal() + theme(legend.position = “none”) + labs(title = “Comparison For Immigrants Making Crime Rates Better (France, Germany, Russia)”, x = “Country”, y = “Scale (0-10)”)

task3plot

The population of Germany have the highest rate of people who believe immigrants make crime rates better, followed by France, and then Russia.

Task 4

Produce a cross-tab between your outcome of interest and a socio-demographic variable (use datasummary_crosstab). Then, calculate column percentages using cprop(), making sure to pick a second socio-demographic variable. Discuss briefly what you note (i.e., add text in your markdown after the Task 4 code).

france_data <- france_data %>% mutate(born_in_country = recode(brncntr, 1 = “Yes”, 2 = “No”, 7 = NA_character_, 8 = NA_character_, 9 = NA_character_))

table(france_data$born_in_country)

table(france_data$brncntr)

imwbcrm <- datasummary_crosstab(imwbcrm ~ born_in_country, data = france_data)

imwbcrm

table(france_data\(imwbcrm, france_data\)brncntr) %>% cprop()

Task 5

Choose one of the two socio-demographic variables you just worked with. Visualize the conditional probability (or column percentages) of your outcome given your selected socio-dem variable. Discuss briefly what you note (i.e., add text in your markdown after the Task 5 code).

df <- france_data %>% filter(!is.na(brncntr) & !is.na(imwbcrm))

table(df$brncntr)

table(df\(imwbcrm, df\)brncntr) %>% cprop() %>% as.data.frame() %>% filter(Var1 != “Total”, Var2 != “All”) %>% ggplot(aes(x=Var1, y=Freq, fill=Var2)) + geom_col(position = “dodge”) + labs(title= “Do Immigrants Make Crime Rates Better? in France”, y = “Conditional Percentage”, x = “Agreement With Statement (0 = Disagree) (10 = Agree)”, fill = “Born In The Country Vs. Not”)