Announcement

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

  • random effects in 'mlogit' (no panel data)

    Hi All,

    I have a multinomial (categorical) response variable and I am using 'mlogit' command to estimate a model. Can I estimate random individual effect despite not having panel data?

    Regards,
    Phani

  • #2
    Your question can be answered on two levels.

    1. Theoretical. You don't have to have panel data per se to use random effects. You just need multi-level data, which could be things like individual observations nested in geographic regions or organizations, etc.

    2. Implementation. There is no estimation command for multinomial logistic regression with random effects in official Stata. I am also unaware of any user-written programs to do this, but if somebody else knows of one, I hope he or she will chime in.

    Comment


    • #3
      Dear Clyde,

      Thank you very much. I can now search for alternative software(s) that can handle this.

      Regards,
      Phani

      Comment


      • #4
        Hi Clyde and Phani,

        In Stata, random effects, or more generally, multilevel multinomial logit models can be fit using the gsem command. For example:

        Code:
        . * Toy data:
        . clear
        . set seed 1234
        . set obs 200
        number of observations (_N) was 0, now 200
        
        . gen id = _n
        . mat C  = (1,0.5,1)
        . drawnorm v2 v3, corr(C) cstorage(upper)
        . expand 50
        (9,800 observations created)
        
        . gen double x1  = runiform()
        . gen double x2  = runiform()
        . gen double xb2 = -1 + 0.30*x1 + 0.75*x2 + v2
        . gen double xb3 =  1 - 0.30*x1 + 0.50*x2 + v3
        . gen double p1  = 1/(1 + exp(xb2) + exp(xb3))
        . gen double p2  = exp(xb2)/(1 + exp(xb2) + exp(xb3))
        . gen double p3  = exp(xb3)/(1 + exp(xb2) + exp(xb3))
        . gen double U   = runiform()
        . gen int    y   = cond(U < p1, 1, cond(U < p1 + p2, 2, 3))
        . 
        . * 2-level random effects multinomial logit with common variance component:
        . gsem (i.y <- x1 x2 M1[id]@1), mlogit
        
        Fitting fixed-effects model:
        
        Iteration 0:   log likelihood = -9483.1709  
        Iteration 1:   log likelihood = -9432.8833  
        Iteration 2:   log likelihood = -9432.7378  
        Iteration 3:   log likelihood = -9432.7378  
        
        Refining starting values:
        
        Grid node 0:   log likelihood = -8997.4235
        
        Fitting full model:
        
        Iteration 0:   log likelihood = -8997.4235  
        Iteration 1:   log likelihood = -8992.9794  
        Iteration 2:   log likelihood = -8992.2502  
        Iteration 3:   log likelihood = -8992.2445  
        Iteration 4:   log likelihood = -8992.2445  
        
        Generalized structural equation model           Number of obs     =     10,000
        Response       : y
        Base outcome   : 1
        Family         : multinomial
        Link           : logit
        Log likelihood = -8992.2445
        
         ( 1)  [2.y]M1[id] = 1
         ( 2)  [3.y]M1[id] = 1
        ------------------------------------------------------------------------------
                     |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
        1.y          |  (base outcome)
        -------------+----------------------------------------------------------------
        2.y          |
                  x1 |   .3379587   .1169641     2.89   0.004     .1087133    .5672041
                  x2 |   1.001778   .1173906     8.53   0.000     .7716967    1.231859
                     |
              M1[id] |          1  (constrained)
                     |
               _cons |  -.8220507   .1139486    -7.21   0.000    -1.045386   -.5987157
        -------------+----------------------------------------------------------------
        3.y          |
                  x1 |  -.2226142   .0910412    -2.45   0.014    -.4010517   -.0441766
                  x2 |   .6243208   .0917941     6.80   0.000     .4444076     .804234
                     |
              M1[id] |          1  (constrained)
                     |
               _cons |    .934252   .0961452     9.72   0.000      .745811    1.122693
        -------------+----------------------------------------------------------------
          var(M1[id])|   .8809435   .1096691                      .6902105    1.124384
        ------------------------------------------------------------------------------
        . 
        . * 2-level model with separate uncorrelated random effects:
        . gsem (2.y <- x1 x2 M1[id]) (3.y <- x1 x2 M2[id]), cov(M1[id]*M2[id]@0) mlogit
        
        Fitting fixed-effects model:
        
        Iteration 0:   log likelihood = -9483.1709  
        Iteration 1:   log likelihood = -9432.8833  
        Iteration 2:   log likelihood = -9432.7378  
        Iteration 3:   log likelihood = -9432.7378  
        
        Refining starting values:
        
        Grid node 0:   log likelihood = -8641.9587
        
        Fitting full model:
        
        Iteration 0:   log likelihood = -8641.9587  
        Iteration 1:   log likelihood = -8637.8922  
        Iteration 2:   log likelihood =  -8637.852  
        Iteration 3:   log likelihood =  -8637.852  
        
        Generalized structural equation model           Number of obs     =     10,000
        Response       : y
        Base outcome   : 1
        Family         : multinomial
        Link           : logit
        Log likelihood =  -8637.852
        
         ( 1)  [2.y]M1[id] = 1
         ( 2)  [3.y]M2[id] = 1
        ------------------------------------------------------------------------------
                     |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
        1.y          |  (base outcome)
        -------------+----------------------------------------------------------------
        2.y          |
                  x1 |   .4104958   .1180102     3.48   0.001     .1792001    .6417915
                  x2 |   1.006316   .1186719     8.48   0.000     .7737231    1.238908
                     |
              M1[id] |          1  (constrained)
                     |
               _cons |  -1.180582   .1191947    -9.90   0.000      -1.4142   -.9469649
        -------------+----------------------------------------------------------------
        3.y          |
                  x1 |  -.2687413   .0918692    -2.93   0.003    -.4488016   -.0886809
                  x2 |   .5827684   .0924362     6.30   0.000     .4015968      .76394
                     |
              M2[id] |          1  (constrained)
                     |
               _cons |   .9045162   .0989384     9.14   0.000     .7106005    1.098432
        -------------+----------------------------------------------------------------
          var(M1[id])|   .9828318   .1397224                      .7438233     1.29864
          var(M2[id])|   .9817449   .1174514                      .7765418    1.241173
        ------------------------------------------------------------------------------
        . 
        . * 2-level model with separate correlated random effects: 
        . gsem (2.y <- x1 x2 M1[id]) (3.y <- x1 x2 M2[id]), mlogit
        
        Fitting fixed-effects model:
        
        Iteration 0:   log likelihood = -9483.1709  
        Iteration 1:   log likelihood = -9432.8833  
        Iteration 2:   log likelihood = -9432.7378  
        Iteration 3:   log likelihood = -9432.7378  
        
        Refining starting values:
        
        Grid node 0:   log likelihood = -8641.9587
        
        Fitting full model:
        
        Iteration 0:   log likelihood = -8641.9587  
        Iteration 1:   log likelihood = -8631.1745  
        Iteration 2:   log likelihood = -8622.0542  
        Iteration 3:   log likelihood = -8621.6876  
        Iteration 4:   log likelihood =  -8621.686  
        Iteration 5:   log likelihood =  -8621.686  
        
        Generalized structural equation model           Number of obs     =     10,000
        Response       : y
        Base outcome   : 1
        Family         : multinomial
        Link           : logit
        Log likelihood =  -8621.686
        
         ( 1)  [2.y]M1[id] = 1
         ( 2)  [3.y]M2[id] = 1
        ------------------------------------------------------------------------------
                     |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
        1.y          |  (base outcome)
        -------------+----------------------------------------------------------------
        2.y          |
                  x1 |   .4000091   .1184321     3.38   0.001     .1678864    .6321319
                  x2 |   1.019196   .1191293     8.56   0.000     .7857068    1.252685
                     |
              M1[id] |          1  (constrained)
                     |
               _cons |  -1.108902   .1215729    -9.12   0.000     -1.34718   -.8706231
        -------------+----------------------------------------------------------------
        3.y          |
                  x1 |  -.2673496   .0923936    -2.89   0.004    -.4484376   -.0862615
                  x2 |   .5992371   .0930305     6.44   0.000     .4169007    .7815734
                     |
              M2[id] |          1  (constrained)
                     |
               _cons |   .9290522    .102277     9.08   0.000     .7285929    1.129512
        -------------+----------------------------------------------------------------
          var(M1[id])|   1.057072   .1462123                      .8060612    1.386249
          var(M2[id])|   1.094853   .1325752                      .8635433    1.388121
        -------------+----------------------------------------------------------------
          cov(M1[id],|
              M2[id])|   .5123288   .1083916     4.73   0.000     .2998851    .7247725
        ------------------------------------------------------------------------------
        There is also an example in the [SEM] manual which discusses this in more detail (example 41g in here: https://www.stata.com/manuals/semtoc.pdf).

        Joerg

        Comment


        • #5
          , while I have not personally fit one yet, I am glad to report that multinomial regression models with random effects can be fit in Stata under -gsem-.

          Here is a Stata blog post, and SEM example 41. Phani, do note the warnings in the post that these models can take quite some time to fit. Also, in general, do be aware that more complex random effect models can have trouble reaching convergence. SEM intro 12 and the -mixed- manual offer some pointers on how to resolve convergence issues. Feel free to ask here if you can't resolve or understand something, but be aware that we may not have an easy solution either.
          Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

          When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

          Comment


          • #6
            Thank you very much Joerg and Weiwen.

            I have been trying the gsem command but as Weiwen pointed out, it is taking for ever. I even used "difficult" to overcome the 'not concave' problem. The model is still running (after 5days of starting) and is into 1000s of iterations.

            Comment


            • #7
              Originally posted by Phani Chintakayala View Post
              Thank you very much Joerg and Weiwen.

              I have been trying the gsem command but as Weiwen pointed out, it is taking for ever. I even used "difficult" to overcome the 'not concave' problem. The model is still running (after 5days of starting) and is into 1000s of iterations.
              Phani, if you have a repeated string of iterations with the not concave message, and your model has been running for a long time without the log-likelihood changing visibly, then the log likelihood function is not concave at that point. That can happen if your model is not identified - I can't easily explain what not identified means, but the SEM manual does describe it better than I can. If the model isn't identified, then it may be that you have to simplify the model. I have no good advice without seeing the commands you are trying to run. However, say you ran your model and at about 100 iterations, your log likelihood hit an asymptote. One thing you can do is to tell gsem to run that many iterations only, then examine the parameter list. If the standard error of a parameter is missing, there was a problem with that parameter. That can help diagnose identification problems ... maybe. For example, continuing from Joerg's syntax:

              Code:
              gsem (2.y <- x1 x2 M1[id]) (3.y <- x1 x2 M2[id]), cov(M1[id]*M2[id]@0) mlogit iterate(100)
              Alternatively, it could simply be a case of bad start values, as outlined in intro 12. I don't have personal experience with multinomial random effects logit, but for latent class models, its known that the likelihood function often has many local maxima, and we are strongly advised to use multiple random starts.

              One thing you can do is this. Does your model converge with mlogit? If so, save the parameter estimate in a matrix. For example, continuing from Joerg's syntax:

              Code:
              mlogit y x1 x2
              mat b = e(b)
              gsem (2.y <- x1 x2 M1[id]) (3.y <- x1 x2 M2[id]), cov(M1[id]*M2[id]@0) mlogit from(b)
              That tells gsem to start its likelihood maximization from the parameters of the plain multinomial logit model. This can help. Other things you can do are to try the alternative numerical integration methods in sem intro 12. In particular, reduce the number of integration points or use the -intmethod(laplace)- option to produce a preliminary estimate, then re-fit the model with the default integration method (fewer integration points and the Laplacian approximation produce less accurate estimates, but they iterate faster).

              I would recommend reading SEM intro 12. Note that you have a continuous latent variable (your DV is categorical, but you are estimating a latent continuous variable), so you can skip the sections that deal with categorical latent variables. If that doesn't help you, you should post the exact commands you are using, and preferably a sample of your data using -dataex-, which is already installed if you have Stata 15.1, or else you can manually install it from SSC:

              Code:
              ssc install dataex
              Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

              When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

              Comment


              • #8
                Thank you very much Weiwen.

                I am trying your suggestions. Will update the progress.

                Regards,
                Phani

                Comment


                • #9
                  Hi Joerg and Weiwen,

                  Once again thank you very much for your detailed examples and followups.

                  I have run the model mlogit and the gsem with limited iterations. The outputs are below. I would appreciate if you can have a look and suggest where things are going wrong?

                  I have tried using starting values as well but getting an error message (see the last command below).

                  Sorry for the poor formatting.


                  . mlogit choice child transhare abovelimit homeowner caruser cc_issue cc_agree co2_higher lifestyle_change trans_easy short_easy long_easy femployed single male university l
                  > owinc pricepertonne age q25_2 q27_2, b(1)

                  Iteration 0: log likelihood = -972.79178
                  Iteration 1: log likelihood = -743.3975
                  Iteration 2: log likelihood = -711.21758
                  Iteration 3: log likelihood = -709.48164
                  Iteration 4: log likelihood = -709.4566
                  Iteration 5: log likelihood = -709.45657

                  Multinomial logistic regression Number of obs = 834
                  LR chi2(63) = 526.67
                  Prob > chi2 = 0.0000
                  Log likelihood = -709.45657 Pseudo R2 = 0.2707

                  ----------------------------------------------------------------------------------
                  choice | Coef. Std. Err. z P>|z| [95% Conf. Interval]
                  -----------------+----------------------------------------------------------------
                  1 | (base outcome)
                  -----------------+----------------------------------------------------------------
                  2 |
                  child | -.6702093 .4255564 -1.57 0.115 -1.504284 .163866
                  transhare | 3.067716 .7291656 4.21 0.000 1.638578 4.496854
                  abovelimit | .8423101 .5426126 1.55 0.121 -.221191 1.905811
                  homeowner | -.2946713 .3206441 -0.92 0.358 -.9231223 .3337796
                  caruser | .2463197 .312541 0.79 0.431 -.3662493 .8588887
                  cc_issue | 1.046795 .3545495 2.95 0.003 .3518903 1.741699
                  cc_agree | -.0571075 .4169075 -0.14 0.891 -.8742312 .7600162
                  co2_higher | .0525444 .3024596 0.17 0.862 -.5402656 .6453544
                  lifestyle_change | .4034689 .3133155 1.29 0.198 -.2106182 1.017556
                  trans_easy | .9349785 .4227753 2.21 0.027 .1063541 1.763603
                  short_easy | .1502776 .4566217 0.33 0.742 -.7446845 1.04524
                  long_easy | 1.156375 .4296224 2.69 0.007 .3143307 1.99842
                  femployed | .2924719 .3461332 0.84 0.398 -.3859368 .9708805
                  single | .2612598 .3448956 0.76 0.449 -.4147231 .9372427
                  male | -1.109306 .29848 -3.72 0.000 -1.694316 -.5242959
                  university | -.6193263 .2989415 -2.07 0.038 -1.205241 -.0334116
                  lowinc | .1527425 .3423694 0.45 0.656 -.5182892 .8237741
                  pricepertonne | .0022177 .0017115 1.30 0.195 -.0011367 .0055721
                  age | .0143827 .0139368 1.03 0.302 -.0129329 .0416983
                  q25_2 | .3901725 .5096967 0.77 0.444 -.6088147 1.38916
                  q27_2 | -.9500469 .4747762 -2.00 0.045 -1.880591 -.0195026
                  _cons | -3.452439 1.470041 -2.35 0.019 -6.333667 -.5712118
                  -----------------+----------------------------------------------------------------
                  3 |
                  child | -.4476917 .4413991 -1.01 0.310 -1.312818 .4174346
                  transhare | -.9156164 .6927932 -1.32 0.186 -2.273466 .4422334
                  abovelimit | .3231469 .3979076 0.81 0.417 -.4567376 1.103031
                  homeowner | -.1560867 .3267769 -0.48 0.633 -.7965576 .4843842
                  caruser | -2.661261 .4717683 -5.64 0.000 -3.58591 -1.736612
                  cc_issue | 1.382853 .3635148 3.80 0.000 .6703775 2.095329
                  cc_agree | -.2444373 .4085163 -0.60 0.550 -1.045115 .5562399
                  co2_higher | -.353841 .3111466 -1.14 0.255 -.9636772 .2559952
                  lifestyle_change | -.8452457 .35125 -2.41 0.016 -1.533683 -.1568083
                  trans_easy | 1.358544 .4043511 3.36 0.001 .5660299 2.151057
                  short_easy | -.5114854 .4539472 -1.13 0.260 -1.401206 .3782347
                  long_easy | .6518412 .4312856 1.51 0.131 -.1934631 1.497145
                  femployed | .0283343 .3486515 0.08 0.935 -.6550101 .7116786
                  single | .718275 .3382603 2.12 0.034 .0552971 1.381253
                  male | -.6527046 .3020304 -2.16 0.031 -1.244673 -.060736
                  university | -.5339491 .2995976 -1.78 0.075 -1.12115 .0532513
                  lowinc | -.454321 .3371815 -1.35 0.178 -1.115185 .2065425
                  pricepertonne | .004285 .0016935 2.53 0.011 .0009659 .0076041
                  age | -.0109512 .0133928 -0.82 0.414 -.0372006 .0152983
                  q25_2 | -.8594064 .4561301 -1.88 0.060 -1.753405 .0345923
                  q27_2 | -.8073489 .4545005 -1.78 0.076 -1.698154 .0834557
                  _cons | 3.131066 1.288969 2.43 0.015 .6047325 5.6574
                  -----------------+----------------------------------------------------------------
                  4 |
                  child | -.5684425 .2949556 -1.93 0.054 -1.146545 .0096598
                  transhare | 3.019954 .5280011 5.72 0.000 1.985091 4.054817
                  abovelimit | .7809854 .348545 2.24 0.025 .0978498 1.464121
                  homeowner | .4874809 .2412865 2.02 0.043 .0145681 .9603936
                  caruser | .5060365 .229572 2.20 0.028 .0560835 .9559894
                  cc_issue | .8934858 .24259 3.68 0.000 .4180182 1.368953
                  cc_agree | .4550151 .2834697 1.61 0.108 -.1005753 1.010606
                  co2_higher | .400327 .2172683 1.84 0.065 -.025511 .8261651
                  lifestyle_change | -.2072331 .2319815 -0.89 0.372 -.6619086 .2474423
                  trans_easy | 1.391921 .3314683 4.20 0.000 .7422548 2.041586
                  short_easy | .1526381 .3492608 0.44 0.662 -.5319005 .8371767
                  long_easy | .9196663 .3335019 2.76 0.006 .2660145 1.573318
                  femployed | .1042191 .2465637 0.42 0.673 -.3790368 .587475
                  single | .3235724 .2532223 1.28 0.201 -.1727343 .8198791
                  male | -.8603054 .2163054 -3.98 0.000 -1.284256 -.4363546
                  university | -.2771929 .2128974 -1.30 0.193 -.6944642 .1400784
                  lowinc | -.1233201 .2480652 -0.50 0.619 -.609519 .3628789
                  pricepertonne | .0022619 .0012346 1.83 0.067 -.0001579 .0046818
                  age | .0005356 .0100014 0.05 0.957 -.0190667 .0201379
                  q25_2 | -.6927403 .3514541 -1.97 0.049 -1.381578 -.0039028
                  q27_2 | -.6127836 .358989 -1.71 0.088 -1.316389 .0908219
                  _cons | -.7322576 1.027276 -0.71 0.476 -2.745681 1.281166
                  ----------------------------------------------------------------------------------


                  . gsem(2.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.university i.lowinc pricepertonne tra
                  > nshare age i.q25_2 i.q27_2 M2[URN2]@1)(3.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.uni
                  > versity i.lowinc pricepertonne transhare age i.q25_2 i.q27_2 M3[URN2]@1)(4.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifesty
                  > le_change i.femployed i.male i.university i.lowinc pricepertonne transhare age i.q25_2 i.q27_2 M4[URN2]@1), mlogit difficult iterate(20)

                  Fitting fixed-effects model:

                  Iteration 0: log likelihood = -972.79178
                  Iteration 1: log likelihood = -770.68413
                  Iteration 2: log likelihood = -745.10525
                  Iteration 3: log likelihood = -743.38677
                  Iteration 4: log likelihood = -743.36456
                  Iteration 5: log likelihood = -743.36456

                  Refining starting values:

                  Grid node 0: log likelihood = -752.54186

                  Fitting full model:

                  Iteration 0: log likelihood = -752.54186 (not concave)
                  Iteration 1: log likelihood = -744.28394 (not concave)
                  Iteration 2: log likelihood = -744.05177 (not concave)
                  Iteration 3: log likelihood = -744.03685 (not concave)
                  Iteration 4: log likelihood = -744.03519 (not concave)
                  Iteration 5: log likelihood = -744.03513 (not concave)
                  Iteration 6: log likelihood = -744.03513 (not concave)
                  Iteration 7: log likelihood = -744.03513 (not concave)
                  Iteration 8: log likelihood = -744.03513 (not concave)
                  Iteration 9: log likelihood = -744.03513 (not concave)
                  Iteration 10: log likelihood = -743.54491 (not concave)
                  Iteration 11: log likelihood = -743.52123 (not concave)
                  Iteration 12: log likelihood = -743.52069 (not concave)
                  Iteration 13: log likelihood = -743.52069 (not concave)
                  Iteration 14: log likelihood = -743.52069 (not concave)
                  Iteration 15: log likelihood = -743.52069 (not concave)
                  Iteration 16: log likelihood = -743.52069 (not concave)
                  Iteration 17: log likelihood = -743.52069 (not concave)
                  Iteration 18: log likelihood = -743.52069 (not concave)
                  Iteration 19: log likelihood = -743.52069 (not concave)
                  Iteration 20: log likelihood = -743.49105 (not concave)
                  convergence not achieved

                  Generalized structural equation model Number of obs = 834
                  Response : choice
                  Base outcome : 1
                  Family : multinomial
                  Link : logit
                  Log likelihood = -743.49105

                  ( 1) [2.choice]M2[URN2] = 1
                  ( 2) [3.choice]M3[URN2] = 1
                  ( 3) [4.choice]M4[URN2] = 1
                  ---------------------------------------------------------------------------------------
                  | Coef. Std. Err. z P>|z| [95% Conf. Interval]
                  ----------------------+----------------------------------------------------------------
                  1.choice | (base outcome)
                  ----------------------+----------------------------------------------------------------
                  2.choice <- |
                  |
                  1.child | -.5745745 .5368495 -1.07 0.284 -1.62678 .4776312
                  1.abovelimit | 1.076575 .7796107 1.38 0.167 -.4514338 2.604584
                  1.homeowner | -.5361769 .5383969 -1.00 0.319 -1.591415 .5190617
                  1.caruser | .1561492 .812012 0.19 0.848 -1.435365 1.747664
                  1.cc_issue | .944307 .5591366 1.69 0.091 -.1515806 2.040195
                  1.cc_agree | .1239853 .4955685 0.25 0.802 -.8473111 1.095282
                  1.co2_higher | .1960819 .3934962 0.50 0.618 -.5751565 .9673203
                  1.lifestyle_change | .6437028 .7946539 0.81 0.418 -.9137903 2.201196
                  1.femployed | .3425526 .4707067 0.73 0.467 -.5800156 1.265121
                  1.male | -1.068669 .6334292 -1.69 0.092 -2.310167 .1728293
                  1.university | -.7126309 .5169201 -1.38 0.168 -1.725776 .3005139
                  1.lowinc | .2311094 .4288351 0.54 0.590 -.6093919 1.071611
                  pricepertonne | .0021826 .0019032 1.15 0.251 -.0015476 .0059128
                  transhare | 2.857122 2.840905 1.01 0.315 -2.710948 8.425193
                  age | .01098 .0244036 0.45 0.653 -.0368501 .0588101
                  2.q25_2 | .4604545 1.206138 0.38 0.703 -1.903532 2.824441
                  2.q27_2 | -1.218762 .6480967 -1.88 0.060 -2.489008 .0514847
                  |
                  M2[URN2] | 1 (constrained)
                  |
                  _cons | -3.428926 6.215533 -0.55 0.581 -15.61115 8.753296
                  ----------------------+----------------------------------------------------------------
                  3.choice <- |
                  |
                  1.child | -.4770461 .5827709 -0.82 0.413 -1.619256 .6651639
                  1.abovelimit | .6927774 .429493 1.61 0.107 -.1490133 1.534568
                  1.homeowner | -.3781288 .3492446 -1.08 0.279 -1.062636 .3063779
                  1.caruser | -2.79726 .4867707 -5.75 0.000 -3.751313 -1.843207
                  1.cc_issue | 1.385589 .3925238 3.53 0.000 .6162568 2.154922
                  1.cc_agree | -.1169838 .4539129 -0.26 0.797 -1.006637 .772669
                  1.co2_higher | -.248693 .3326444 -0.75 0.455 -.900664 .4032781
                  1.lifestyle_change | -.725876 .486158 -1.49 0.135 -1.678728 .2269762
                  1.femployed | .0633472 .4913761 0.13 0.897 -.8997322 1.026427
                  1.male | -.61633 .4946735 -1.25 0.213 -1.585872 .3532121
                  1.university | -.5635089 .3819358 -1.48 0.140 -1.312089 .1850715
                  1.lowinc | -.3423981 .3951506 -0.87 0.386 -1.116879 .4320829
                  pricepertonne | .0040585 .0018178 2.23 0.026 .0004956 .0076213
                  transhare | -1.59617 .7793406 -2.05 0.041 -3.12365 -.0686907
                  age | -.0156347 .0144058 -1.09 0.278 -.0438695 .0126002
                  2.q25_2 | -1.110334 .6261445 -1.77 0.076 -2.337555 .1168864
                  2.q27_2 | -.8321763 .5218536 -1.59 0.111 -1.854991 .190638
                  |
                  M3[URN2] | 1 (constrained)
                  |
                  _cons | 2.428503 1.086617 2.23 0.025 .298773 4.558233
                  ----------------------+----------------------------------------------------------------
                  4.choice <- |
                  |
                  1.child | -.4573072 .3024271 -1.51 0.131 -1.050053 .135439
                  1.abovelimit | 1.053518 .3618148 2.91 0.004 .3443744 1.762662
                  1.homeowner | .2462972 .2770404 0.89 0.374 -.296692 .7892864
                  1.caruser | .3636723 .2432642 1.49 0.135 -.1131167 .8404613
                  1.cc_issue | .8131997 .2647287 3.07 0.002 .2943409 1.332058
                  1.cc_agree | .6572609 .2925979 2.25 0.025 .0837796 1.230742
                  1.co2_higher | .5782237 .2192846 2.64 0.008 .1484339 1.008014
                  1.lifestyle_change | -.0247444 .2934482 -0.08 0.933 -.5998923 .5504035
                  1.femployed | .138994 .260578 0.53 0.594 -.3717294 .6497175
                  1.male | -.801521 .2394289 -3.35 0.001 -1.270793 -.3322489
                  1.university | -.3948654 .2266963 -1.74 0.082 -.839182 .0494513
                  1.lowinc | -.049779 .2570425 -0.19 0.846 -.553573 .454015
                  pricepertonne | .002324 .0012582 1.85 0.065 -.0001421 .0047901
                  transhare | 2.596585 .5854405 4.44 0.000 1.449143 3.744027
                  age | -.0037703 .0105063 -0.36 0.720 -.0243623 .0168217
                  2.q25_2 | -.7630965 .387437 -1.97 0.049 -1.522459 -.0037339
                  2.q27_2 | -.9085697 .3651722 -2.49 0.013 -1.624294 -.1928454
                  |
                  M4[URN2] | 1 (constrained)
                  |
                  _cons | -.8485708 .8332659 -1.02 0.309 -2.481742 .7846003
                  ----------------------+----------------------------------------------------------------
                  var(M2[URN2])| .6964736 7.817174 1.95e-10 2.49e+09
                  var(M3[URN2])| .9238516 . . .
                  var(M4[URN2])| .3543106 . . .
                  ----------------------+----------------------------------------------------------------
                  cov(M3[URN2],M2[URN2])| .0938603 4.817104 0.02 0.984 -9.347491 9.535211
                  cov(M4[URN2],M2[URN2])| .1657754 2.797194 0.06 0.953 -5.316623 5.648174
                  cov(M4[URN2],M3[URN2])| .555704 . . . . .
                  ---------------------------------------------------------------------------------------
                  Warning: convergence not achieved



                  . gsem(2.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.university i.lowinc pricepertonne tra
                  > nshare age i.q25_2 i.q27_2 M2[URN2])(3.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.unive
                  > rsity i.lowinc pricepertonne transhare age i.q25_2 i.q27_2 M3[URN2])(4.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_c
                  > hange i.femployed i.male i.university i.lowinc pricepertonne transhare age i.q25_2 i.q27_2 M4[URN2]), mlogit difficult from(b)
                  initial vector: extra parameter 1:o.child found
                  specify skip option if necessary
                  r(111);


                  Regards,
                  Phani

                  Comment


                  • #10
                    Phani Chintakayala I forgot to mention, but using the code delimiters like I do will greatly help with readability You access those using the # button on the formatting toolbar. Also, adding line breaks in your code using /// will help, e.g.

                    Code:
                    gsem(2.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.university i.lowinc pricepertonne transhare age i.q25_2 i.q27_2 M2[URN2]) ///
                    (3.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.university i.lowinc pricepertonne transhare age i.q25_2 i.q27_2 M3[URN2]) ///
                    (4.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.university i.lowinc pricepertonne transhare age i.q25_2 i.q27_2 M4[URN2]), mlogit difficult from(b)
                    One immediate question is this. It looks like you went right to fitting separate random effects for each of the multinomial equations. I know that Joerg's example and Stata's stock example (example 41) show you how to do so, but that doesn't mean you must do so. The simpler model is the one in the first half of both examples, where there's only one random effect for each cluster. Because of the missing standard errors for the variances of M3 and M4, and the covariance of M3 and M4, it looks like SEM is having some difficulty estimating them. I don't know why. But try the simpler random effects model first and see if that estimates:

                    Code:
                    gsem(i.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.university i.lowinc pricepertonne transhare age i.q25_2 i.q27_2 M1[URN2]@1), mlogit
                    If that converges, I would probably try your code with separate but uncorrelated random effects.

                    Another hint is that you can store your list of covariates in a local macro, then call the macro in each level of the equation. You must run the entire block of code at once:

                    Code:
                    local indepvars "i.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.university i.lowinc pricepertonne transhare age i.q25_2 i.q27_2"
                    gsem (2.choice <- `indepvars' M2[URN2]) ///
                    (3.choice <- `indepvars' M3[URN2])
                    (4.choice <- `indepvars' M4[URN2]),
                    mlogit covstructure(M2[URN2] M3[URN2] M4[URN2], diagonal)
                    In the -covstructure- option, imagine the variance-covariance matrix of M2, M3, and M4. The diagonal of the matrix is the variance of each variable. All the off-diagonal entries are the covariances. In the diagonal structure, you tell Stata to assume the off-diagonal entries are all 0, i.e. uncorrelated random effects. If you don't know what this means, just know that this option will give you uncorrelated random effects (if I typed it correctly, although I did verify the syntax on the data from SEM example 41).
                    Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

                    When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

                    Comment


                    • #11
                      Thank you Weiwen. Apologies again for the poor formatting earlier.


                      I tried the code below i.e. the simpler model. It did work.


                      Code:
                      .
                      gsem(i.choice <- i.child i.abovelimit i.homeowner i.caruser i.cc_issue i.cc_agree i.co2_higher i.lifestyle_change i.femployed i.male i.university i.lowinc pricepertonne transhare age i.q25_2 i.q27_2 M1[URN2]@1), mlogit



                      Code:
                      Iteration 53:  log likelihood = -743.36456  (backed up)
                      
                      Generalized structural equation model           Number of obs     =        834
                      Response       : choice
                      Base outcome   : 1
                      Family         : multinomial
                      Link           : logit
                      Log likelihood = -743.36456
                      
                       ( 1)  [2.choice]M1[URN2] = 1
                       ( 2)  [3.choice]M1[URN2] = 1
                       ( 3)  [4.choice]M1[URN2] = 1
                      ------------------------------------------------------------------------------------
                                         |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                      -------------------+----------------------------------------------------------------
                      1.choice           |  (base outcome)
                      -------------------+----------------------------------------------------------------
                      2.choice <-        |
                                         |            1.child |  -.5315352   .4107007    -1.29   0.196    -1.336494    .2734233
                            1.abovelimit |    1.02519   .5267238     1.95   0.052    -.0071697     2.05755
                             1.homeowner |  -.4960768   .3067096    -1.62   0.106    -1.097217    .1050629
                               1.caruser |   .1678429   .3036505     0.55   0.580    -.4273011    .7629869
                              1.cc_issue |    .886499   .3460317     2.56   0.010     .2082894    1.564709
                              1.cc_agree |   .1073904     .40784     0.26   0.792    -.6919614    .9067423
                            1.co2_higher |   .2000184   .2943674     0.68   0.497    -.3769311    .7769679
                      1.lifestyle_change |   .6097751   .3059231     1.99   0.046     .0101769    1.209373
                             1.femployed |   .3146472   .3376154     0.93   0.351    -.3470668    .9763611
                                  1.male |  -1.009644   .2913388    -3.47   0.001    -1.580657   -.4386306
                            1.university |  -.6834921   .2928694    -2.33   0.020    -1.257506   -.1094786
                                1.lowinc |    .204935   .3269771     0.63   0.531    -.4359284    .8457983
                           pricepertonne |   .0020721   .0016805     1.23   0.218    -.0012217    .0053659
                               transhare |   2.591455   .6805921     3.81   0.000     1.257519    3.925391
                                     age |   .0084683   .0133605     0.63   0.526    -.0177177    .0346544
                                 2.q25_2 |   .3759953   .4921932     0.76   0.445    -.5886857    1.340676
                                 2.q27_2 |  -1.156297   .4581017    -2.52   0.012    -2.054159   -.2584338
                                          |
                                M1[URN2] |          1  (constrained)
                                         |
                                   _cons |  -2.923504   1.133607    -2.58   0.010    -5.145332   -.7016756
                      -------------------+----------------------------------------------------------------
                      3.choice <-        |
                                         |
                                 1.child |  -.4448583   .4299682    -1.03   0.301     -1.28758    .3978638
                            1.abovelimit |   .6240957   .3789555     1.65   0.100    -.1186435    1.366835
                             1.homeowner |  -.3615811   .3114134    -1.16   0.246    -.9719402     .248778
                               1.caruser |  -2.692243   .4670866    -5.76   0.000    -3.607716    -1.77677
                              1.cc_issue |   1.249884   .3516178     3.55   0.000     .5607261    1.939043
                              1.cc_agree |  -.1207761   .3947547    -0.31   0.760     -.894481    .6529289
                            1.co2_higher |   -.233319   .3032729    -0.77   0.442    -.8277228    .3610849
                      1.lifestyle_change |  -.6466193    .341124    -1.90   0.058     -1.31521    .0219715
                             1.femployed |   .0745229   .3438946     0.22   0.828    -.5994982    .7485439
                                  1.male |  -.5602599   .2944052    -1.90   0.057    -1.137283    .0167637
                            1.university |  -.5165761   .2894679    -1.78   0.074    -1.083923    .0507705
                                1.lowinc |  -.2882295   .3254283    -0.89   0.376    -.9260573    .3495983
                           pricepertonne |   .0037482   .0016497     2.27   0.023     .0005149    .0069815
                               transhare |  -1.503537   .6638954    -2.26   0.024    -2.804749   -.2023263
                                     age |  -.0137851   .0130641    -1.06   0.291    -.0393901      .01182
                                 2.q25_2 |  -.9891268    .432922    -2.28   0.022    -1.837638   -.1406153
                                 2.q27_2 |  -.7868244   .4380134    -1.80   0.072    -1.645315    .0716661
                                         |
                                M1[URN2] |          1  (constrained)
                                         |
                                   _cons |   2.223947   .9662116     2.30   0.021     .3302073    4.117687
                      -------------------+----------------------------------------------------------------
                      4.choice <-        |
                                         |
                                 1.child |   -.425862   .2782451    -1.53   0.126    -.9712125    .1194884
                            1.abovelimit |    1.00886   .3305441     3.05   0.002     .3610059    1.656715
                             1.homeowner |   .2402929   .2242137     1.07   0.284     -.199158    .6797437
                               1.caruser |   .3982692   .2180805     1.83   0.068    -.0291606    .8256991
                              1.cc_issue |   .7536584   .2298646     3.28   0.001      .303132    1.204185
                              1.cc_agree |    .617762   .2698176     2.29   0.022     .0889293    1.146595
                            1.co2_higher |   .5552985   .2068411     2.68   0.007     .1498973    .9606996
                      1.lifestyle_change |   .0012199   .2209093     0.01   0.996    -.4317543    .4341941
                             1.femployed |   .1322656   .2357174     0.56   0.575     -.329732    .5942633
                                  1.male |  -.7587343   .2060615    -3.68   0.000    -1.162608   -.3548611
                            1.university |  -.3782955   .2040249    -1.85   0.064     -.778177     .021586
                                1.lowinc |  -.0430843   .2309973    -0.19   0.852    -.4958306     .409662
                           pricepertonne |   .0021811   .0011869     1.84   0.066    -.0001452    .0045074
                               transhare |    2.50183    .481958     5.19   0.000     1.557209     3.44645
                                     age |  -.0039324    .009478    -0.41   0.678    -.0225089    .0146441
                                 2.q25_2 |  -.7197268   .3291605    -2.19   0.029    -1.364869   -.0745841
                                 2.q27_2 |  -.8720946   .3389683    -2.57   0.010     -1.53646    -.207729
                                         |
                                M1[URN2] |          1  (constrained)
                                         |
                                   _cons |  -.8712751    .764658    -1.14   0.255    -2.369977     .627427
                      -------------------+----------------------------------------------------------------
                            var(M1[URN2])|   6.16e-33   2.07e-17                             .           .
                      ------------------------------------------------------------------------------------
                      I am keen to get the results with the other models and currently, I am trying the uncorrelated one. If it fails, I presume I can still survive with the simpler model.

                      I tried the # as well for formatting. Hope it works.

                      Thank you once again. You and Joerg have been very helpful.

                      Regards,
                      Phani

                      Comment


                      • #12
                        One of the things that strikes me is the variance of the random effect: 6.16e-33, which is basically 0. This is often the cause of non-convergence. One thing that often helps is to center the continuous explanatory variable at some reasonable value within the range of the data. If you don't know a reasonable value you can choose the mean, but I prefer a substantively meaningful value over the mean.
                        ---------------------------------
                        Maarten L. Buis
                        University of Konstanz
                        Department of history and sociology
                        box 40
                        78457 Konstanz
                        Germany
                        http://www.maartenbuis.nl
                        ---------------------------------

                        Comment


                        • #13
                          Thank you Maarten, Apologies, I don't understand what you mean by 'center the continuous explanatory variable at some reasonable value within the range of the data'. Could you please be a bit more elaborate (probably with an example)?

                          Regards,
                          Phani

                          Comment


                          • #14
                            Originally posted by Phani Chintakayala View Post
                            [CODE]
                            Iteration 53: log likelihood = -743.36456 (backed up)

                            ...
                            -------------------+----------------------------------------------------------------
                            var(M1[URN2])| 6.16e-33 2.07e-17 . .
                            ------------------------------------------------------------------------------------
                            Phani, if iteration 53 was the last iteration, then unfortunately the model probably did not converge properly. The manual entry on maximization says this about a "backed up" message at the last iteration:

                            One is that Stata found a perfect maximum and could not step to a better point; if this is the case, all is fine, but this is a highly unlikely occurrence. The second is that the optimizer worked itself into a bad concave spot where the computed gradient and Hessian gave a bad direction for stepping.
                            The gradient, I believe, is the gradient of the log-likelihood with respect to each parameter. I think that gsem actually outputs the gradient vector in e(gradient). You can inspect that to see which parameters have a gradient that is not close to 0:

                            Code:
                            matrix list e(gradient)
                            But I think there's no need to. As Maarten pointed out, the variance of the random intercept is essentially zero (so chances are, this is the parameter which was not converging and messing everything up). This could mean that you did not need to fit a random intercept model, or it could be worth investigating further. I will let him explain his recommendation for that, because I'd be interested to hear it myself (i.e. I haven't done this myself, so I would love to know how it would help).
                            Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

                            When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

                            Comment

                            Working...
                            X