library(haven) # import Stata data and labels
library(dplyr) # data manipulation
library(ggplot2) # graphs
library(MASS) # ordinal logit: polr()
library(modelsummary) # modelplot()
library(cleanplots) # graph scheme
cleanplots_defaults()
gss <- read_dta("https://tdmize.github.io/data/data/cda_gss.dta")
# Religious attendee = attends about once a month or more
gss <- gss |>
mutate(religous = case_when(attend <= 3 ~ 0, attend >= 4 ~ 1)) |>
filter(year >= 1986)
# Keep model variables; drop any missing data
gss <- gss[c("pillok", "year1972", "religous", "college", "age", "woman", "race3", "faminc")]
gss <- gss[complete.cases(gss), ]
# Reverse coded DV so interpretations are more natural
gss <- gss |>
mutate(pillokR = factor(5 - pillok, levels = 1:4,
labels = c("StrDisag", "Disagree", "Agree", "StrAgree")),
religous = factor(religous, labels = c("Not Religious", "Religious")),
across(c(college, woman, race3), as_factor),
year1972 = as.numeric(year1972)) |>
droplevels()
pillmod <- polr(pillokR ~ year1972 + age + woman + religous + college + race3 + faminc,
data = gss, Hess = TRUE)
# SD of y* (latent SD)
sdystar <- sqrt(var(pillmod$lp) + pi^2/3)
# 5.3.a: coefficients plotted on the axis of y* standardized coefficients
modelplot(pillmod, coef_omit = "\\|", ci_method = "wald") +
scale_x_continuous(breaks = seq(-.5, .5, .1) * sdystar, limits = c(-.5, .5) * sdystar,
labels = function(x) round(x / sdystar, 2)) +
geom_vline(xintercept = 0, linetype = "dashed") +
labs(title = "[5.3.a] Support for birth control access for teenagers",
subtitle = "y* standardized coefficients from ordinal logit")