# st: Effects coding and nested logit in Stata

 From Jacky Haskell To statalist@hsphsun2.harvard.edu Subject st: Effects coding and nested logit in Stata Date Fri, 14 Aug 2009 10:27:41 -0400

```Dear all,

I am analyzing data from a choice experiment and am trying to figure
out what is the correct way of effects coding to run nested logit.

In each choice question, there are three alternatives: Contract A,
Contract B, or Not Buy. Each alternative is characterized by four
attributes. One of the attributes ("survival") has four possible
levels in Contracts A and B, and is always at a status quo level in
the Not Buy alternative; this status quo level is not included in the
four attribute levels in the contracts. Initially, I used effects
codes as follows: three "survival" variables (survival1, survival2,
survival3) representing each of the first three attribute levels,
using the fourth level as a base (a value of -1 for all three
variables), and entering all zeros for the status quo.

So the values for [survival1, survival2, survival3] with effect codes
looks like this:
level 1: 1, 0, 0
level 2: 0, 1, 0
level 3: 0, 0, 1
level 4: -1, -1, -1

I then estimated a nested logit model in Stata 10 using the following commands:
nlogitgen type=alternative(yes: 1 | 2, no: 3)
label list lb_type
nlogittree alternative type, choice(choice)
nlogit choice survival1  survival2 survival3 acres access1 access2
access3 cost || type: || alternative:, noconstant case(idq)

The model was estimated, but Stata gave the following message:
note: variable survival1 has 296 cases that are not
alternative-specific: there is no within-case variability
note: variable survival2 has 274 cases that are not
alternative-specific: there is no within-case variability
note: variable survival3 has 277 cases that are not
alternative-specific: there is no within-case variability

I believe that the lack of within-case variability occurs whenever a
survival variable has all zeros for all three alternatives; for
example, if  Contract A has survival level 2, Contract B has survival
level 3, and Not Buy is always the status quo level, then the variable
survival1 will have a value of zero for all three alternatives.

To avoid this problem, I changed the effects codes to the following:
the same three "survival" variables, but this time using the status
quo level as a base (a value of -1 for all three variables), and
entering all zeros for the fourth attribute level.

Now the values for the variables [survival1, survival2, survival3]
with effect codes looks like this:
level 1: 1, 0, 0
level 2: 0, 1, 0
level 3: 0, 0, 1
level 4: 0, 0, 0

When I run the model with this set of effect codes, there is no longer
an error message. The "cost" variable's parameter estimate is
unchanged, but the survival variables' estimates are different,
causing a significant difference in the resulting willingness-to-pay
estimates obtained from the two models. My question is, which model is
correct? Has anyone come across a similar problem?

Thank you,
Jacky Kemp

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```