Dear All,
I am really getting crazy about the following point. Suppose I have the following model:
I estimate it using a multilevel logit model:
Then I calculate the marginal impact of age:
I want to replicate the above result manually:
I understood (possibly erroneously) that I could get the same value of p if I use:
This is in fact the case. Then, I would like to calculate the average marginal effects of age:
Surprisingly, the result is slightly different from the one obtained using margins:
Why this is the case? Is there any mistake in my procedure?
Thanks in advance for your insights.
Best
Dario
I am really getting crazy about the following point. Suppose I have the following model:
Code:
Prob[Y=1|X]=b0+b1*Age+zeta_i+error
Code:
webuse bangladesh, clear melogit c_use age || district:
Code:
margins, dydx(age) predict(mu)
Average marginal effects Number of obs = 1,934
Model VCE: OIM
Expression: Marginal predicted mean, predict(mu)
dy/dx wrt: age
------------------------------------------------------------------------------
| Delta-method
| dy/dx std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
age | .0018956 .0011887 1.59 0.111 -.0004342 .0042253
------------------------------------------------------------------------------
Code:
predict p, mu
su p
Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
p | 1,934 .3903534 .1014132 .1646984 .6360608
Code:
mat B= e(b)
mat score double xb = B /* This should refer to the fixed part only*/
predict rint, reffects
gen prob=invlogit(xb+rint)
su prob
Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
prob | 1,934 .3903534 .1014132 .1646984 .6360608
Code:
gen dpdx=prob*(1-prob)
gen me_age=dpdx*_b[age]
su me_age
Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
me_age | 1,934 .0019474 .0001967 .0011766 .0021382
Code:
margins, dydx(age) predict(mu)
Average marginal effects Number of obs = 1,934
Model VCE: OIM
Expression: Marginal predicted mean, predict(mu)
dy/dx wrt: age
------------------------------------------------------------------------------
| Delta-method
| dy/dx std. err. z P>|z| [95% conf. interval]
-------------+----------------------------------------------------------------
age | .0018956 .0011887 1.59 0.111 -.0004342 .0042253
------------------------------------------------------------------------------
Thanks in advance for your insights.
Best
Dario
