library(haven) # import Stata data and labels
library(dplyr) # data manipulation
library(ggplot2) # graphs
library(marginaleffects) # predictions and marginal effects
library(cleanplots) # graph scheme
cleanplots_defaults()
love <- read_dta("https://tdmize.github.io/data/data/doan_love_SF.dta")
# Keep model variables; drop any missing data
love <- love[c("informal", "cond", "love10", "rfem", "age", "rce_wht", "ed_coll",
"ed_hs", "inc_50k", "married", "childyn", "children", "ideo", "evangel",
"mainline", "blackprot", "catholic", "ofaithV2")]
love <- love[complete.cases(love), ] |>
mutate(cond = as_factor(cond))
# Continuous DV: Informal Privileges
inform <- lm(informal ~ cond * love10 + rfem + age + rce_wht + ed_coll + ed_hs +
inc_50k + married + childyn + children + ideo + evangel + mainline + blackprot +
catholic + ofaithV2, data = love)
# 7.2.a
plot_predictions(inform, by = c("love10", "cond"),
newdata = datagrid(love10 = seq(0, 10, .5), cond = unique, grid_type = "counterfactual")) +
annotate("text", x = c(4, 4, 8, 8), y = c(3, 9.5, 5.7, 11), size = 3,
label = c("Pr = 4.12", "Pr = 8.06", "Pr = 6.95", "Pr = 9.81")) +
scale_x_continuous(breaks = seq(0, 10, 2)) +
scale_y_continuous(breaks = seq(0, 12, 2)) +
labs(title = "[7.2.a] Predicted Support of Informal Privileges by Perceptions of Love",
subtitle = "Effect of Sexual Orientation of Couple",
x = "Perceptions of Love", y = "Predicted Approval", color = NULL, fill = NULL)