I estimate a logit model and then I want to compute the (average) marginal effects of the regressors on the probability of a positive outcome. Since my dataset is quite big (roughly 450,000 observations), margins takes ages. Therefore, I tried to work this problem around using predictnl to "manually" compute the required marginal effects. Now consider the following example:
Code:
webuse bangladesh logit c_use urban age children margins, dydx(urban age children)
Code:
Average marginal effects Number of obs = 1,934 Model VCE: OIM Expression: Pr(c_use), predict() dy/dx wrt: urban age children ------------------------------------------------------------------------------ | Delta-method | dy/dx std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- urban | .1784138 .0221528 8.05 0.000 .1349952 .2218325 age | -.0063953 .0016695 -3.83 0.000 -.0096674 -.0031232 children | .0853374 .0117828 7.24 0.000 .0622435 .1084314 ------------------------------------------------------------------------------
Code:
egen mage=mean(age) egen mchildren=mean(children) egen murban=mean(urban) predictnl marurban =_b[urban]*(1/(1+exp(-(_b[_cons]+_b[urban]*murban*_b[age]*mage+_b[children]*mchildren))))*(1-(1/(1+exp(-(_b[_cons]+_b[urban]*murban*_b[age]*mage+_b[children]*mchildren))))), se(se1)
Code:
Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- marurban | 1,934 .1756926 0 .1756926 .1756926 se1 | 1,934 .0214322 0 .0214322 .0214322
Code:
nlcom (marurban: _b[urban]*(1/(1+exp(-(_b[_cons]+_b[urban]*murban*_b[age]*mage+_b[children]*mchildren))))*(1-(1/(1+exp(-(_b[_cons]+_b[urban]*murban*_b[age]*mage+_b[children]*mchildren))))))
Code:
Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- marurban | 1,934 .1756926 0 .1756926 .1756926 se1 | 1,934 .0214322 0 .0214322 .0214322
Thanks in advance for your help.
Dario
0 Response to margins, predictnl and nlcom
Post a Comment