Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Estimating marginal effects of linear and quadratic term from a logit regression


From   "maartenbuis" <[email protected]>
To   [email protected]
Subject   Re: st: Estimating marginal effects of linear and quadratic term from a logit regression
Date   Mon, 08 Nov 2004 10:02:31 -0000

Dear Pradeep,

I just realised that my answer may have been a bit terse. Let me 
elaborate a litle: Finding the marginal effect of a variable in a 
logistic regression is finding the first derivative with respect to 
that x: {d pr(foreign=1)}/dx. Note that:

pr(foreign=1)= exp(xb)/(1+xb) , lets call that L(xb), and
xb=_b[-cons]+_b[weight]*weight+_b[price]*price+_b[mpg]*mpg+_b[mpg2]
*mpg^2

You can now apply the chain rule {d pr(foreign =1)}/dx = dL/(d xb) * 
(d xb)/dx. It so happens that L(xb) is the cumulative probality 
function of the logistic distribution. The deriviative of a 
cumulative probability function is the probability density function 
of that distribution. The probability density function of the 
logistic is: exp(xb)/(1+exp(xb))^2. So:

dL/(d xb) = exp(xb)/(1+xb)^2
(d xb)/(d mpg) = _b[mpg] + 2*_b[mpg2]*mpg

evaluating this function at the mean for each variable gives you the 
marginal effect of mpg when all variables have their mean value. Not 
that you can thus calculate the marginal effect of weight, price and 
mpg, but not of mpg^2, which makes substantive sense.

I hope that this clarifies my earlier post,
Maarten

--- In [email protected], "maartenbuis" <maartenbuis@y...> 
wrote:
> Dear Pradeep,
> 
> Calculating the marginal effect for a logistic regression when one 
of 
> the explanatory variables is also entered with an quadratic term 
can 
> be done by `hand' (well, by -nlcom- actually) but it gets a bit 
ugly, 
> see the example below. 
> 
> Notice that the first couple of lines of the -nlcom- is the 
> probability density function of the logistic: exp(xb)/(1+exp(xb))
^2. 
> The last lines of the -nlcom- command is the derivative of xb with 
> respect to x of interest, in this cas mpg: _b[mpg]+2*_b[mpg2]*(mean 
> mpg). 
> 
> Maarten
> 
> #delim ;
> sysuse auto;
> 
> gen mpg2=mpg^2;
> 
> logit foreign price weight mpg mpg2;
> 
> sum price, meanonly;
> local price = r(mean);
> 
> sum weight, meanonly;
> local weight = r(mean);
> 
> sum mpg, meanonly;
> local mpg = r(mean);
> 
> nlcom(
> 	exp(_b[_cons] + _b[price]*`price' + _b[weight]*`weight' + _b
> [mpg]*`mpg' + _b[mpg2]*`mpg'^2)/
>       (1+exp(_b[_cons] + _b[price]*`price' + _b[weight]*`weight' + 
_b
> [mpg]*`mpg' + _b[mpg2]*`mpg'^2))^2*
>       (_b[mpg]+2*_b[mpg2]*`mpg')
>       );
> 
> --- pradeep.kurukulasuriya@y...> wrote:
> > I have a logit model with a linear and quadratic variable along 
> with some
> > other variables (call it stuff). I am trying to estimate the 
> marginal
> > effects for different sets variables in my model where each set 
is 
> comprised
> > of a linear and quadratic term. Is there a ado file for this that 
> does not
> > require the differentiation to be done manually (and then run a 
> proceedure
> > like nlcom) or is that the best there is?
> 
> 
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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