Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: standard errors using MARGINS


From   jpitblado@stata.com (Jeff Pitblado, StataCorp LP)
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: standard errors using MARGINS
Date   Thu, 15 Oct 2009 11:57:20 -0500

Carter Hill <eohill@lsu.edu> is trying to reproduce -margins- results using
-predictnl-:

> I can replicate AME (exactly) but not standard error using MARGINS.
> Using PREDICTNL we can compute observation level marginal effects and
> standard errors. Average of the Marginal Effect matches output from
> MARGINS. But standard error does not. I'd like to know how MARGINS is
> computing its Delta Method Standard Error. Sample output below. Thanks.
> 
> . poisson art fem mar kid5 phd ment, vce(oim)
> 
> . * marginal effect of MENT observation by observation
> . 
> . predictnl dydment = exp(_b[_cons]+_b[fem]*fem+_b[mar]*mar +
> _b[kid5]*kid5 + _b[phd]*phd ///
> >            + _b[ment]*ment)*_b[ment], se(dydment_se)
> 
> . 
> . * predicted ART difference from assuming all N female and all N male
> . 
> . predictnl femdiff = exp(_b[_cons]+_b[fem]+_b[mar]*mar + _b[kid5]*kid5
> + _b[phd]*phd + _b[ment]*ment) ///
> >                   - exp(_b[_cons]+_b[mar]*mar + _b[kid5]*kid5 +
> _b[phd]*phd + _b[ment]*ment), se(femdiff_se)
> 
> . 
> . * AME i.FEM and dART/dMENT
> . 
> . summarize femdiff femdiff_se dydment dydment_se 
> 
>     Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>      femdiff |       915   -.3748107    .1342408  -1.936606  -.1879618
>   femdiff_se |       915     .092062    .0332046   .0459706   .5079955
>      dydment |       915    .0432412    .0170774   .0226905   .2459053
>   dydment_se |       915    .0042211    .0031078   .0021575   .0538789
> 
> . 
> . * compare above to use of MARGINS statement
> . 
> . quietly poisson art i.fem mar kid5 phd ment
> 
> . *------------------------------------------
> . * AME matches use of predictnl
> . * but standard error does not
> . *------------------------------------------
> . 
> . margins, dydx(fem ment)
> 
> Average marginal effects                          Number of obs   =
> 915
> Model VCE    : OIM
> 
> Expression   : Predicted number of events, predict()
> dy/dx w.r.t. : 1.fem ment
> 
> ------------------------------------------------------------------------
> ------
>              |            Delta-method
>              |      dy/dx   Std. Err.      z    P>|z|     [95% Conf.
> Interval]
> -------------+----------------------------------------------------------
> ------
>        1.fem |  -.3748107   .0900846    -4.16   0.000    -.5513733
> -.1982481
>         ment |   .0432412   .0035694    12.11   0.000     .0362454
> .0502371
> ------------------------------------------------------------------------
> ------

The simple explanation why Carter's hand SE calculations do not match up is
that the mean of the individually estimated standard errors does not equal the
estimated standard error of the mean of the prediction.  A square root gets in
the way.

-margins- does not compute the individual standard errors, it computes a
Jacobian matrix (which is a partial derivative matrix with respect to each
parameter of the model) -r(Jacobian)- for the estimated marginal effects
-r(b)- then estimates the variance matrix -r(V)- of -r(b)- via

	r(V) = r(Jacobian)*e(V)*r(Jacobian)'

The reported standard errors are then just the square-roots of the diagonal
elements of -r(V)-.

-predictnl- does something very similar but at the observation level.

Let J_i be the Jacobian vector for a single marginal effect at the i^th
observation.  Then -margins-' Jacobian matrix -r(Jacobian)- would be

	r(Jacobian) = (1/n) sum_{i=1}^n J_i

So Carter is computing

	(1/n) sum_{i=1}^n sqrt(J_i*e(V)*J_i')

while -margins- is computing

	sqrt(r(Jacobian)*e(V)*r(Jacobian)')

All derivatives for these nonlinear predictions are computed numerically.

--Jeff
jpitblado@stata.com
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index