Announcement

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

  • xtmlogit constraints

    How to use constraints with xtmlogit?

    I try to put constraints on the variance of the random effects in the xtmlogit command. I either get error r(111) or r(133). How should it be actually written?

    Best,

    Oivind A Nilsen

    . use https://www.stata-press.com/data/r17/estatus
    . xtset id

    . qui xtmlogit estatus i.hhchild age hhincome i.hhsigno i.bwinner
    . lincom _b[/:var(u1)]
    ( 1) [/]var(u1) = 0
    ------------------------------------------------------------------------------
    estatus | Coefficient Std. err. z P>|z| [95% conf. interval]
    -------------+----------------------------------------------------------------
    (1) | .8587807 .1090216 7.88 0.000 .6451022 1.072459
    ------------------------------------------------------------------------------

    . lincom _b[/:var(u2)]
    ( 1) [/]var(u2) = 0
    ------------------------------------------------------------------------------
    estatus | Coefficient Std. err. z P>|z| [95% conf. interval]
    -------------+----------------------------------------------------------------
    (1) | .7370366 .1388917 5.31 0.000 .4648138 1.009259
    ------------------------------------------------------------------------------

    . lincom _b[/:var(u1)] - _b[/:var(u2)]
    ( 1) [/]var(u1) - [/]var(u2) = 0
    ------------------------------------------------------------------------------
    estatus | Coefficient Std. err. z P>|z| [95% conf. interval]
    -------------+----------------------------------------------------------------
    (1) | .1217441 .1693622 0.72 0.472 -.2101996 .4536879
    ------------------------------------------------------------------------------

    . constraint 1 _b[/:var(u1)] = _b[/:var(u2)]
    . constraint 2 var(u1) = var(u2)

    . xtmlogit estatus i.hhchild age hhincome i.hhsigno i.bwinner, re constraint(1)
    (note: constraint number 1 caused error r(111))
    :
    :

    . xtmlogit estatus i.hhchild age hhincome i.hhsigno i.bwinner, re constraint(2)
    (note: constraint number 2 caused error r(133))

    :
    :

  • #2
    Look at the -covariance()- option:

    Code:
    use https://www.stata-press.com/data/r17/estatus
    xtset id
    xtmlogit estatus i.hhchild age hhincome i.hhsigno i.bwinner, cov(identity)
    Res.:

    Code:
    . xtmlogit estatus i.hhchild age hhincome i.hhsigno i.bwinner, cov(identity)
    
    Fitting comparison model ...
    
    Refining starting values:
    
    Grid node 0:   log likelihood = -4483.1721
    Grid node 1:   log likelihood = -4516.6753
    
    Fitting full model:
    
    Iteration 0:   log likelihood = -4483.1721  
    Iteration 1:   log likelihood = -4470.6708  
    Iteration 2:   log likelihood = -4469.0996  
    Iteration 3:   log likelihood = -4469.0937  
    Iteration 4:   log likelihood = -4469.0937  
    
    Random-effects multinomial logistic regression  Number of obs     =      4,761
    Group variable: id                              Number of groups  =        800
    
    Random effects u_i ~ Gaussian                   Obs per group:
                                                                  min =          5
                                                                  avg =        6.0
                                                                  max =          7
    
    Integration method: mvaghermite                 Integration pts.  =          7
    
                                                    Wald chi2(10)     =     237.67
    Log likelihood  = -4469.0937                    Prob > chi2       =     0.0000
    
     ( 1)  [/]var(u1) - [/]var(u2) = 0
    ------------------------------------------------------------------------------------
               estatus | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------------+----------------------------------------------------------------
    Out_of_labor_force |
               hhchild |
                  Yes  |   .4594018   .0955743     4.81   0.000     .2720795     .646724
                   age |  -.0048037   .0065878    -0.73   0.466    -.0177156    .0081081
              hhincome |  -.0046924   .0018168    -2.58   0.010    -.0082532   -.0011315
                       |
               hhsigno |
                  Yes  |   .4940244   .0942887     5.24   0.000      .309222    .6788268
                       |
               bwinner |
                  Yes  |  -.4725241   .0725275    -6.52   0.000    -.6146754   -.3303729
                 _cons |  -.4714592   .2823061    -1.67   0.095    -1.024769    .0818507
    -------------------+----------------------------------------------------------------
    Unemployed         |
               hhchild |
                  Yes  |  -.0396524    .120952    -0.33   0.743     -.276714    .1974092
                   age |   .0044433   .0083021     0.54   0.593    -.0118285    .0207151
              hhincome |   -.031131   .0026716   -11.65   0.000    -.0363672   -.0258947
                       |
               hhsigno |
                  Yes  |   .0955353    .119958     0.80   0.426    -.1395781    .3306487
                       |
               bwinner |
                  Yes  |    -.22569   .0957551    -2.36   0.018    -.4133666   -.0380133
                 _cons |  -.1076647    .355049    -0.30   0.762     -.803548    .5882186
    -------------------+----------------------------------------------------------------
    Employed           |  (base outcome)
    -------------------+----------------------------------------------------------------
                var(u1)|   .8180218   .0890205                      .6608967    1.012503
                var(u2)|   .8180218   .0890205                      .6608967    1.012503
    ------------------------------------------------------------------------------------
    LR test vs. multinomial logit: chibar2(01) = 224.80   Prob >= chibar2 = 0.0000
    
    .

    Comment


    • #3
      Thanks, Andrew. My questions was really more general. Sorry for not being precise. How to specify a constraint that involve either the two var - var(u1) and var(u2), or the cov(u1,u2) if I had first estimated a xtmlogit.., covariance(unstructured), and then want to run a new xtmlogit based with these new constraints? I'm not able to include constraints based on either the var() or cov().

      Comment


      • #4
        Originally posted by Oivind Nilsen View Post
        I'm not able to include constraints based on either the var() or cov().
        It seems to be a bug. I recommend taking it up with StataCorp's Technical Support

        In the meantime, you can use gsem.
        Code:
        version 17.0
        
        clear *
        
        quietly use https://www.stata-press.com/data/r17/estatus
        
        quietly gsem ///
            (2.estatus <- i.hhchild c.age c.hhincome i.hhsigno i.bwinner M1[id]) ///
            (3.estatus <- i.hhchild c.age c.hhincome i.hhsigno i.bwinner M2[id]), ///
                mlogit ///
                    covariance(M1[id]*M2[id]@0)
        estimates store Unconstrained
        
        *
        * Begin here
        *
        constraint define 1 _b[/var(M1[id])] = _b[/var(M2[id])]
        
        gsem ///
            (2.estatus <- i.hhchild c.age c.hhincome i.hhsigno i.bwinner M1[id]) ///
            (3.estatus <- i.hhchild c.age c.hhincome i.hhsigno i.bwinner M2[id]), ///
                mlogit ///
                    covariance(M1[id]*M2[id]@0) ///
                    constraints(1) ///
                        nocnsreport nodvheader nolog
        lrtest Unconstrained
        
        exit

        Comment


        • #5
          Thanks, Joseph. How do I contact the TechSupport?

          Comment


          • #6
            Originally posted by Oivind Nilsen View Post
            Thanks, Andrew. My questions was really more general. Sorry for not being precise. How to specify a constraint that involve either the two var - var(u1) and var(u2), or the cov(u1,u2) if I had first estimated a xtmlogit.., covariance(unstructured), and then want to run a new xtmlogit based with these new constraints? I'm not able to include constraints based on either the var() or cov().
            I don't think the command will allow you to do that as the covariance options imply some form of constraint on the variances for the random effects.

            vartype Description
            ------------------------------------------------------------------------------------------------
            independent distinct variances for each random effect and all covariances 0;
            the default
            shared one common random effect
            identity equal variances for random effects and all covariances 0
            exchangeable equal variances for random effects and one common pairwise
            covariance
            unstructured all variances and covariances to be distinctly estimated
            But let's see what Tech Support have to say. Follow https://www.stata.com/support/tech-support/contact/ in contacting them and have your license information ready. Also post back with any replies.

            Comment


            • #7
              Hi all, Oivind has uncovered a bug that we will fix in a future update. In the meantime, constraints on variance components can be specified by adding a period after the u in the variance component handle. For example:
              Code:
              . use https://www.stata-press.com/data/r17/estatus
              (Fictional employment status data)
              
              . xtset id
              
              Panel variable: id (unbalanced)
              
              . constraint 1 _b[/:var(u.1)] = _b[/:var(u.2)]
              
              . xtmlogit estatus i.hhchild age hhincome i.hhsigno i.bwinner, re constraint(1)
              
              Fitting comparison model ...
              
              Refining starting values:
              
              Grid node 0:   log likelihood = -4483.1721
              Grid node 1:   log likelihood = -4516.6753
              
              Fitting full model:
              
              Iteration 0:   log likelihood = -4483.1721  
              Iteration 1:   log likelihood = -4470.6708  
              Iteration 2:   log likelihood = -4469.0996  
              Iteration 3:   log likelihood = -4469.0937  
              Iteration 4:   log likelihood = -4469.0937  
              
              Random-effects multinomial logistic regression       Number of obs    =  4,761
              Group variable: id                                   Number of groups =    800
              
              Random effects u_i ~ Gaussian                        Obs per group:
                                                                                min =      5
                                                                                avg =    6.0
                                                                                max =      7
              
              Integration method: mvaghermite                      Integration pts. =      7
              
                                                                   Wald chi2(10)    = 237.67
              Log likelihood = -4469.0937                          Prob > chi2      = 0.0000
              
               ( 1)  [/]var(u1) - [/]var(u2) = 0
              ------------------------------------------------------------------------------
                   estatus | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
              -------------+----------------------------------------------------------------
              Out_of_lab~e |
                   hhchild |
                      Yes  |   .4594018   .0955743     4.81   0.000     .2720795     .646724
                       age |  -.0048037   .0065878    -0.73   0.466    -.0177156    .0081081
                  hhincome |  -.0046924   .0018168    -2.58   0.010    -.0082532   -.0011315
                           |
                   hhsigno |
                      Yes  |   .4940244   .0942887     5.24   0.000      .309222    .6788268
                           |
                   bwinner |
                      Yes  |  -.4725241   .0725275    -6.52   0.000    -.6146754   -.3303729
                     _cons |  -.4714592   .2823061    -1.67   0.095    -1.024769    .0818507
              -------------+----------------------------------------------------------------
              Unemployed   |
                   hhchild |
                      Yes  |  -.0396524    .120952    -0.33   0.743     -.276714    .1974092
                       age |   .0044433   .0083021     0.54   0.593    -.0118285    .0207151
                  hhincome |   -.031131   .0026716   -11.65   0.000    -.0363672   -.0258947
                           |
                   hhsigno |
                      Yes  |   .0955353    .119958     0.80   0.426    -.1395781    .3306487
                           |
                   bwinner |
                      Yes  |    -.22569   .0957551    -2.36   0.018    -.4133666   -.0380133
                     _cons |  -.1076647    .355049    -0.30   0.762     -.803548    .5882186
              -------------+----------------------------------------------------------------
              Employed     |  (base outcome)
              -------------+----------------------------------------------------------------
                    var(u1)|   .8180218   .0890205                      .6608967    1.012503
                    var(u2)|   .8180218   .0890205                      .6608967    1.012503
              ------------------------------------------------------------------------------
              I hope this helps, we apologize for the inconvenience.

              Joerg

              Comment


              • #8
                Great. Thanks. This might be helpful when one is searching for starting values. Best regards, Øivind

                Comment

                Working...
                X