| Title | Marginal effects after estimations with weights | |
| Author | May Boggess, StataCorp | |
| Date | April 2004 |
. clear
. set mem 2M
(output omitted)
. webuse nhanes2d
. svy: logit highbp hei black, offset(hlthstat)
(running logit on estimation sample)
Survey: Logistic regression
Number of strata = 31 Number of obs = 10351
Number of PSUs = 62 Population size = 1.172e+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)
= .06750566
------------------------------------------------------------------------------
variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X
---------+--------------------------------------------------------------------
height | .0013649 .00033 4.19 0.000 .000727 .002003 168.46
black*| -.004929 .00943 -0.52 0.601 -.023408 .01355 .095506
hlthstat | (offset) 2.39875
------------------------------------------------------------------------------
(*) dy/dx is for discrete change of dummy variable from 0 to 1
. summarize hei [aweight=finalwgt] if e(sample)
Variable | Obs Weight Mean Std. Dev. Min Max
-------------+-----------------------------------------------------------------
height | 10351 117157513 168.4599 9.699111 135.5 200
. replace hei = r(mean)
(10351 real changes made)
. summarize black [aweight=finalwgt] if e(sample)
Variable | Obs Weight Mean Std. Dev. Min Max
-------------+-----------------------------------------------------------------
black | 10351 117157513 .0955059 .2939267 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 .0675057 0 .0675057 .0675057
. replace black=0
(10351 real changes made)
. predict p0, p
. replace black=1
(10351 real changes made)
. predict p1, p
. gen marg=p1-p0
. summarize marg
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
marg | 10351 -.004929 0 -.004929 -.004929
mfx uses the pweight from svyset and puts it in the aweight option of summarize. This gives the same mean as svy: mean would but not the same standard deviation. However, since we don't need the standard deviation, we can get away with this here.
This trick is actually making things a bit easier since using svy: mean would change our estimation results, and we wouldn't be able to follow it with mfx.
Now let's redo the above example without weights by utilizing the nowgt of mfx:
. clear
. set mem 2M
(output omitted)
. webuse nhanes2d
. svy: logit highbp hei wei black, offset(hlthstat)
(running logit on estimation sample)
Survey: Logistic regression
Number of strata = 31 Number of obs = 10351
Number of PSUs = 62 Population size = 1.172e+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)
= .06757666
------------------------------------------------------------------------------
variable | dy/dx Std. Err. z P>|z| [ 95% C.I. ] X
---------+--------------------------------------------------------------------
height | -.0008998 .00036 -2.49 0.013 -.001609 -.000191 167.651
weight | .0030887 .00035 8.76 0.000 .002398 .00378 71.8975
black*| -.0163552 .00787 -2.08 0.038 -.031789 -.000921 .104917
hlthstat | (offset) 2.59349
------------------------------------------------------------------------------
(*) dy/dx is for discrete change of dummy variable from 0 to 1
. summarize hei if e(sample)
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
height | 10351 167.6509 9.655916 135.5 200
. replace hei = r(mean)
(10351 real changes made)
. summarize wei if e(sample)
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
weight | 10351 71.89752 15.35642 30.84 175.88
. replace wei = r(mean)
(10351 real changes made)
. summarize black if e(sample)
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
black | 10351 .1049174 .3064618 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 .0675767 0 .0675767 .0675767
. replace black=0
(10351 real changes made)
. predict p0, p
. replace black=1
(10351 real changes made)
. predict p1, p
. gen marg=p1-p0
. summarize marg
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
marg | 10351 -.0163552 0 -.0163552 -.0163552