In Stata 11, the margins command replaced mfx.
| Title | Marginal effects after estimations with weights | |
| Author | May Boggess, StataCorp |
Yes, using the nowght option. Let’s first make sure we understand how mfx handles weights for survey data, and then we'll see how to ignore the weights when we need to.
. clear
. set mem 2M
(output omitted)
. webuse nhanes2d
. svy: logit highbp height black, offset(hlthstat)
(running logit on estimation sample)
Survey: Logistic regression
Number of strata = 31 Number of obs = 10349
Number of PSUs = 62 Population size = 1.171e+08
Design df = 31
F( 2, 30) = 10.30
Prob > F = 0.0004
------------------------------------------------------------------------------
| Linearized
highbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
height | .0216824 .0049413 4.39 0.000 .0116046 .0317603
black | -.0805318 .1565209 -0.51 0.611 -.3997582 .2386946
_cons | -8.669328 .8423297 -10.29 0.000 -10.38727 -6.951385
hlthstat | (offset)
------------------------------------------------------------------------------
. mfx, predict(p)
Marginal effects after svy:logit
y = Pr(highbp) (predict, p)
= .06750846
------------------------------------------------------------------------------
variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X
---------+--------------------------------------------------------------------
height | .0013649 .00033 4.19 0.000 .000727 .002003 168.462
black*| -.0049292 .00943 -0.52 0.601 -.023409 .01355 .095527
hlthstat | (offset) 2.39875
------------------------------------------------------------------------------
(*) dy/dx is for discrete change of dummy variable from 0 to 1
. summarize height [aweight=finalwgt] if e(sample)
Variable | Obs Weight Mean Std. Dev. Min Max
-------------+-----------------------------------------------------------------
height | 10349 117131111 168.462 9.698747 135.5 200
. replace height = r(mean)
(10351 real changes made)
. summarize black [aweight=finalwgt] if e(sample)
Variable | Obs Weight Mean Std. Dev. Min Max
-------------+-----------------------------------------------------------------
black | 10349 117131111 .0955274 .2939563 0 1
. replace black = r(mean)
black was byte now float
(10351 real changes made)
. summarize hlthstat [aweight=finalwgt] if e(sample)
Variable | Obs Weight Mean Std. Dev. Min Max
-------------+-----------------------------------------------------------------
hlthstat | 10349 117131111 2.398746 1.163176 1 8
. replace hlthstat = r(mean)
hlthstat was byte now float
(10351 real changes made)
. predict y, p
. summarize y
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
y | 10351 .0675085 0 .0675085 .0675085
. replace black=0
(10351 real changes made)
. predict p0, p
. replace black=1
(10351 real changes made)
. predict p1, p
. generate marg=p1-p0
. summarize marg
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
marg | 10351 -.0049292 0 -.0049292 -.0049292
In the previous example, we correctly calculated the predicted value for y, and we even calculated the marginal effect for black and found that checked out OK, too. We also saw that all the means and the offset have taken the weight into account, as well.
mfx obtains the pweight variable from svyset and uses it as an aweight variable with summarize. This gives the same mean as svy: mean but not the same standard deviation. However, because we don’t need the standard deviation, we can get away with this here.
This trick is actually making things a bit easier because using svy: mean would change our estimation results, and we wouldn't be able to use mfx after svy: mean.
Now let’s redo the above example without weights by specifying the nowght option of mfx:
. clear
. set mem 2M
(output omitted)
. webuse nhanes2d
. svy: logit highbp height weight black, offset(hlthstat)
(running logit on estimation sample)
Survey: Logistic regression
Number of strata = 31 Number of obs = 10349
Number of PSUs = 62 Population size = 1.171e+08
Design df = 31
F( 3, 29) = 55.69
Prob > F = 0.0000
------------------------------------------------------------------------------
| Linearized
highbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
height | -.0142804 .0053408 -2.67 0.012 -.0251729 -.0033879
weight | .0490184 .0037007 13.25 0.000 .0414709 .056566
black | -.2857725 .1423184 -2.01 0.053 -.5760329 .0044878
_cons | -6.318211 .8832654 -7.15 0.000 -8.119643 -4.51678
hlthstat | (offset)
------------------------------------------------------------------------------
. mfx, predict(p) nowght
Marginal effects after svy:logit
y = Pr(highbp) (predict, p)
= .06758168
------------------------------------------------------------------------------
variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X
---------+--------------------------------------------------------------------
height | -.0008999 .00036 -2.49 0.013 -.001609 -.000191 167.653
weight | .0030889 .00035 8.76 0.000 .002398 .00378 71.8998
black*| -.0163564 .00788 -2.08 0.038 -.031792 -.000921 .104938
hlthstat | (offset) 2.59349
------------------------------------------------------------------------------
(*) dy/dx is for discrete change of dummy variable from 0 to 1
. summarize height if e(sample)
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
height | 10349 167.6526 9.655687 135.5 200
. replace height = r(mean)
(10351 real changes made)
. summarize weight if e(sample)
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
weight | 10349 71.89977 15.35705 30.84 175.88
. replace weight = r(mean)
(10351 real changes made)
. summarize black if e(sample)
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
black | 10349 .1049377 .3064879 0 1
. replace black = r(mean)
black was byte now float
(10351 real changes made)
. summarize hlthstat if e(sample)
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
hlthstat | 10349 2.593487 1.221695 1 8
. replace hlthstat = r(mean)
hlthstat was byte now float
(10351 real changes made)
. predict y, p
. summarize y
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
y | 10351 .0675817 0 .0675817 .0675817
. replace black=0
(10351 real changes made)
. predict p0, p
. replace black=1
(10351 real changes made)
. predict p1, p
. generate marg=p1-p0
. summarize marg
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
marg | 10351 -.0163564 0 -.0163564 -.0163564
nowght does exactly what we want. All the means have been calculated without weights. Even the offset is calculated without weights. The predicted y value and the marginal effect for black checks out OK.