Home  /  Resources & Support  /  FAQs  /  Nested logit
Note: This FAQ is no longer relevant since the nlogit command was introduced in Stata 7.

Is there a nested logit command in Stata?

Title   Comparison of the nested logit and the constrained multinomial models
Author William Gould and William Sribney, StataCorp
Date April 1999

The short answer is, no. Stata does not presently have a command that does nested logit. However, Stata does have one feature — the ability to estimate multinomial models with constraints across the equations — which may help for some choice models.

Consider a choice among {1,2,3} in which you imagine the choice is made

Nested Logit model:
A choice is made first between 1 and (2,3) and then, if (2,3), a choice is made between 2 and 3.

Constrained Multinomial model:
A choice is made among {1,2,3}, but there are some variables that affect only {1,{2,3}}, and some that affect {1,2,3}.

The Nested Logit and Constrained Multinomial models are somewhat related, but clearly different.

How to estimate the Constrained Multinomial model

Let W be the outcome 1, 2, or 3.
Example: 1=do not buy a car, 2=buy a Ford, 3=buy a Mercedes.
Let X be a variable that affects {1,{2,3}}.
Example: X=age of current car.
Let Z be a variable that affects {1,2,3}.
Example: Z=wealth.
In the unconstrained multinomial logistic model, we write:
      r1 = 1

      r2 = exp(a2 + X*b2 + Z*c2)

      r3 = exp(a3 + X*b3 + Z*c3)

      p1 = Pr(W==1) = r1/(r1+r2+r3) = 1/(1+r2+r3)

      p2 = Pr(W==2) = r2/(r1+r2+r3) = r2/(1+r2+r3)

      p3 = Pr(W==3) = r3/(r1+r2+r3) = r3/(1+r2+r3)
Here we have (arbitrarily) used group 1 as the base group for normalization. The coefficients to be estimated are a2, b2, c2, a3, b3, and c3. The Relative Risks (RR) are ratios of the probabilities:
      RR(W==1 wrt W==1) = Pr(W==1) / Pr(W==1) = r1 = 1

      RR(W==2 wrt W==1) = Pr(W==2) / Pr(W==1) = r2

      RR(W==3 wrt W==1) = Pr(W==3) / Pr(W==1) = r3

Relative Risk Ratios are ratios of the Relative Risks (ratios of ratios!). The Relative Risk Ratio (RRR) for a one-unit change in the corresponding variable, relative to the (arbitrarily chosen) base group (W==1) is simply the exponentiated value of a coefficient. For example,
      Pr(W==2|age+1) / Pr(W==1|age+1)
      ------------------------------- = exp(b2)
      Pr(W==2|age)   / Pr(W==1|age)
or, in words, exp(b2) is the RRR of X (age of car), Ford vs. no new purchase.

Here is the verbal interpretation of all the coefficients:

      exp(b2) = RRR of X (age of car), Ford vs. no new purchase
      exp(c2) = RRR of Z (wealth), Ford vs. no new purchase

      exp(b3) = RRR of X (age of car), Mercedes vs. no new purchase
      exp(c3) = RRR of Z (wealth), Mercedes vs. no new purchase
The real trick is learning to think in the Relative Risk metric (meaning r1, r2, and r3).

We want to constrain variable X — age of current car — so that it's effect is to leave p2/p3 unchanged. X affects the overall risk of buying a car (1-p1) but not which car is purchased. Thus, we want to constrain the change in

      p2   r2   exp(a2 + X*b2 + Z*c2)
      -- = -- = ---------------------
      p3   r3   exp(a3 + X*b3 + Z*c3)

to be 0 for a change in X, meaning b2=b3 (because then X*b2 and X*b3 cancel).

If this is the constraint we want, here's the Stata code to do it. Let's assume the variables are named

      W    carpur, 1=no car, 2=Ford, 3=Mercedes
      X    c_c_age
      Z    wealth
Then the Stata code is
      . constraint define 1 [2]c_c_age=[3]c_c_cage
      . mlogit carpur c_cage style wealth, base(1) constrain(1)