I recently started using margins (slow upgrade to the post-stata 10 world), and tried to re-write some of the old .do files. It turns out that I had trouble getting the same results by using mfx and margins.
I ran a relatively simple logit regression using the old "mfx" command first, and the commands and results look like:
commands:
logistic compaper insider oncestock later i.occucode, robust
mfx
results:
logistic compaper insider oncestock later i.occucode, robust
i.occucode _Ioccucode_1-9 (naturally coded; _Ioccucode_5 omitted)
Logistic regression Number of obs = 2908
Wald chi2(7) = 653.70
Prob > chi2 = 0.0000
Log pseudolikelihood = -1443.3277 Pseudo R2 = 0.2347
Robust
compaper Odds Ratio Std. Err. z P>z [95% Conf. Interval]
insider 1.338362 .2074708 1.88 0.060 .9876923 1.813533
oncestock 1.253733 .1549868 1.83 0.067 .9839642 1.597463
later 3.360304 .4007488 10.16 0.000 2.659895 4.245146
_Ioccucode_1 .1455745 .0373587 -7.51 0.000 .0880323 .2407291
_Ioccucode_2 .6183545 .0827797 -3.59 0.000 .4756488 .8038752
_Ioccucode_8 8.142382 1.246059 13.70 0.000 6.032384 10.99041
_Ioccucode_9 .1708144 .0351556 -8.59 0.000 .1141136 .2556887
_cons .2302005 .0236327 -14.31 0.000 .1882437 .2815087
. mfx
Marginal effects after logistic
y = Pr(compaper) (predict)
= .32067289
variable dy/dx Std. Err. z P>z [ 95% C.I. ] X
insider* .0659358 .03623 1.82 0.069 -.005075 .136947 .096974
oncest~k* .0502987 .02797 1.80 0.072 -.004522 .105119 .223177
later* .2475381 .02154 11.49 0.000 .205318 .289758 .605571
_Ioccu~1* -.2819143 .02058 -13.70 0.000 -.322246 -.241582 .083219
_Ioccu~2* -.0979491 .02522 -3.88 0.000 -.147373 -.048525 .158528
_Ioccu~8* .4806974 .03001 16.02 0.000 .421881 .539514 .168845
_Ioccu~9* -.2778684 .01988 -13.98 0.000 -.316836 -.238901 .120014
(*) dy/dx is for discrete change of dummy variable from 0 to 1
Then I tried the margins:
commands:
logistic compaper i.insider i.oncestock i.later ib5.occucode, robust
margins, dydx(insider oncestock later occucode)
Results:
Logistic regression Number of obs = 2908
Wald chi2(7) = 653.70
Prob > chi2 = 0.0000
Log pseudolikelihood = -1443.3277 Pseudo R2 = 0.2347
Robust
compaper Odds Ratio Std. Err. z P>z [95% Conf. Interval]
1.insider 1.338362 .2074708 1.88 0.060 .9876923 1.813533
1.oncestock 1.253733 .1549868 1.83 0.067 .9839642 1.597463
1.later 3.360304 .4007488 10.16 0.000 2.659895 4.245146
occucode
1 .1455745 .0373587 -7.51 0.000 .0880323 .2407291
2 .6183545 .0827797 -3.59 0.000 .4756488 .8038752
8 8.142382 1.246059 13.70 0.000 6.032384 10.99041
9 .1708144 .0351556 -8.59 0.000 .1141136 .2556887
_cons .2302005 .0236327 -14.31 0.000 .1882437 .2815087
. margins, dydx(insider oncestock later occucode)
Average marginal effects Number of obs = 2908
Model VCE : Robust
Expression : Pr(compaper), predict()
dy/dx w.r.t. : 1.insider 1.oncestock 1.later 1.occucode 2.occucode 8.occucode
9.occucode
Delta-method
dy/dx Std. Err. z P>z [95% Conf. Interval]
1.insider .0485594 .0264908 1.83 0.067 -.0033615 .1004803
1.oncestock .0370138 .0203009 1.82 0.068 -.0027752 .0768028
1.later .2052595 .0198058 10.36 0.000 .1664409 .2440782
occucode
1 -.2745338 .0233213 -11.77 0.000 -.3202427 -.2288248
2 -.0955908 .0255189 -3.75 0.000 -.145607 -.0455747
8 .439998 .0285118 15.43 0.000 .384116 .49588
9 -.2623443 .0221572 -11.84 0.000 -.3057715 -.2189171
Note: dy/dx for factor levels is the discrete change from the base level.
I have a hard time understanding why these two methods gave pretty different results. I'm pretty sure I made a mistake somewhere in the syntax for margins, but have a hard time figuring it out. Thanks for your time in advance!
I ran a relatively simple logit regression using the old "mfx" command first, and the commands and results look like:
commands:
logistic compaper insider oncestock later i.occucode, robust
mfx
results:
logistic compaper insider oncestock later i.occucode, robust
i.occucode _Ioccucode_1-9 (naturally coded; _Ioccucode_5 omitted)
Logistic regression Number of obs = 2908
Wald chi2(7) = 653.70
Prob > chi2 = 0.0000
Log pseudolikelihood = -1443.3277 Pseudo R2 = 0.2347
Robust
compaper Odds Ratio Std. Err. z P>z [95% Conf. Interval]
insider 1.338362 .2074708 1.88 0.060 .9876923 1.813533
oncestock 1.253733 .1549868 1.83 0.067 .9839642 1.597463
later 3.360304 .4007488 10.16 0.000 2.659895 4.245146
_Ioccucode_1 .1455745 .0373587 -7.51 0.000 .0880323 .2407291
_Ioccucode_2 .6183545 .0827797 -3.59 0.000 .4756488 .8038752
_Ioccucode_8 8.142382 1.246059 13.70 0.000 6.032384 10.99041
_Ioccucode_9 .1708144 .0351556 -8.59 0.000 .1141136 .2556887
_cons .2302005 .0236327 -14.31 0.000 .1882437 .2815087
. mfx
Marginal effects after logistic
y = Pr(compaper) (predict)
= .32067289
variable dy/dx Std. Err. z P>z [ 95% C.I. ] X
insider* .0659358 .03623 1.82 0.069 -.005075 .136947 .096974
oncest~k* .0502987 .02797 1.80 0.072 -.004522 .105119 .223177
later* .2475381 .02154 11.49 0.000 .205318 .289758 .605571
_Ioccu~1* -.2819143 .02058 -13.70 0.000 -.322246 -.241582 .083219
_Ioccu~2* -.0979491 .02522 -3.88 0.000 -.147373 -.048525 .158528
_Ioccu~8* .4806974 .03001 16.02 0.000 .421881 .539514 .168845
_Ioccu~9* -.2778684 .01988 -13.98 0.000 -.316836 -.238901 .120014
(*) dy/dx is for discrete change of dummy variable from 0 to 1
Then I tried the margins:
commands:
logistic compaper i.insider i.oncestock i.later ib5.occucode, robust
margins, dydx(insider oncestock later occucode)
Results:
Logistic regression Number of obs = 2908
Wald chi2(7) = 653.70
Prob > chi2 = 0.0000
Log pseudolikelihood = -1443.3277 Pseudo R2 = 0.2347
Robust
compaper Odds Ratio Std. Err. z P>z [95% Conf. Interval]
1.insider 1.338362 .2074708 1.88 0.060 .9876923 1.813533
1.oncestock 1.253733 .1549868 1.83 0.067 .9839642 1.597463
1.later 3.360304 .4007488 10.16 0.000 2.659895 4.245146
occucode
1 .1455745 .0373587 -7.51 0.000 .0880323 .2407291
2 .6183545 .0827797 -3.59 0.000 .4756488 .8038752
8 8.142382 1.246059 13.70 0.000 6.032384 10.99041
9 .1708144 .0351556 -8.59 0.000 .1141136 .2556887
_cons .2302005 .0236327 -14.31 0.000 .1882437 .2815087
. margins, dydx(insider oncestock later occucode)
Average marginal effects Number of obs = 2908
Model VCE : Robust
Expression : Pr(compaper), predict()
dy/dx w.r.t. : 1.insider 1.oncestock 1.later 1.occucode 2.occucode 8.occucode
9.occucode
Delta-method
dy/dx Std. Err. z P>z [95% Conf. Interval]
1.insider .0485594 .0264908 1.83 0.067 -.0033615 .1004803
1.oncestock .0370138 .0203009 1.82 0.068 -.0027752 .0768028
1.later .2052595 .0198058 10.36 0.000 .1664409 .2440782
occucode
1 -.2745338 .0233213 -11.77 0.000 -.3202427 -.2288248
2 -.0955908 .0255189 -3.75 0.000 -.145607 -.0455747
8 .439998 .0285118 15.43 0.000 .384116 .49588
9 -.2623443 .0221572 -11.84 0.000 -.3057715 -.2189171
Note: dy/dx for factor levels is the discrete change from the base level.
I have a hard time understanding why these two methods gave pretty different results. I'm pretty sure I made a mistake somewhere in the syntax for margins, but have a hard time figuring it out. Thanks for your time in advance!
Comment