Skip to content

Instantly share code, notes, and snippets.

@ryanburge
Created February 25, 2026 18:35
Show Gist options
  • Select an option

  • Save ryanburge/bc5d9e4dd1ce88067f3eb48204320182 to your computer and use it in GitHub Desktop.

Select an option

Save ryanburge/bc5d9e4dd1ce88067f3eb48204320182 to your computer and use it in GitHub Desktop.
CCES 2024 - Race and Religion
cces24 %>%
+ mutate(
+ vote = case_when(CC24_410 == 1 ~ "Democrat",
+ CC24_410 == 2 ~ "Republican",
+ CC24_410 == 4 ~ "Third Party"),
+ christian = religpew %in% 1:4,
+ white_christian = religpew %in% 1:4 & race == 1,
+ nonreligious = religpew %in% 9:11
+ ) %>%
+ filter(!is.na(vote)) %>%
+ group_by(vote) %>%
+ summarise(
+ pct_white_christian = weighted.mean(white_christian, commonweight, na.rm = TRUE),
+ pct_christian = weighted.mean(christian, commonweight, na.rm = TRUE),
+ pct_nonreligious = weighted.mean(nonreligious, commonweight, na.rm = TRUE)
+ )
# A tibble: 3 × 4
vote pct_white_christian pct_christian pct_nonreligious
<chr> <dbl> <dbl> <dbl>
1 Democrat 0.253 0.422 0.450
2 Republican 0.603 0.712 0.177
3 Third Party 0.270 0.356 0.464
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment