Announcement

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

  • gologit2 suddenly having problems in Stata 15

    I have sent this problem to Stata tech support. I will be amazed if anyone on the list can help me but I figured I would toss it out just in case anyone has encountered a similar problem.

    My gologit2 program, first introduced in 2006, works fine in Stata 11.2 through Stata 14. For example, in Stata 14, if I give the commands

    Code:
    use https://www3.nd.edu/~rwilliam/statafiles/ordwarm2, clear
    gologit2 warm i.male i.white, auto waldforce nolabel nofvlabel
    I get

    Code:
    Generalized Ordered Logit Estimates             Number of obs     =      2,293
                                                    Wald chi2(4)      =      97.78
                                                    Prob > chi2       =     0.0000
    Log likelihood = -2944.6035                     Pseudo R2         =     0.0171
    
     ( 1)  [eq1]1.white - [eq2]1.white = 0
     ( 2)  [eq2]1.white - [eq3]1.white = 0
    ------------------------------------------------------------------------------
            warm |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    eq1          |
          1.male |  -.3042833   .1247377    -2.44   0.015    -.5487647   -.0598019
         1.white |  -.3331343   .1159147    -2.87   0.004    -.5603229   -.1059457
           _cons |   2.351311   .1366675    17.20   0.000     2.083447    2.619174
    -------------+----------------------------------------------------------------
    eq2          |
          1.male |  -.5922755   .0851572    -6.96   0.000    -.7591805   -.4253705
         1.white |  -.3331343   .1159147    -2.87   0.004    -.5603229   -.1059457
           _cons |   .7943304    .117114     6.78   0.000     .5647912     1.02387
    -------------+----------------------------------------------------------------
    eq3          |
          1.male |   -1.01099   .1195953    -8.45   0.000    -1.245393   -.7765879
         1.white |  -.3331343   .1159147    -2.87   0.004    -.5603229   -.1059457
           _cons |  -.8269653   .1184391    -6.98   0.000    -1.059102   -.5948289
    ------------------------------------------------------------------------------
    I also went way back to Stata 11.2 and it worked fine there too (once I dropped nofvlabel). But, if I give the exact same commands in Stata 15, I get

    Code:
    Generalized Ordered Logit Estimates             Number of obs     =      2,293
                                                    Wald chi2(4)      =      97.78
                                                    Prob > chi2       =     0.0000
    Log likelihood = -2944.6035                     Pseudo R2         =     0.0171
    
     ( 1)  [eq1]1.white - [eq2]1.white = 0
     ( 2)  [eq2]1.white - [eq3]1.white = 0
    ------------------------------------------------------------------------------
            warm |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    eq1          |
          1.male |  -.3042833   .1247377    -2.44   0.015    -.5487647   -.0598019
         1.white |  -.3331343   .1159147    -2.87   0.004    -.5603229   -.1059457
           _cons |   2.351311   .1366675    17.20   0.000     2.083447    2.619174
    -------------+----------------------------------------------------------------
    eq2          |
          0.male |  -3.38e-16   3.76e-17    -8.99   0.000    -4.12e-16   -2.64e-16
          1.male |  -.5922755   .0851572    -6.96   0.000    -.7591805   -.4253705
         0.white |   9.66e-17   1.72e-17     5.62   0.000     6.29e-17    1.30e-16
         1.white |  -.3331343   .1159147    -2.87   0.004    -.5603229   -.1059457
           _cons |   .7943304    .117114     6.78   0.000     .5647912     1.02387
    -------------+----------------------------------------------------------------
    eq3          |
          1.male |   -1.01099   .1195953    -8.45   0.000    -1.245393   -.7765879
         1.white |  -.3331343   .1159147    -2.87   0.004    -.5603229   -.1059457
           _cons |  -.8269653   .1184391    -6.98   0.000    -1.059102   -.5948289
    ------------------------------------------------------------------------------
    That is, I get these incredibly small but highly significant junk parameter estimates for 0.male and 0.white. Those junk parameters don't seem to affect anything thing else, e.g. the DF and chi-square are the same, as are the other parameter estimates. They are really annoying but the estimates are basically 0 so they don't have much impact.

    gologit2 calls the ml command. My guess is that something changed in ml in Stata 15 that causes it to add these junk parameters. That may need fixes on Stata's end, but I am happy to program around it on my side if I can figure out how.

    Also, you can bypass gologit2 and call ml directly, and the problem is the same. I've tried tweaking the ml command (e.g. drop the collinear option) but so far no luck. Dropping the 0b. variables doesn't work if there are more than 2 categories to a variable. If there is some option I can add to ml that will make the problem go away I would love to know what it is! Thanks

    Code:
    use https://www3.nd.edu/~rwilliam/statafiles/ordwarm2, clear
    constraint 1998 [eq1]1.white = [eq2]1.white
    constraint 1999 [eq1]1.white = [eq3]1.white
    
    ml model lf gologit2_ll /// 
     (eq1:warm= 0b.male 1.male  0b.white 1.white) (eq2: 0b.male 1.male  0b.white 1.white) ///
     (eq3: 0b.male 1.male  0b.white 1.white) , /// 
     constraints(1999 1998)   waldtest(-3)  ///
     lf0(3 -2995.770427280555) collinear /// 
     title(Generalized Ordered Logit Estimates) missing maximize nocnsnotes  nolog collinear 
    ml display, nofvlabel
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 17.0 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

  • #2
    The problem is obviously with factor variables. If you try using just male and white, taking advantage of the fact that they are coded 0 and 1, everything works fine. I then got the maximum likelihood estimation to work by using i.male and i.white in the constraint and model, instead of 0b.male, 1.male, 0b.white and 1.white:

    Code:
    use https://www3.nd.edu/~rwilliam/statafiles/ordwarm2, clear
    constraint 1998 [eq1]i.white = [eq2]i.white
    constraint 1999 [eq1]i.white = [eq3]i.white
    
    ml model lf gologit2_ll /// 
     (eq1:warm=  male  i.white) (eq2: male i.white) ///
     (eq3: male  i.white) , ///  
     lf0(3 -2995.770427280555) collinear /// 
     title(Generalized Ordered Logit Estimates) missing maximize nocnsnotes  nolog collinear 
    ml display, nofvlabel
    This also worked with more than two categories, which I tested by randomly changing half the whites to code 2. Using i.white as above gave the same results as defining dummies for codes 1 and 2 with four constraints.



    Comment


    • #3
      Thanks German. You are right, of course, the problem is with factor variables. There is some wildly esoteric problem with factor variables and precision when using equality constraints that sometimes causes coefficients to be super small when they should be zero. I think I have figured out how to set the rogue values at 0 (like they should be) and am beta testing it now.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Originally posted by Richard Williams View Post
        There is some wildly esoteric problem with factor variables and precision when using equality constraints that sometimes causes coefficients to be super small when they should be zero.
        I have encountered that, too, on occasion. I think that it's usually been with sem or gsem when I'm trying to set some coefficient or another to zero. In sporadic cases, they appear as something like what you see here. It's been an annoyance more than anything, but it seems that it needs to be brought to the attention of the developers, and the next time I run across it, I will.

        Comment


        • #5
          If anyone is interested, here is the code I added to gologit2 that I think/hope has solved the problem. I don't know if there is any other program in the world having this wildly esoteric issue, but if there is this same code might solve it. Thanks to German Rodriguez for identifying the general area of the problem, and to Jeff Pitblado, Clyde Schechter and daniel klein for helping me to figure out a solution.

          Code:
          program basecategoryfix, eclass
          * Fixes problems with base/omitted category coefficients
          * sometimes having super-small values instead of equaling zero.
          * Fixes the covariance too.
          * _ms_omit_info identifies columns that should have 0 values
          * and then the appropriate coefficients and covariances get zeroed out.
          
              version 11.2
          
              tempname b v omitted
              matrix `b' = e(b)
              matrix `v' = e(V)
              local numrows = rowsof(`v')    
              _ms_omit_info `v'
              matrix `omitted' = r(omit)
          
              forval colnum = 1 / `numrows' {
                  if `omitted'[1, `colnum'] ==1 {
                      matrix `b'[1, `colnum'] = 0
                      forval rownum = 1/`numrows' {
                          matrix `v'[`colnum', `rownum'] = 0
                          matrix `v'[`rownum', `colnum'] = 0
                      }
                  }
              }
              
              * Replace old values with corrected zero values
              ereturn repost b = `b' V = `v'
          
          end
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          Stata Version: 17.0 MP (2 processor)

          EMAIL: [email protected]
          WWW: https://www3.nd.edu/~rwilliam

          Comment


          • #6
            Hi,

            Is there a bug in Stata MP 15.0 for gologit2 and margins? I was trying to test the marginal effects (tried both commands: margins, dydx(*) or mfx) after running generalised logit models (command: gologit2). The Stata MP 15.0 gives errors stating that ''too few variables specified, y(dependent variable) has 3 outcomes and so you must specify 3 new variables, or you can use the outcome() option and specify variable one at a time'. However, I tested the commands in Stata SE15.1 and Stata SE14.1 where the analyses went all fine. Therefore, I believe that there is a bug in the Stata MP 15.0.


            Also, the same concern on a potential bug in Stata MP 15.0 is with running gologit2 and margins with the multiple-imputed dataset.

            My codes are:
            mi estimate, cmdok: gologit2 tru(3levels) ts1 ts2 ts3 /// this is no problem; ts are all continuous variables

            Followed by testing the marginal effects:
            mimrgns, dydx(*) which did not work as an error occurred: "must specify outcome () opition with xb option, an error occurred when mi estimate executed mimrgns_estimate on m=1"

            Although, the predicted probability could be calculated.
            mimrgns, dydx(*) predict (outcome(0))

            However, I was advised to report the marginal effects so I really have to sort it out what actually caused the errors.
            The reason why I am asking about a bug in Stata MP 15.0 is because of the environment where I am able to access my data only has Stata MP 15.0, so I am trying to find out what actually caused the errors.

            Any advice would be appreciated.




            Comment


            • #7
              Qianli, without having data and a replicable example, it is hard to fully answer your Qs. I will say I am not aware of any bugs in gologit2 along these lines, but that doesn't mean there aren't any. Some thoughts.
              • It sounds like you have used multiple machines. Make sure they all have the most current version of gologit2, available from SSC:
              Code:
              . which gologit2
              c:\ado\plus\g\gologit2.ado
              *! version 3.2.5 17may2019 Richard Williams, [email protected]
              • If there was a bug involving Stata 15 MP, it may have been fixed in Stata 15.1 MP. I doubt that is the problem though. Nevertheless, harass whoever controls the machine to get it up to date; I hate to mess around with errors that may have been fixed two years ago.
              • See pp. 7-8 of https://www3.nd.edu/~rwilliam/xsoc73994/MD02.pdf for comments on using mimrgns. For one thing, it defaults to xb, not pr. You may have to specify each outcome separately.
              If you still think there are problems and can provide replicable examples (it could be with a different publicly available data set) I can look more closely. But, my first guesses are (1) you have an old version of gologit2 on the Stata 15 MP machine and/or (2) you aren't using the right syntax with mimrgns.
              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              Stata Version: 17.0 MP (2 processor)

              EMAIL: [email protected]
              WWW: https://www3.nd.edu/~rwilliam

              Comment

              Working...
              X