I am interested in reproducing average marginal effects from a random effects logit model (run in Stata using xtlogit
). I understand how to reproduce the average marginal effects from a logit
model using the Delta method. For instance, in the code below, I successfully reproduce the average marginal effect for age
reported in margins
.
*** Stata code
* download data
webuse union, clear
* calculate delta and copy variable of interest - age
sum age
gen xdelta = r(sd)/1000
clonevar age_ = age
* run logit model and calculate average marginal effect using margins
logit union age_
margins,dydx(age_)
* calculate average marginal effect by hand - mean of xme equals result from margins above
predict p1
replace age_ = age_+xdelta
predict p2
gen xme = (p2 - p1) / xdelta
sum xme
* calculate average marginal effect at fixed value of age using margins
margins,at(age=(16))
* calculate average marginal effect by hand - mean of p3 equals result from margins above
replace age_ = 16
predict p3
sum p3
Where I'm struggling is reproducing the average marginal effects for a xtlogit
model.
*** Stata code
* download data and designate panel variables
webuse union, clear
xtset idcode year
* run xtlogit model
xtlogit union age
* calculate average marginal effects - can't figure out how to reproduce these estimates :(
margins, dydx(*)
margins, at(age=(16))
Any help for figuring out how to reproduce the xtlogit
marginal effects is greatly appreciated. Thank you!
----- edited to make clearer that I'm interested in reproducing estimates reported by margins