# st: ML and conditional logits: lf vs d0

 From Mike Brewer To statalist@hsphsun2.harvard.edu Subject st: ML and conditional logits: lf vs d0 Date Thu, 01 Aug 2002 09:14:02 +0100

```Dear Stata Listers,

I am writing an ML routine to estimate something similar to a conditional logit (ie
several choices, choice-specific variables), and I am confused as to whether I am
able to write an lf estimator to do this.

p38 of "ML Estimation with Stata" states that: "The following are examples of
likelihoods that do not meet this [ie the lf] the criterion: the conditional
(fixed-effects) logit model...". Indeed, Stata's clogit command requires data in
"long form", ie:

id choice attribute choose
1   1          5            0
1   2          10           1
1   3          15           0

2   1        6              1
2   2        12              0
2   3        18             0

3   1       7               0
3   2       14              0
3   3       21              1

(ie person 1 chose choice number 2, person 2 chose 1 and person 3 chose 3.)

The usual d0 ML program then goes something like as follows [where the likelihood
contribution for each person is the exponential of the utility of the actual choice
divided by the sum of the exponentials of the utilities of each of the possible
choices; excuse the economist's interpretation].

/* d0 evaluator */
args todo b lnf
mleval `theta' = `b',eq(1)
tempvar expU
gen double `expU' = exp(`theta')
egen `sumexpU' = sum(`expU'), by(id)
mlsum `lnf' = `expU'/`sumexpU' if choose==1
/* probably go on to calculate derivatives and Hessian too */
exit;

But is it not equally possible to arrange data in wide format, ie:

id choose attribute1 attribute2 attribute3
1   2          5               10             15
2   1          6               12             18
3   3          7               14             21

and then code an lf evaluator?

I'll answer my own question: I think it is logistically possible , although it is a
much less elegant ML program than the long-format d0 program, but I wondered
whether it was econometrically valid? A limited experiment suggested that the 2
methods do give similar results, but the lf method is of course much quicker.

Any thoughts or experiences gratefully received!

Mike Brewer

--
Mike Brewer
Senior Research Economist
Institute for Fiscal Studies
7 Ridgmount Street, London, WC1E 7AE, UK

http://www.ifs.org.uk
Tel: +44 (0)20 7291 4800
Fax: +44 (0)20 7323 4780

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