Here is a reproducable example as suggested by Olivier.
library(stats)
library(margins)
# Generate Data
set.seed(1234)
# Continuous
y<-rnorm(1000)
x1<-4*runif(1000)
x2<-2*rnorm(1000)
# Categorical
c1<-as.factor(ifelse(x1<=0.9,"A",
ifelse(x1>0.9 & x1<=2.4,"B",
ifelse(x1>2.4 & x1<=3.5,"C","D"))))
c2<-as.factor(ifelse(x2>2,"Y","N"))
table(c1)
> c1
> A B C D
> 201 397 268 134
table(c2)
> c2
> N Y
> 825 175
# Dummy dependent variable
y<-ifelse(y>0,1,0)
table(y)
> y
> 0 1
> 517 483
probit<-glm(y ~ x1 + x2 + c1 + c2,family=binomial(link="probit"))
# AME
margins<-summary(margins(probit))
margins[,c(1,2)]
> factor AME
> c1B 0.0068
> c1C 0.0620
> c1D 0.0800
> c2Y -0.0176
> x1 -0.0371
> x2 0.0037
# COMPUTE PARTIAL DENSITY FUNCTION
pdf<-mean(dnorm(predict(probit)))
# Compute Manually AME of x1 (Continous Variable)
round(pdf*coef(probit)[2],4) # This is the same AME returned by the margins command !
> x1
> -0.0371
# 1. Compute Manually AME of C1 and C2 for each level (Categorical Variable) using pdf
round(pdf*coef(probit)[4],4) # AME_C1 Level B
> c1B
> 0.0069
round(pdf*coef(probit)[5],4) # AME_C1 Level C
> c1C
> 0.0623
round(pdf*coef(probit)[6],4) # AME_C1 Level D
> c1D
> 0.0804
# They all are slightly different to those returned my margins command
round(pdf*coef(probit)[7],4) # AME_C2 (dummy)
> c2Y
> -0.0176
Therefore my question is : " Does margins command computes marginal effects by using a discrete change for dummy and categorical data ?"
In theory, If the variable Xj is continous, the marginal probability effect is :
[https://i.stack.imgur.com/OtEEx.jpg]
However if Xj is a dummy :
[https://i.stack.imgur.com/XMwrx.jpg]