Last active
October 3, 2025 05:27
-
-
Save acbass49/12c4efedb7f5fc8ea584056fce2927da to your computer and use it in GitHub Desktop.
19 Mormon Onlineness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(tidyverse) | |
| library(binom) | |
| library(haven) | |
| library(car) | |
| library(ggtext) | |
| library(sjlabelled) | |
| library(clipr) | |
| # Load PRLS | |
| typology_data <- read.csv("./data/rls/mormon_typology.csv") | |
| pew_data <- haven::read_sav("./data/rls/rls2024.sav") | |
| pew_data$respondent_id <- paste0("2024X", pew_data$P_SUID) | |
| # Merge typology data with pew data | |
| pew_data <- pew_data |> | |
| left_join(typology_data, by = "respondent_id") | |
| pew_data |> | |
| filter(!INTFREQ %in% 99) |> | |
| filter(!RELTRAD %in% 900000) |> | |
| mutate( | |
| INTFREQ = ifelse(INTFREQ %in% 3:6, 3, INTFREQ), | |
| RELTRAD = as_character(RELTRAD)) |> | |
| group_by(RELTRAD) |> | |
| count(INTFREQ, wt = WEIGHT) |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| select(RELTRAD, INTFREQ, prop) |> | |
| pivot_wider(names_from = INTFREQ, values_from = c(prop)) |> | |
| arrange(desc(`1`)) |> | |
| clipr::write_clip() | |
| pew_data |> | |
| drop_na(mormon_typology) |> | |
| group_by(mormon_typology) |> | |
| filter(!INTFREQ %in% 99) |> | |
| count(INTFREQ, wt = WEIGHT) |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| select(mormon_typology, INTFREQ, prop) |> | |
| pivot_wider(names_from = INTFREQ, values_from = c(prop)) |> | |
| clipr::write_clip() | |
| # Load the dataset | |
| data <- haven::read_dta('./data/CES/data/2024.dta', encoding = 'UTF-8') | |
| data$relig_church_rc <- car::recode(as.numeric(data$pew_churatd),"1:2 = 'Weekly or More'; 3 = 'Monthly'; 4:5 = 'A few times a year/Seldom'; 6 = 'Never'") | |
| data$relig_church_rc <- factor(data$relig_church_rc, | |
| levels = c("Weekly or More", "Monthly", "A few times a year/Seldom", "Never")) | |
| data$relig_church_rc2 <- car::recode(as.numeric(data$pew_churatd),"1:2 = 'Weekly or More'; 3:4 = 'Monthly/A few times a year'; 5:6 = 'Seldom/Never'") | |
| data$relig_church_rc2 <- factor(data$relig_church_rc2, | |
| levels = c("Weekly or More", "Monthly/A few times a year", "Seldom/Never")) | |
| data$prayer <- data$pew_prayer | |
| data <- data |> | |
| mutate( | |
| prayer_rc = case_when( | |
| prayer == 1 ~ "Several Times a Day", | |
| prayer %in% 2:7 ~ "Less Than Several Times a Day", | |
| TRUE ~ NA_character_ | |
| ), | |
| prayer_rc2 = case_when( | |
| prayer %in% 1:2 ~ "Daily or More", | |
| prayer %in% 3:7 ~ "Less Than Several Times a Day", | |
| TRUE ~ NA_character_ | |
| ) | |
| ) | |
| # abortion was not in the cumulative file, so I need to merge it in | |
| # I went through each year and added the abortion variable manually. | |
| mormon_data <- data |> filter(data$religpew == 3) | |
| mormon_data$relig_imp <- mormon_data$pew_religimp | |
| mormon_data$devout <- dplyr::case_when( | |
| mormon_data$prayer_rc == "Several Times a Day" & | |
| mormon_data$relig_imp == 1 & | |
| mormon_data$relig_church_rc == "Weekly or More" ~ 1, | |
| TRUE ~ 0 | |
| ) | |
| mormon_data |> | |
| group_by(devout) |> | |
| count(newsint, wt = commonweight) |> | |
| drop_na() |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| select(devout, newsint, prop) |> | |
| pivot_wider(names_from = newsint, values_from = c(prop)) |> | |
| write_clip() | |
| mormon_data |> | |
| group_by(devout) |> | |
| count(CC24_300d_1, wt = commonweight) |> | |
| drop_na() |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| filter(CC24_300d_1 == 1) |> | |
| print(n=50) | |
| mormon_data |> | |
| group_by(devout) |> | |
| count(CC24_300d_2, wt = commonweight) |> | |
| drop_na() |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| filter(CC24_300d_2 == 1) |> | |
| print(n=50) | |
| mormon_data |> | |
| group_by(devout) |> | |
| count(CC24_300d_3, wt = commonweight) |> | |
| drop_na() |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| filter(CC24_300d_3 == 1) |> | |
| print(n=50) | |
| mormon_data |> | |
| group_by(devout) |> | |
| count(CC24_300d_5, wt = commonweight) |> | |
| drop_na() |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| filter(CC24_300d_5 == 1) |> | |
| print(n=50) | |
| mormon_data |> | |
| group_by(devout) |> | |
| count(CC24_300d_6, wt = commonweight) |> | |
| drop_na() |> | |
| mutate( | |
| prop = n / sum(n), | |
| total_n = sum(n), | |
| lower = binom.confint(x = n, n = total_n, method = "asymptotic")$lower, | |
| upper = binom.confint(x = n, n = total_n, method = "asymptotic")$upper | |
| ) |> | |
| filter(CC24_300d_6 == 1) |> | |
| print(n=50) | |
| # https://gist.github.com/acbass49/12c4efedb7f5fc8ea584056fce2927da |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment