# Remove NAs from the data first
d_posted_clean <- d_posted[!is.na(d_posted$high_unemploy) &
!is.na(d_posted$response) &
!is.na(d_posted$response_public), ]
# Run models
model_unemp_high_resp <- lm(response ~ tr1 + tr2 + tr3,
data = subset(d_posted_clean, high_unemploy == 1))
model_unemp_high_pub <- lm(response_public ~ tr1 + tr2 + tr3,
data = subset(d_posted_clean, high_unemploy == 1))
model_unemp_low_resp <- lm(response ~ tr1 + tr2 + tr3,
data = subset(d_posted_clean, high_unemploy == 0))
model_unemp_low_pub <- lm(response_public ~ tr1 + tr2 + tr3,
data = subset(d_posted_clean, high_unemploy == 0))
# Function to extract coefficient and SE
extract_coef <- function(model, var) {
coef_val <- round(coef(model)[var], 3)
se_val <- round(sqrt(diag(vcovHC(model, type = "HC1")))[var], 3)
return(c(coef_val, se_val))
}
# Build the table manually
hte_unemp_table <- data.frame(
Variable = c("T1: collective action threat", "",
"T2: tattling threat", "",
"T3: claims of loyalty", "",
"Constant", "",
"Observations", "R-squared"),
High_Resp = c(extract_coef(model_unemp_high_resp, "tr1")[1],
paste0("(", extract_coef(model_unemp_high_resp, "tr1")[2], ")"),
extract_coef(model_unemp_high_resp, "tr2")[1],
paste0("(", extract_coef(model_unemp_high_resp, "tr2")[2], ")"),
extract_coef(model_unemp_high_resp, "tr3")[1],
paste0("(", extract_coef(model_unemp_high_resp, "tr3")[2], ")"),
extract_coef(model_unemp_high_resp, "(Intercept)")[1],
paste0("(", extract_coef(model_unemp_high_resp, "(Intercept)")[2], ")"),
nobs(model_unemp_high_resp),
round(summary(model_unemp_high_resp)$r.squared, 3)),
High_Pub = c(extract_coef(model_unemp_high_pub, "tr1")[1],
paste0("(", extract_coef(model_unemp_high_pub, "tr1")[2], ")"),
extract_coef(model_unemp_high_pub, "tr2")[1],
paste0("(", extract_coef(model_unemp_high_pub, "tr2")[2], ")"),
extract_coef(model_unemp_high_pub, "tr3")[1],
paste0("(", extract_coef(model_unemp_high_pub, "tr3")[2], ")"),
extract_coef(model_unemp_high_pub, "(Intercept)")[1],
paste0("(", extract_coef(model_unemp_high_pub, "(Intercept)")[2], ")"),
nobs(model_unemp_high_pub),
round(summary(model_unemp_high_pub)$r.squared, 3)),
Low_Resp = c(extract_coef(model_unemp_low_resp, "tr1")[1],
paste0("(", extract_coef(model_unemp_low_resp, "tr1")[2], ")"),
extract_coef(model_unemp_low_resp, "tr2")[1],
paste0("(", extract_coef(model_unemp_low_resp, "tr2")[2], ")"),
extract_coef(model_unemp_low_resp, "tr3")[1],
paste0("(", extract_coef(model_unemp_low_resp, "tr3")[2], ")"),
extract_coef(model_unemp_low_resp, "(Intercept)")[1],
paste0("(", extract_coef(model_unemp_low_resp, "(Intercept)")[2], ")"),
nobs(model_unemp_low_resp),
round(summary(model_unemp_low_resp)$r.squared, 3)),
Low_Pub = c(extract_coef(model_unemp_low_pub, "tr1")[1],
paste0("(", extract_coef(model_unemp_low_pub, "tr1")[2], ")"),
extract_coef(model_unemp_low_pub, "tr2")[1],
paste0("(", extract_coef(model_unemp_low_pub, "tr2")[2], ")"),
extract_coef(model_unemp_low_pub, "tr3")[1],
paste0("(", extract_coef(model_unemp_low_pub, "tr3")[2], ")"),
extract_coef(model_unemp_low_pub, "(Intercept)")[1],
paste0("(", extract_coef(model_unemp_low_pub, "(Intercept)")[2], ")"),
nobs(model_unemp_low_pub),
round(summary(model_unemp_low_pub)$r.squared, 3))
)
# Display table
hte_unemp_table %>%
kable(
booktabs = TRUE,
col.names = c("", "Response", "Public", "Response", "Public"),
align = c("l", "c", "c", "c", "c")
) %>%
kable_styling(
bootstrap_options = c("striped", "hover"),
full_width = FALSE,
position = "center"
) %>%
add_header_above(c(" " = 1, "High Unemployment" = 2, "Low Unemployment" = 2)) %>%
footnote(
general = "Huber White robust standard errors in parentheses.",
general_title = "Note:",
footnote_as_chunk = TRUE
)