Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Re: Re: Re: st: 'margin' and marg. effects of second-order polynomials
From
Tirthankar Chakravarty <[email protected]>
To
[email protected]
Subject
Re: Re: Re: Re: st: 'margin' and marg. effects of second-order polynomials
Date
Thu, 30 Dec 2010 03:13:30 -0800
standard normal density.
T
On Thu, Dec 30, 2010 at 3:09 AM, Tirthankar Chakravarty
<[email protected]> wrote:
> Justina,
>
> While the following sentence at <http://www.stata.com/stata11/margins.html>:
>
> "[...] Because of Stata 11’s new factor-variable features, we can get
> average partial and marginal effects for age even when age enters as a
> polynomial:"
>
> confirms what I have said above, it is sometimes a good exercise to
> check these yourself. I show below how you might do this for a probit
> model with higher-order terms (in principle, the extension to ordered
> probit is the same because of the parallel lines assumption). Recall
> that the formula for the change in probability of success is (_not_ as
> you write):
>
> d(P(y=1))/dx = \phi(x'b)(b_1+2*b_{12}*x_1)
>
> where x is the entire vector of covariates, and x_1 is the covariate
> of interest (for which the second-order term is also included in the
> linear index, hence the form of the marginal effect), b_1 is the
> coefficient on the main term and b_{12} is the coefficient on the
> polynomial term. Note that this is for each individual observation.
> From these, computing the so-called average marginal effects is easy.
> Here is the code:
>
> ************************************************
> clear*
> clear mata
> sysuse auto, clear
> g mpgsq = mpg^2
>
> mata
> // probit log-likelihood
> void fnProbitLL(todo,b,crit,g,H)
> {
> external vY,mX
> crit= vY'*log(normal(mX*b'))+(1:-vY)'*log(1:-normal(mX*b'))
> }
>
> // create data
> vY = st_data(., ("foreign"))
> cons=J(rows(vY),1,1)
> mX = st_data(., ("mpg", "price", "mpgsq")), cons
> stata("qui: logit foreign mpg price mpgsq ")
> init = st_matrix("e(b)")
>
> // optimize
> S=optimize_init()
> optimize_init_valueid(S, "log-likelihood")
> optimize_init_which(S, "max")
> optimize_init_evaluatortype(S,"d0")
> optimize_init_evaluator(S, &fnProbitLL())
> optimize_init_params(S, init)
> optimize_init_technique(S, "nr")
> optimize_init_trace_value(S, "on")
> optimize_init_trace_params(S, "on")
> optimize(S)
>
> // retrieve results
> vB = optimize_result_params(S)
> mVarCovar = optimize_result_V_oim(S)
>
> // construct marginal effects (Ai & Norton, EL, 2003)
> dB12 = vB[1, 3] // coeff. on 2nd-order term
> dB1 = vB[1, 1] // coeff. on main term
> // vector of individual marginal effects
> vPE = normalden(mX*vB'):*(dB1:+2*dB12:*mX[.,1])
> // average partial effect
> printf("The average marginal effect of age= %g.\n", colsum(vPE)/rows(vPE))
> end
>
> // probit foreign c.mpg##c.mpg price
> probit foreign mpg c.mpg#c.mpg price
> margins, dydx(mpg)
> ************************************************
>
> And you see that the marginal effects computed directly from the
> formula coincides exactly with what Stata gives you using -margins-.
>
> The standard reference for this sort of thing is Ai & Norton,
> "Interaction terms in logit and probit models", Economics Letters,
> 80(1), 2003, and the accompanying Stata Journal article, which can be
> found here:
> http://www.stata-journal.com/article.html?article=st0063
>
> T
>
>
>
> On Thu, Dec 30, 2010 at 1:08 AM, Justina Fischer <[email protected]> wrote:
>> thanks for these insights ans sorry for bothering you a last time:
>>
>> estimating
>>
>> logistic outcome treatment##group c.age##c.age
>>
>> what marginal effect does
>>
>> margins, dydx(age)
>>
>> estimate ? is it dy/dx = a + 2bx ?
>>
>> Justina
>
>
>
> --
> To every ω-consistent recursive class κ of formulae there correspond
> recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
> belongs to Flg(κ) (where v is the free variable of r).
>
--
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).
*
* 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/