  # RE: st: marginal effects for ordered logit

 From "Markiewicz, Agnieska" To Subject RE: st: marginal effects for ordered logit Date Tue, 16 Nov 2004 13:21:58 +0100

```Dear Maarten,

Thanks for you help. Now when I know how to calculate the odds, could
you help me with finding the right command to make a graph?

Aga

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of maartenbuis
Sent: Thursday, November 11, 2004 1:13 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: marginal effects for ordered logit

--- <Agnieszka.Markiewicz@e...> wrote:
> First of all I get the message that _b is an invalid name.

_b[variable name] is a convenient way of getting the parameter for
variable `variable name' from the last estimation command, e.g.

. sysuse auto
. reg price foreign

<snipt>
----------------------------------------------
price |      Coef.   Std. Err.      t  <etc.>
-------------+--------------------------------
foreign |   312.2587   754.4488     0.41 <etc.>
_cons |   6072.423    411.363    14.76 <etc.>
----------------------------------------------

. display _b[foreign]
312.25874

. display _b[_cons]
6072.4231

> Second, I would like to ask how to calculate the log odds in stata
> for an ordered logit.

That is easy: exponentiating minus the parameter estimates gives you
the odds. E.g. if you estimated -ologit rep78 mpg mpg2-, whereby mpg2
is the square of mpg, than -twoway function y = exp(-_b[mpg]*x-
_b[mpg2]*x^2), range(12 41) ytitle("odds") xtitle("mpg")- gives you
the odds of belonging to a group versus all `lower' groups. Notice
that you will get only one graph. The odds of belonging to group 2
versus group 1 is the same as the odds of belonging to group 3 versus
group 2 and 1, and is the same as the odds of belonging to group 4
versus group 3, 2 and 1. This is an assumption of the ordered logit
model which is known as the proportional odds assumption.

Getting the marginal effects in ordered logit is similar to getting
the marginal effects in logit, but not exactly the same. Again it is
a matter of finding the derivative of a function that relates the
probability of belonging to a group to the explanatory variables. In
ordered logit these functions are (if your have five groups):

Pr(group 1) = L(_cut1-xb)
Pr(group 2) = L(_cut2-xb) - L(_cut1-xb)
Pr(group 3) = L(_cut3-xb) - L(_cut2-xb)
Pr(group 4) = L(_cut4-xb) - L(_cut3-xb)
Pr(group 5) = 1 - L(_cut4-xb)

L  = exp(.)/(1+exp(.))
xb = _b[gear_ratio]*gear_ratio + _b[foreign]*foreign +
_b[mpg]*mpg + _b[mpg^2]*mpg^2

Notice the `-' in front of xb. Using the chain rule just as in
http://www.stata.com/statalist/archive/2004-11/msg00264.html results
in the following do-file:

version 7 //ensuring that it will run on your stata7
sysuse auto
gen mpg2 = mpg^2

ologit rep78 gear_ratio foreign mpg mpg2

sum gear_ratio, meanonly
local gear = r(mean)
sum mpg, meanonly
local mpg = r(mean)

/*
marginal effect of mpg for US cars
with mean gear ratio and mpg on the probability
of belonging to group 1
*/

#delim ;
display exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2)/
(1+exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2))^2 *
(-_b[mpg]-2*_b[mpg2]*`mpg');

/*
marginal effect of mpg for US cars
with mean gear ratio and mpg on the probability
of belonging to group 2
*/

display exp(_b[_cut2]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2)/
(1+exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2))^2 *
(-_b[mpg]-2*_b[mpg2]*`mpg') -
exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2)/
(1+exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2))^2 *
(-_b[mpg]-2*_b[mpg2]*`mpg');

/*
marginal effect of mpg for US cars
with mean gear ratio and mpg on the probability
of belonging to group 3
*/

display exp(_b[_cut3]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2)/
(1+exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2))^2 *
(-_b[mpg]-2*_b[mpg2]*`mpg') -
exp(_b[_cut2]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2)/
(1+exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2))^2 *
(-_b[mpg]-2*_b[mpg2]*`mpg');

/*
marginal effect of mpg for US cars
with mean gear ratio and mpg on the probability
of belonging to group 5
*/

display exp(_b[_cut4]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2)/
(1+exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2))^2 *
(-_b[mpg]-2*_b[mpg2]*`mpg') -
exp(_b[_cut3]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2)/
(1+exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2))^2 *
(-_b[mpg]-2*_b[mpg2]*`mpg');

/*
marginal effect of mpg for US cars
with mean gear ratio and mpg on the probability
of belonging to group 6
*/

display 1 -
exp(_b[_cut4]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2)/
(1+exp(_b[_cut1]-_b[gear_ratio]*`gear'
-_b[foreign]*0-_b[mpg]*`mpg'-_b[mpg2]*`mpg'^2))^2 *
(-_b[mpg]-2*_b[mpg2]*`mpg');

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