Re: st: How does margins get semi-elasticity eydx here?

 From Skipper Seabold To statalist@hsphsun2.harvard.edu Subject Re: st: How does margins get semi-elasticity eydx here? Date Thu, 31 Dec 2009 00:02:06 -0500

```On Wed, Dec 30, 2009 at 11:16 PM, Austin Nichols
<austinnichols@gmail.com> wrote:
> Skipper Seabold <jsseabold@gmail.com> :
> The -margins- manual entry is exhaustive and a good place to start,
> but in short:
> Don't divide by y but by yhat.  Particularly for a zero/one depvar,
> where dividing by y just sets the negative outcomes to missing
> (dividing by zero) and leaves the positives unchanged (dividing by

I looked through it if you mean the main reference pdf, I think it was
just a notational thing for me and not actually thinking about what I
was doing.

> one).  Also no need to use Mata here...  and easier to see a mistake
> in Stata probably.
>

Thanks this is much cleaner.

> clear all
> use http://www.ats.ucla.edu/stat/stata/examples/greene/tbl19-1
> qui logit grade gpa tuce psi
> set type double
> predict xb, xb
> g f=invlogit(xb)/(1+exp(xb))
> predict p
> g fp=f/p
> su
> mat b=r(mean)*e(b)
> margins, eydx(*)
> mat li b
>
>
> On Wed, Dec 30, 2009 at 10:50 PM, Skipper Seabold <jsseabold@gmail.com> wrote:
>> If eydx is defined as dy/dx * (1/y), then I don't understand how the
>> following values are found by margins (using Stata 11):
>>
>> use http://www.ats.ucla.edu/stat/stata/examples/greene/tbl19-1, clear
>> logit grade gpa tuce psi
>>
>> <snip>
>>
>> margins, eydx
>>
>> Average marginal effects                          Number of obs   =         32
>> Model VCE    : OIM
>>
>> ey/dx w.r.t. : gpa tuce 1.psi
>>
>> ------------------------------------------------------------------------------
>>             |            Delta-method
>>             |      ey/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
>> -------------+----------------------------------------------------------------
>>         gpa |   1.854637   .8479031     2.19   0.029     .1927771    3.516496
>>        tuce |   .0624472   .0930901     0.67   0.502    -.1200061    .2449006
>>       1.psi |   1.554903   .7283702     2.13   0.033      .127324    2.982483
>> ------------------------------------------------------------------------------
>>
>>
>> Presumably it would give something like the following, if I had
>> treated psi as continuous (Please excuse the hackish mata.  I'm still
>> learning my way around...).  Are the missing values (NaNs or Infs,
>> depending on your take) handled in some odd way or is something
>> entirely different going on?  I didn't see anything in the manual on
>> this or with a (quick) google search.
>>
>> mata
>> exog = st_data(., ("gpa", "tuce", "psi"))
>> stata(". gen cons = 1")
>> cons = st_data(., "cons")
>> exog = (exog,cons)
>> params = st_matrix("e(b)")'
>> xb = exog * params
>> pdf = exp(-xb):/(1:+exp(-xb)):^2
>> dydx = pdf * params'
>> mfx = mean(effects :/ endog)
>> end
>>
>> Any clarifications or further references would be appreciated.
>>
>> Cheers,
>> Skipper
>>
>
> *
> *   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/
>

*
*   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/
```