Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • mixlogit: Variable has no within-group variance

    I am having trouble estimating a mixed logit model with the command -mixlogit- in Stata 14.
    I have some individual specific variables of which I know for a fact that they influence the choice that is being made.

    The data is as follows:
    Each respondent of a survey had to make a choice between three alternatives. They have to do this 8 times in total.
    I have some individual specific explanatory variables. For example variable a20 is a dummy variable that is equal to 1 if the age of the respondent is below 20 and 0 otherwise.

    I want to estimate the mixed logit model with the following command:
    Code:
    mixlogit choice td a20, rand(at fee) group(group) id(id)
    I get the error r(459): "Variable a20 has no within-group variance"

    The data for the first respondent can be found below:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(id group) str3 alternative byte(choice at td) double fee byte a20
    1 1 "FSP" 1 10 10   0 0
    1 1 "PSP" 0 10 10  .6 0
    1 1 "PUP" 0  5 10  .8 0
    1 2 "FSP" 1 10 15   0 0
    1 2 "PSP" 0 10 15  .6 0
    1 2 "PUP" 0  5 10  .8 0
    1 3 "FSP" 1 15 15   0 0
    1 3 "PSP" 0 10 10  .8 0
    1 3 "PUP" 0  5 10  .8 0
    1 4 "FSP" 1 15 10   0 0
    1 4 "PSP" 0 10 15  .8 0
    1 4 "PUP" 0  5 10  .8 0
    1 5 "FSP" 1 15 15   0 0
    1 5 "PSP" 0 10 10  .6 0
    1 5 "PUP" 0  5 10 1.5 0
    1 6 "FSP" 1 15 10   0 0
    1 6 "PSP" 0 10 15  .6 0
    1 6 "PUP" 0  5 10 1.5 0
    1 7 "FSP" 1 10 10   0 0
    1 7 "PSP" 0 10 10  .8 0
    1 7 "PUP" 0  5 10 1.5 0
    1 8 "FSP" 1 10 15   0 0
    1 8 "PSP" 0 10 15  .8 0
    1 8 "PUP" 0  5 10 1.5 0
    end

  • #2
    I am not a user of mixlogit (a user-written package from the Stata Journal and SSC), but here is my understanding of your problem.

    What you hypothesize is not an effect of age as such, but rather of the interaction of age and the particular alternatives. For example, all else being equal, perhaps 19-year-olds prefer PUP to FSP more strongly than do 25-year-olds.

    Stata is telling you that a20 is always the same for all three alternatives for a given individual, so it can have no effect on that individual's choice. If that seems odd, consider what the case would be if there were a price variable associated with your alternatives, and it were the same for all three alternatives. Stata has no way of knowing that age is a characteristic of the individual and affects the individual's perception of each alternative differently.

    From within Stata, the output of search mixlogit returns among other things a link to the original SJ paper at

    https://www.stata-journal.com/sjpdf....iclenum=st0133

    Reviewing that paper, it appears to me that the example beginning at the bottom of page 397, where the alternatives are interacted with gender, may give you some guidance.

    Comment

    Working...
    X