# Re: st: clogit marginal effects?

 From "Arne Risa Hole" To statalist@hsphsun2.harvard.edu Subject Re: st: clogit marginal effects? Date Wed, 30 Aug 2006 09:56:01 +0100

```Hi Jim

Apparently -mfx- cannot be used following -clogit- with the
predict(pc1) option, which is what you want. The following FAQ
explains http://www.stata.com/support/faqs/stat/mfx_unsuit.html

An alternative is to do the calculations manually and use the -nlcom-
command to get the standard errors. The code below demonstrates how to
do this using both the differential and the
difference-in-probabilities approach (it's a bit messy so you may want
to double-check the calculations but I believe the outline is
correct).

Note that the marginal effects are calculated slightly differently
from my previous email: instead of calculating individual marginal
effects and averaging the marginal effects are calculated at the mean
of the explanatory variables, analogous to -mfx- with the at(mean)
option.

Arne

/* Marginal effects for variable female w/ SEs */

use http://www.stata-press.com/data/r9/choice.dta

gen usa = (car == 1)
gen japan = (car == 2)
gen europe = (car == 3)
gen female = (sex == 0)
gen femJap = female*japan
gen femEur = female*europe
gen incJap = income*japan
gen incEur = income*europe

qui clogit choice japan europe femJap femEur incJap incEur dealer, group(id)

qui sum femJap if japan == 1
local femJap = r(mean)
qui sum femEur if europe == 1
local femEur = r(mean)
qui sum incJap if japan == 1
local incJap = r(mean)
qui sum incEur if europe == 1
local incEur = r(mean)
qui sum dealer if usa == 1
local dealUSA = r(mean)
qui sum dealer if japan == 1
local dealJap = r(mean)
qui sum dealer if europe == 1
local dealEur = r(mean)

/* Differential approach */

local v_USA _b[dealer]*`dealUSA'
local v_Jap _b[japan]+_b[femJap]*`femJap'+_b[incJap]*`incJap'+_b[dealer]*`dealJap'
local v_Eur _b[europe]+_b[femEur]*`femEur'+_b[incEur]*`incEur'+_b[dealer]*`dealEur'

