Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

[no subject]



************************************************
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 <JFischer@diw.de> 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).

*
*   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   |   Site index