Last active
February 23, 2025 05:34
-
-
Save acbass49/d419ab4f3e7551a382ed8eee85adb91f to your computer and use it in GitHub Desktop.
The BYU effect
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
| # load packages | |
| library(tidyverse) | |
| library(sjlabelled) | |
| library(clipr) | |
| data <- read.csv("./data/fire/fire.csv") | |
| labels <- read.csv("./data/fire/labels.csv") | |
| # checking labels | |
| labels |> | |
| filter(Variable == "school") # mormon == 3 | |
| # create variables for analysis | |
| data$party <- factor(case_when( | |
| data$partyid %in% c(1,2,3) ~ "Dem", | |
| data$partyid %in% c(4) ~ "Ind", | |
| data$partyid %in% c(5,6,7) ~ "Rep", | |
| data$partyid %in% c(8) ~ "Other", | |
| ), levels = c("Rep", "Ind", "Dem", "Other")) | |
| data$BYU <- as.integer(data$school == "Brigham Young University-Provo") | |
| data$UU <- as.integer(data$school == "University of Utah") | |
| data$USU <- as.integer(data$school == "Utah State University") | |
| data$school_rc <- dplyr::case_when( | |
| data$school == "Brigham Young University-Provo" ~ "BYU", | |
| data$school == "University of Utah" ~ "UU", | |
| data$school == "Utah State University" ~ "USU", | |
| TRUE ~ "Other" | |
| ) | |
| data$is_anxious <- as.integer(data$anxious %in% c(3,4,5)) | |
| data$is_lonely <- as.integer(data$lonely %in% c(3,4,5)) | |
| data$no_time_self <- as.integer(data$notime %in% c(3,4,5)) | |
| data$is_depressed <- as.integer(data$depressed %in% c(3,4,5)) | |
| data$is_stressed <- as.integer(data$stressed %in% c(3,4,5)) | |
| recodes <- c( | |
| '1' = 'business', #Accounting | |
| '2' = 'social sciences', #African/Afr-American Studies | |
| '3' = 'natural sciences', #Agricultural/Food Sciences | |
| '4' = 'natural sciences',#Animal Science | |
| '5' = 'social sciences',#Anthropology | |
| '6' = 'natural sciences',#Archaeology | |
| '7' = 'engineering',#Architecture | |
| '8' = 'humanities/arts',#Art History | |
| '9' = 'humanities/arts',#Asian/Mideast Lang & Lit | |
| '10' = 'humanities/arts',#Asian/Mideast Studies | |
| '11' = 'natural sciences',#Physics and Astronomy | |
| '12' = 'natural sciences',#Biochemistry and Molecular Biology | |
| '13' = 'natural sciences',#Biological Sciences | |
| '14' = 'business',#business | |
| '15' = 'natural sciences',#Chemistry | |
| '16' = 'humanities/arts',#classics | |
| '17' = 'social sciences',#Cognitive Science | |
| '18' = 'humanities/arts',#Communication | |
| '19' = 'engineering',#Computer Science | |
| '20' = 'humanities/arts',#Dance | |
| '21' = 'engineering',#Data Science | |
| '22' = 'social sciences',#Development Studies | |
| '23' = 'business',#Digital Media Design | |
| '24' = 'natural sciences',#Earth Sciences | |
| '25' = 'social sciences',#Economics | |
| '26' = 'teaching',#Education | |
| '27' = 'engineering',#Education | |
| '28' = 'humanities/arts',#English | |
| '29' = 'natural sciences',#Environmental Studies | |
| '30' = 'social sciences',#Ethnicity and Race Studies | |
| '31' = 'humanities/arts',#European Cultural Studies | |
| '32' = 'humanities/arts',#Fashion | |
| '33' = 'humanities/arts',#Film and Media Studies | |
| '34' = 'business',#Finance | |
| '35' = 'humanities/arts',#Fine Arts | |
| '36' = 'humanities/arts',#French and Italian | |
| '37' = 'natural sciences',#Geography | |
| '38' = 'humanities/arts',#German Studies | |
| '39' = 'humanities/arts',#History | |
| '40' = 'business',#Hotel Administration | |
| '41' = 'social sciences',#International Relations | |
| '42' = 'humanities/arts',#Jewish Studies | |
| '43' = 'humanities/arts',#Lat Am/Latino/Carib Studies | |
| '44' = 'social sciences',#Law/Criminology | |
| '45' = 'humanities/arts',#Linguistics | |
| '46' = 'business',#Marketing | |
| '47' = 'engineering',#Mathematics | |
| '48' = 'humanities/arts',#Music | |
| '50' = 'natural sciences',#Neuroscience | |
| '51' = 'natural sciences',#Nursing | |
| '52' = 'humanities/arts',#Philosophy | |
| '53' = 'teaching',#Physical Education | |
| '54' = 'social sciences',#Political Science | |
| '55' = 'humanities/arts',#Portuguese and Brazilian Studies | |
| '56' = 'natural sciences',#Pre-Medical | |
| '57' = 'natural sciences',#Psychological and Brain Sciences | |
| '58' = 'natural sciences',#Public Health | |
| '59' = 'social sciences',#Public Policy | |
| '61' = 'business',#Real Estate | |
| '62' = 'humanities/arts',#Religion | |
| '63' = 'engineering',#Robotics and Intelligent Systems | |
| '65' = 'social sciences',#Sociology | |
| '66' = 'humanities/arts',#Spanish and Portuguese | |
| '67' = 'natural sciences',#Statistics | |
| '68' = 'humanities/arts',#SStudio Art | |
| '69' = 'humanities/arts',#Theater | |
| '70' = 'other',#Undecided | |
| '71' = 'social sciences',#Urban Studies | |
| '72' = 'humanities/arts',#Visual Arts | |
| '73' = 'social sciences',#Women's and Gender Studies (and Sexuality) | |
| '74' = 'other'#other | |
| ) | |
| data$major_type <- as.character(recodes[data$major1]) | |
| data$religattend_rc <- car::recode(data$religattend, '8:9=1;else=0') | |
| data$gender_rc <- factor(car::recode(data$gender, '1="male";2="female";3:6="other";-99=NA'), | |
| levels = c('male', 'female', 'other')) | |
| data$grad_level <- factor(car::recode( | |
| data$gradyear, | |
| "2024='Senior';2025='Junior';2026='Sophomore';2027='Freshman'"), | |
| levels = c('Freshman', 'Sophomore', 'Junior', 'Senior')) | |
| data$grad_level2 <- factor(car::recode( | |
| data$gradyear, | |
| "2024='Junior/Senior';2025='Junior/Senior';2026='Freshman/Sophomore';2027='Freshman/Sophomore'"), | |
| levels = c('Freshman/Sophomore', 'Junior/Senior')) | |
| # its too sparse so need to collapse major type again | |
| data$major_type2 <- as.character(recode_factor(data$major_type, | |
| 'business' = 'business/engineering/natural sciences', | |
| 'social sciences' = 'social sciences/humanities/arts/teaching/other', | |
| 'natural sciences' = 'business/engineering/natural sciences', | |
| 'engineering' = 'business/engineering/natural sciences', | |
| 'humanities/arts' = 'social sciences/humanities/arts/teaching/other', | |
| 'teaching' = 'social sciences/humanities/arts/teaching/other', | |
| 'other' = 'social sciences/humanities/arts/teaching/other' | |
| )) | |
| # Summarizing data for post | |
| ## Church attendance over time | |
| data |> | |
| filter(religion == 3) |> | |
| group_by(grad_level, BYU) |> | |
| count(religattend_rc) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level,BYU),names_from = religattend_rc, values_from = prop) |> | |
| arrange(BYU, grad_level) |> | |
| write_clip() | |
| # using school_rc variable | |
| data |> | |
| filter(religion == 3) |> | |
| group_by(grad_level2, school_rc) |> | |
| count(religattend_rc) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(grad_level2,school_rc),names_from = religattend_rc, values_from = prop) |> | |
| arrange(school_rc, grad_level2) |> | |
| write_clip() | |
| # quick peak at majors | |
| data |> | |
| filter(religion == 3) |> | |
| group_by(major_type) |> | |
| count(religattend_rc) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(major_type),names_from = religattend_rc, values_from = prop) |> | |
| arrange(desc(`1`)) |> | |
| select(major_type, `1`) | |
| # quick peak at majors | |
| data |> | |
| filter(religion == 3) |> | |
| group_by(gender_rc) |> | |
| count(religattend_rc) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(gender_rc),names_from = religattend_rc, values_from = prop) |> | |
| arrange(desc(`1`)) |> | |
| select(gender_rc, `1`) | |
| data |> | |
| filter(religion == 3) |> | |
| group_by(gender_rc, major_type) |> | |
| count(religattend_rc) |> | |
| drop_na() |> | |
| mutate(prop = n / sum(n)) |> | |
| pivot_wider(id_cols = c(gender_rc,major_type),names_from = religattend_rc, values_from = prop) |> | |
| arrange(major_type) |> | |
| filter(gender_rc != "other" & major_type != "other") |> | |
| select(gender_rc,major_type, `1`) | |
| # gist: https://gist.github.com/acbass49/d419ab4f3e7551a382ed8eee85adb91f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment