Marginal effects for interaction terms I am trying to compute probit regression that includes interaction terms. When I compute marginal effects after the main coefficients R gives me marginal effects for interaction terms and Stata doesn't. It says that Stata doesn't compute marginal effects for interaction terms because logically it's not possible. But then how does R compute them? and if it oes are they correct ?
I tried both Stata and R for the analysis and I am confused.
 A: Here is an example where I compute the same average marginal effects using R and Stata. The margin's vignette is also useful to explain marginal effects with interaction terms using R: https://cran.r-project.org/web/packages/margins/vignettes/Introduction.html
In Stata, the margins command can be used to compute marginal effects for interaction terms.
use "https://dss.princeton.edu/training/students.dta", clear

* Create the Math dummy variable
gen math= major=="Math"
encode gender, gen(sex)

probit math c.age##i.sex

* Compute marginal effects for interaction term
margins, dydx(*)


  Average marginal effects
  Number of   obs     =         30 Model VCE    : OIM
  Expression   : Pr(math), predict() dy/dx w.r.t. : age 2.sex

  Delta-method dy/dx   Std. Err.      z   P>z [95% Conf. Interval]        
  age   -.0087594   .0124467    -0.70 0.482   .0331544    .0156356
  sex  Male     -.361844   .1711841    -2.11  0.035   .6973588   -.0263293
  Note: dy/dx for factor levels is the discrete   change from the base level.


In R, the margins package can be used to compute marginal effects for interaction terms.
library(foreign)
library(margins)

mydata <-  read.dta("http://dss.princeton.edu/training/students.dta")

# Create the Math dummy variable
mydata$math <- ifelse(mydata$major == "Math", 1, 0)

model <- glm(math ~ age + gender + age:gender, data = mydata, 
             family = binomial(link = "probit"))

# Compute marginal effects for interaction term
m <- margins(model)
margins_summary(model)


 factor     AME     SE       z      p   lower   upper
 age -0.0088 0.0123 -0.7112 0.4770 -0.0329  0.0154  
 genderMale -0.3618 0.1716 -2.1084 0.0350 -0.6982 -0.0255


