Announcement

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

  • Marginal effect after cmmixlogit

    Dear collegues,

    I'm currently working on a consumers survey. In this survey, we asked consumers to rank their preferred labelling scheme among a pool of nine alternatives (and a no-alternative option). For each consumers, we thus have their most prefered option among 10.

    After that, I wanted to analyse the answers provided to better understand how consumers' preferences are structured. To do so, i used the cmmixlogit command.

    My data are organised as follow :

    Click image for larger version

Name:	HAM.png
Views:	1
Size:	30.5 KB
ID:	1707854


    - ID identifies each respondent (here, i present data only for my first two respondents)
    - Rang: Equal to 1 for the chosen option, otherwise equal to 0
    - Alternatives = Associated alternatives
    - The remaining variables are related to individual characteristics.

    For exemple, my first respondent ranked the health allegation as his/her favourite scheme. The second consumer did the same.

    I used the followind code line to launched my mixed logit choice model

    Code:
    cmset ID alternatives
    cmmixlogit rang, casevars(i.recode_age i.genre deplittoral prix_crit enfant univ tradi prefgeo) basealternative (10)
    I get consistent results. But after this step, i want to measure the marginal effect of explanatory variables on the preference expressed.

    I thus tried to use first the following command

    Code:
    margins, dydx(*)
    Unfortunately, I get the following error message :

    alternative Com.equi is not in the fitted model; error in option outcome()
    r(458);

    I then tried to used the same command, but using only one explanatory variable

    Code:
    margins, dydx(prix_crit)
    I also get an error message :

    no cases remain after removing invalid observations
    r(2000);


    So I'm unable to analyse my marginal effects, and I don't see how to get around these problems. Has anyone had this problem before? Do you have any potential solutions for me?

    Thank you in advance for your time

    Best regards

    Jean-François




  • #2
    Is alternatives a string variable? If so, use help encode to create a numeric variable from it, then run your analysis again using the numeric variable. In theory, it is allowed to use a string variable there but there might be something weird about these particular strings, something we will have to look into.

    That said, notice that if you exclusively use case-specific covariates, the mixed logit model boils down to the special case of simple logit. Have a look at the following example, the results from cmmixlogit and mlogit are equivalent:
    Code:
    . webuse inschoice
    (Fictional health insurance data)
    
    . cmset id insurance
    
         Case ID variable: id
    Alternatives variable: insurance
    
    . cmmixlogit choice, casevars(income)
    
    Fitting fixed parameter model:
    
    Fitting full model:
    
    Iteration 0:   log likelihood = -394.22042  
    Iteration 1:   log likelihood = -394.22042  
    
    Mixed logit choice model                       Number of obs      =      1,250
    Case ID variable: id                           Number of cases    =        250
    
    Alternatives variable: insurance               Alts per case: min =          5
                                                                  avg =        5.0
                                                                  max =          5
    
    Integration points:              0                Wald chi2(4)    =       5.25
    Log likelihood =        -394.22042                Prob > chi2     =     0.2629
    
    ------------------------------------------------------------------------------
          choice | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    Health       |
          income |   .0762443   .1333404     0.57   0.567    -.1850981    .3375868
           _cons |  -.6201366   .7138245    -0.87   0.385    -2.019207    .7789337
    -------------+----------------------------------------------------------------
    HCorp        |  (base alternative)
    -------------+----------------------------------------------------------------
    SickInc      |
          income |  -.1176294    .129578    -0.91   0.364    -.3715976    .1363388
           _cons |   .4319901   .6677559     0.65   0.518    -.8767873    1.740768
    -------------+----------------------------------------------------------------
    MGroup       |
          income |  -.1652967   .1353851    -1.22   0.222    -.4306466    .1000531
           _cons |   .5032474   .6894884     0.73   0.465     -.848125     1.85462
    -------------+----------------------------------------------------------------
    MoonHealth   |
          income |  -.2203374   .1508352    -1.46   0.144    -.5159689    .0752941
           _cons |   .4075541   .7539384     0.54   0.589    -1.070138    1.885246
    ------------------------------------------------------------------------------
    
    . mlogit insurance income if choice == 1
    
    Iteration 0:   log likelihood = -396.92859  
    Iteration 1:   log likelihood = -394.22974  
    Iteration 2:   log likelihood = -394.22042  
    Iteration 3:   log likelihood = -394.22042  
    
    Multinomial logistic regression                         Number of obs =    250
                                                            LR chi2(4)    =   5.42
                                                            Prob > chi2   = 0.2472
    Log likelihood = -394.22042                             Pseudo R2     = 0.0068
    
    ------------------------------------------------------------------------------
       insurance | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    Health       |
          income |   .0762443   .1333404     0.57   0.567    -.1850981    .3375868
           _cons |  -.6201366   .7138245    -0.87   0.385    -2.019207    .7789338
    -------------+----------------------------------------------------------------
    HCorp        |  (base outcome)
    -------------+----------------------------------------------------------------
    SickInc      |
          income |  -.1176294    .129578    -0.91   0.364    -.3715976    .1363388
           _cons |   .4319901   .6677559     0.65   0.518    -.8767873    1.740768
    -------------+----------------------------------------------------------------
    MGroup       |
          income |  -.1652967   .1353851    -1.22   0.222    -.4306466    .1000531
           _cons |   .5032474   .6894884     0.73   0.465     -.848125     1.85462
    -------------+----------------------------------------------------------------
    MoonHealth   |
          income |  -.2203374   .1508352    -1.46   0.144    -.5159689    .0752941
           _cons |   .4075541   .7539384     0.54   0.589    -1.070138    1.885246
    ------------------------------------------------------------------------------

    Comment


    • #3
      Dear Collegues,

      Thanks for your help, I managed to get my marginal effects!

      Best regards,

      Jean-François

      Comment

      Working...
      X