»  Home »  Resources & support »  FAQs »  Stata7: Marginal effects by example
This FAQ is for users of Stata 7. It is not relevant for Stata 8.

### Stata 7: How do you compute marginal effects after ologit/oprobit/mlogit using mfx?

 Title Stata7: Marginal effects by example Author Ronna Cong, StataCorp Date February 2001; updated May 2001

The Stata 7 command mfx numerically calculates the marginal effects or the elasticities and their standard errors after estimation. mfx works after ologit, oprobit, and mlogit. However, due to the multiple-outcome feature of these three commands, one has to run mfx separately for each outcome.

The marginal effect is defined as

	d F(X)
----------
d X

The predict() option in mfx allows users to specify the form of F(X), and the at() option allows users to specify the points (X) where the marginal effects are to be evaluated.

Examples are presented under two sections: Section 1: Specifying the form of F(X); and Section 2: Specifying the Xs.

### Section 1: Specifying the form of F(X)

Exactly what mfx can calculate is determined by the previous estimation command and by the predict() option. Users should check the predict options for the estimation command before running mfx.

Examples are presented for biprobit, heckman, heckprob, intreg, mlogit, ologit, oprobit, tobit, treatreg, xtintreg, xtlogit, xtprobit, and xttobit.

### biprobit

The marginal effects for positive outcomes, Pr(depvar1=1, depvar2=1), are
        . mfx compute, predict(p11)

The marginal effects for Pr(depvar1=1, depvar2=0) are
        . mfx compute, predict(p10)

The marginal effects for Pr(depvar1=0, depvar2=1) are
        . mfx compute, predict(p01)

The marginal effects for Pr(depvar1=0, depvar2=0) are
        . mfx compute, predict(p00)

The marginal effects for the marginal probability of outcome 1, Pr(depvar1=1), are
        . mfx compute, predict(pmarg1)

The marginal effects for the marginal probability of outcome 2, Pr(depvar2=1), are
        . mfx compute, predict(pmarg2)

The marginal effects for the conditional probability of outcome 1 given outcome 2, Pr(depvar1=1 | depvar2=1), are
        . mfx compute, predict(pcond1)

The marginal effects for the conditional probability of outcome 2 given outcome 1, Pr(depvar2=1 | depvar1=1), are
        . mfx compute, predict(pcond2)


### heckman

The marginal effects for the expected value of the dependent variable conditional on being observed, E(y | y observed), are
        . mfx compute, predict(ycond)

The marginal effects for the probability of the dependent variable being observed, Pr(y observed), are
        . mfx compute, predict(psel)


### heckprob

The marginal effects for the probability of a positive outcome, Pr(depvar=1), are
        . mfx compute, predict(pmargin)

The marginal effects for the probability of a positive outcome given the dependent variable being observed, Pr(depvar=1 | depvar_s=1), are
        . mfx compute, predict(pcond)

The marginal effects for the probability of the dependent variable being observed, Pr(depvar_s=1), are
        . mfx compute, predict(psel)

The marginal effects for Pr(depvar=1, depvar_s=1) are
        . mfx compute, predict(p11)

The marginal effects for Pr(depvar=1, depvar_s=0) are
        . mfx compute, predict(p10)

The marginal effects for Pr(depvar=0, depvar_s=1) are
        . mfx compute, predict(p01)

The marginal effects for Pr(depvar=0, depvar_s=0) are
        . mfx compute, predict(p00)


### intreg and tobit

The marginal effects for the probability of being uncensored are
        . mfx compute, predict(p(a,b))

where a is the lower limit for left censoring and b is the upper limit for right censoring.

The marginal effects for the expected value of the dependent variable conditional on being uncensored, E(y | a<y<b), are

        . mfx compute, predict(e(a,b))

where a is the lower limit for left censoring and b is the upper limit for right censoring.

The marginal effects for the unconditional expected value of the dependent variable, E(y*), where y* = max(a, min(y,b)), are

        . mfx compute, predict(ys(a, b))

where a is the lower limit for left censoring and b is the upper limit for right censoring.

### mlogit, ologit, and oprobit

Due to the multiple-outcome feature of these three commands, mfx must be run separately for each outcome.

Run the estimation command first:

        . use auto, clear

. mlogit rep78 mpg

or
        . ologit rep78 mpg

or
        . oprobit rep78 mpg

The marginal effects for the probability of outcome 1, Pr(y=1), are
        . mfx compute, predict(outcome(1))

The marginal effects for the probability of outcome 2, Pr(y=2), are
        . mfx compute, predict(outcome(2))

and so forth.

### treatreg

The marginal effects for the expected value of y conditional on being treated, E(y | treatment = 1), are
        . mfx compute, predict(yctrt)

The marginal effects for the expected value of y conditional on being untreated, E(y | treatment =0), are
        . mfx compute, predict(ycntrt)

The marginal effects for the probability of being treated, Pr(treatment=1), are
        . mfx compute, predict(ptrt)


### xtintreg and xttobit

The marginal effects for the probability of being uncensored are
        . mfx compute, predict(pr0(a, b))

where a is the lower limit for left censoring and b is the upper limit for right censoring.

The marginal effects for the expected value of y conditional on being uncensored are

        . mfx compute, predict(e0(a, b))

where a is the lower limit for left censoring and b is the upper limit for right censoring.

The marginal effects for the unconditional expected value of y are

        . mfx compute, predict(ys(a, b))

where a is the lower limit for left censoring and b is the upper limit for right censoring.

### xtlogit and xtprobit

The marginal effects for predicted probability after the random-effects model are
        . mfx compute, predict(pu0)

The marginal effects for the predicted probability, taking into account offset() after the population-averaged model, are
        . mfx compute, predict(mu)

The marginal effects for predicted probability, ignoring offset() after the population-averaged model, are
        . mfx compute, predict(rate)


### Section 2: Specifying the Xs

By default, mfx calculates the marginal effects at the means of the independent variables.

To calculate the marginal effects at the medians, type

        . mfx compute, at(median)

To calculate the marginal effects at zeros, type
        . mfx compute, at(zero)

To calculate the marginal effects at mpg=20 and zeros for other independent variables, type
        . mfx compute, at(zero mpg=20)