local p_USA exp(`v_USA')/(exp(`v_USA')+exp(`v_Jap')+exp(`v_Eur'))
local p_Jap exp(`v_Jap')/(exp(`v_USA')+exp(`v_Jap')+exp(`v_Eur'))
local p_Eur exp(`v_Eur')/(exp(`v_USA')+exp(`v_Jap')+exp(`v_Eur'))

nlcom `p_USA'*(-_b[femJap]*`p_Jap' - _b[femEur]*`p_Eur')
nlcom `p_Jap'*(_b[femJap] - _b[femJap]*`p_Jap' - _b[femEur]*`p_Eur')
nlcom `p_Eur'*(_b[femEur] - _b[femJap]*`p_Jap' - _b[femEur]*`p_Eur')

/* Difference in probabilities approach */

local vm_USA _b[dealer]*`dealUSA'
local vm_Jap _b[japan]+_b[incJap]*`incJap'+_b[dealer]*`dealJap'
local vm_Eur _b[europe]+_b[incEur]*`incEur'+_b[dealer]*`dealEur'

local vf_USA _b[dealer]*`dealUSA'
local vf_Jap _b[japan]+_b[femJap]+_b[incJap]*`incJap'+_b[dealer]*`dealJap'
local vf_Eur _b[europe]+_b[femEur]+_b[incEur]*`incEur'+_b[dealer]*`dealEur'

local pm_USA exp(`vm_USA')/(exp(`vm_USA')+exp(`vm_Jap')+exp(`vm_Eur'))
local pm_Jap exp(`vm_Jap')/(exp(`vm_USA')+exp(`vm_Jap')+exp(`vm_Eur'))
local pm_Eur exp(`vm_Eur')/(exp(`vm_USA')+exp(`vm_Jap')+exp(`vm_Eur'))

local pf_USA exp(`vf_USA')/(exp(`vf_USA')+exp(`vf_Jap')+exp(`vf_Eur'))
local pf_Jap exp(`vf_Jap')/(exp(`vf_USA')+exp(`vf_Jap')+exp(`vf_Eur'))
local pf_Eur exp(`vf_Eur')/(exp(`vf_USA')+exp(`vf_Jap')+exp(`vf_Eur'))

nlcom `pf_USA'-`pm_USA'
nlcom `pf_Jap'-`pm_Jap'
nlcom `pf_Eur'-`pm_Eur'

On 29/08/06, James Marton <marton@uky.edu> wrote:
```
```Hi Arne

Thanks for the suggestions! I have a spreadsheet that estimates the clogit
marginal effects manually.  I will try your approach and compare.

I was hoping there was a way to use the mfx commands in STATA so that the
marginal effects would be estimated directly and the significance tests for
the marginal effects would be presented as well.

Jim

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Arne Risa Hole
Sent: Tuesday, August 29, 2006 10:52 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: clogit marginal effects?

Hi James

As far as I can see the marginal effects can be calculated in the same
way as for the multinomial logit model in this case (see e.g. Greene,
2003, pp. 722, for the formula). In the case of the 'female' variable
an alternative approach is to simply calculate the difference in the
probability of choosing a car of a particular nationality assuming the
respondents are female/male, i.e. marginal effect = prob(assuming
female) - prob(assuming male). The program below demonstrates the two
approaches using the choice.dta dataset.

Hope this helps.

Arne

use http://www.stata-press.com/data/r9/choice.dta

gen usa = (car == 1)
gen japan = (car == 2)
gen europe = (car == 3)
gen female = (sex == 0)
gen femJap = female*japan
gen femEur = female*europe
gen incJap = income*japan
gen incEur = income*europe

qui clogit choice japan europe femJap femEur incJap incEur dealer, group(id)

/* Predicted probabilities by nationality */
predict double prob
sort id, stable
by id: egen double prob_USA = sum(prob*usa)
by id: egen double prob_Jap = sum(prob*japan)
by id: egen double prob_Eur = sum(prob*europe)

/* Individual-specific marginal effects for variable female */

gen double meff_fem = prob_USA*(-_b[femJap]*prob_Jap -
_b[femEur]*prob_Eur) if usa == 1
replace meff_fem = prob_Jap*(_b[femJap] - _b[femJap]*prob_Jap -
_b[femEur]*prob_Eur) if japan == 1
replace meff_fem = prob_Eur*(_b[femEur] - _b[femJap]*prob_Jap -
_b[femEur]*prob_Eur) if europe == 1

/* Average marginal effects for variable female */

sum meff_fem if usa == 1
sum meff_fem if japan == 1
sum meff_fem if europe == 1

/* Alternative individual-specific marginal effects for variable female */

/* Predicted probabilities by nationality, all respondents assumed male */
replace femJap = 0
replace femEur = 0
predict double mprob

/* Predicted probabilities by nationality, all respondents assumed female */
replace femJap = japan
replace femEur = europe
predict double fprob

/* Difference in probabilities, female-male */
gen double meff_fem2 = fprob-mprob

/* Alternative average marginal effects for variable female */

sum meff_fem2 if usa == 1
sum meff_fem2 if japan == 1
sum meff_fem2 if europe == 1

On 28/08/06, James Marton <marton@uky.edu> wrote:
> Hello Everyone
>
> I am trying to estimate marginal effects for a conditional logit model
that
> is essentially identical to the one presented as example 5 on page 227 in
> the STATA 9 reference for A-J under the clogit command.  In that example,
> each person chooses between 3 types of cars: American (excluded category),
> Japanese, and European. Their choice depends on their sex and income (both
> person specific) and also the number of car dealerships of each type in
> their city (person & choice specific).  The dataset is available at:
>
> http://www.stata-press.com/data/r9/choice.dta
>
> Does anyone know how to generate a set of marginal effects for each person
> specific variable?  In other words, after running the clogit model whose
> output is given on page 228, I would like to put together a table with the
> following information:
>
> Variable        Marginal Effect
>
> Female  marginal effect for choosing American if female
>                marginal effect for choosing Japanese if female
>                marginal effect for choosing European if female
>
> Income  marginal effect for choosing American if income inc. by 1 unit
>                marginal effect for choosing Japanese if income inc. by 1
> unit
>                marginal effect for choosing European if income inc. by 1
> unit
>
> Here the marginal effects for female should sum to one and the marginal
> effects for income should sum to one.
>
> Any suggestions would be greatly appreciated!
>
> Jim Marton
> Assistant Professor
> Martin School of Public Policy and Administration University of Kentucky
> marton@uky.edu
> http://www-martin.uky.edu/~marton
>
>
>
>
> *
> *   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/

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