Department of Political Science at Georgia State University
3/2/23
Toy Data
How do we implement interaction terms in R?
# Lets load in the data via the VDEM package # and clean it a bitvdem <-readRDS("data/vdem12.rds")vdem <- vdem |>filter(country_name =="United States of America") |>rename(democracy = v2x_polyarchy,gdp_per_cap = e_gdppc,urbanization = e_miurbani,polarization = v2cacamps,polarization_ord = v2cacamps_ord) |>mutate(high_polarization =ifelse(polarization >=-1, 1, 0))
Estimating Interaction Terms in R
As with all things in R there are several ways to do this
: and * are the most popular
/ is a nice trick to get the full marginal effect
I personally prefer * since it involves less typing