Skip to content

Instantly share code, notes, and snippets.

View ryanburge's full-sized avatar

Ryan Burge ryanburge

View GitHub Profile
@ryanburge
ryanburge / cath_wk_attend.R
Created April 13, 2024 17:31
Catholic Weekly Attendance
over <- gss %>%
filter(year == 1982 | year == 1987) %>%
filter(reltrad == 1 | reltrad == 2 | reltrad == 3 | reltrad == 4) %>%
mutate(att = case_when(attend == 6 | attend == 7 | attend == 8 ~ 1,
attend <= 5 ~ 0)) %>%
group_by(year, reltrad) %>%
mean_ci(att, wt = oversamp)
## This is the weight for the rest of the sample ####
In the past seven days, how often have you
A. Felt nervous, anxious, or on edge?
B. Felt depressed?
C. Felt lonely?
D. Felt hopeful about the future? (Reversed)
E. Had trouble sleeping
1. Less than 1 day
@ryanburge
ryanburge / stacked_bars_flipped.R
Last active December 31, 2023 16:20
Stacked Bars Flipped
gg %>%
filter(trad2 != "NA") %>%
mutate(lab = round(pct, 2)) %>%
ggplot(., aes(x = 1, y = pct, fill = fct_rev(age2))) +
geom_col(color = "black") +
coord_flip() +
facet_wrap(~ trad2, ncol =1, strip.position = "left") +
theme_rb() +
scale_fill_manual(values = c(moma.colors("OKeeffe", 5))) +
ggg1 <- cces08 %>%
mutate(rel = frcode(religpew == 9 ~ "Atheist",
religpew == 10 ~ "Agnostic",
religpew == 11 ~ "Nothing in Particular")) %>%
mutate(vote = CC410) %>%
mutate(vote = frcode(vote == 1 ~ "Republican",
vote == 2 ~ "Democrat",
vote == 3 | vote == 4 | vote == 5 | vote == 6 ~ "Third Party")) %>%
group_by(rel) %>%
graph <- cces %>%
filter(year == 2008 | year == 2012 | year == 2016 | year == 2020 | year == 2022) %>%
cces_pid3(pid7) %>%
mutate(religpew = religion) %>%
mutate(rel = frcode(religpew <= 8 ~ "Religious",
religpew == 9 | religpew == 10 | religpew == 11 ~ "Secular")) %>%
group_by(pid3, year) %>%
ct(rel, wt = weight, show_na = FALSE) %>%
na.omit() %>%
filter(pid3 != "Independent")
@ryanburge
ryanburge / coding_assignment_2_fall_2023.R
Created November 25, 2023 15:40
Coding Assignment #2 - Fall 2023
## Packages ##
library(socsci)
library(car)
install.packages("jtools")
library(jtools)
install.packages("interactions")
library(interactions)
REGRESSION TUTORIAL: https://rpubs.com/ryanburge/reg_interact
@ryanburge
ryanburge / grad_methods_code_1116.R
Created November 16, 2023 15:58
Code for 11/16
error_bar <- function(wd){
if(missing(wd)){
geom_errorbar(aes(ymin=lower, ymax=upper), width=.2, position=position_dodge(.9))
} else{
geom_errorbar(aes(ymin=lower, ymax=upper), width=wd, position=position_dodge(.9))
}
}
@ryanburge
ryanburge / grad_methods_111502023.R
Created November 15, 2023 17:54
Grad Methods - 11/15/2023
error_bar <- function(wd){
if(missing(wd)){
geom_errorbar(aes(ymin=lower, ymax=upper), width=.2, position=position_dodge(.9))
} else{
geom_errorbar(aes(ymin=lower, ymax=upper), width=wd, position=position_dodge(.9))
}
}
@ryanburge
ryanburge / coding_assignment_1_fall_2023.R
Created November 2, 2023 15:55
Coding Assignment 1 - Fall 2023
## Read your data in with this line:
gss <- read_csv("https://raw.githubusercontent.com/ryanburge/ct/master/gss_small.csv", guess_max = 25000)
## Codebook:
https://gssdataexplorer.norc.org/
## Maxwell Abillia
1. What percentage of people supported access to a legal abortion in the case of rape in 1994?
2. How many white women did not finish high school in the 1972 sample?
@ryanburge
ryanburge / grad_methods_1101.R
Last active November 1, 2023 21:38
Graduate Methods - 11/1/2023
# install.packages("remotes")
# library(remotes)
# remotes::install_github("ryanburge/socsci")
# library(socsci)
gss <- read_csv("https://raw.githubusercontent.com/ryanburge/ct/master/gss_small.csv", guess_max = 25000)
Codebook: https://gssdataexplorer.norc.org/