Note: Originally posted on Stack Overflow, but crossposted here following advice.


I am running a multi-level logistic regression in Stata on multiple imputed data with the following command:

Code:
mi estimate, cmdok post: melogit outcome i.var1 i.var2 i.var3, difficult || id:
I have succeeded in running similar models with the same covariates and different outcomes. These models only take 1 to 2 minutes using my dataset (approx. n=130,000 with n=10 imputations).

For other binary outcomes, even after many hours, Stata reaches a certain point and is running "something" but I'm not sure what (i.e. the circle in the bottom right is spinning). The other binary outcomes are not excessively rare or common (prevalences range from 3% to 30%). I used
Code:
set trace on
to check what was happening under the hood (last approx. 100 lines of output below). I'm not familiar with Mata. Stata reaches this point and seemingly doesn't progress any further, but doesn't return an error code and stop the program. Can anyone suggest why Stata is struggling to proceed any further with the regression, or suggest alternatives to avoid this problem? The same issue occurs both with melogit and meglm with a logit link and binomial family specified.


Code:
       - syntax name(name=maxmin) [, NEGH TOLerance(numlist ma
    > x=1 >=0) LTOLerance(numlist max=1 >=0) NONRTOLerance NRTOLerance(numlist max=1 >=0)
    >  QTOLerance(numlist max=1 >=0) GTOLerance(numlist max=1 >=0) ITERate(numlist max=1
    > >=0) NOTCONCAVE(numlist max=1 >=0) ndami DIFficult HALFSTEPonly DOOPT SEArch(name)
    > Repeat(passthru) Bounds(string) SCore(string) noWARNing noCLEAR noLOg DOTs SHOWTOLe
    > rance SHOWNRtolerance SHOWSTEP TRace COEFDIffs GRADient HESSian noSKIPline noOUTput
    >  Level(cilevel) moptobj(string) * ]
                                  - if `:length local nrtolerance' {
                                  = if 0 {
                                    opts_exclusive "nrtolerance() `nonrtolerance'"
                                    }
                                  - if `:length local qtolerance' {
                                  = if 0 {
                                    opts_exclusive "qtolerance() `nonrtolerance'"
                                    }
                                  - opts_exclusive "`nonrtolerance' `shownrtolerance'"
                                  = opts_exclusive " "
                                    ---------------------------- begin opts_exclusive ---
                                    - version 8.2
                                    - args opts optname errcode
                                    - local opts `opts'
                                    = local opts  
                                    - local n 0
                                    - while `"`opts'"' != "" {
                                    = while `""' != "" {
                                      local ++n
                                      gettoken item`n' opts : opts, bind
                                      }
                                    - if `n' < 2 {
                                    = if 0 < 2 {
                                    - exit
                                    ------------------------------ end opts_exclusive ---
                                  - if `:length local shownrtolerance' {
                                  = if 0 {
                                    local showtolerance showtolerance
                                    }
                                  - if "$ML_preserve" != "no" {
                                  = if "no" != "no" {
                                    if `:length local score' {
                                    di as err "May not specify score() option unless" _n
    > "     a)  estimation subsample is the entire data in memory, or" _n "     b)  you s
    > pecify nopreserve option on -ml model- statement (meaning" _n "         your evalua
    > tion program explicitly restricts itself to obs." _n "         for which $" "ML_sam
    > p==1."
                                    exit 198
                                    }
                                    preserve
                                    local N = c(N)
                                    quietly keep if $ML_sample
                                    if (`N' != c(N)) {
                                    mata: Mopt_init_regetviews()
                                    }
                                    }
                                  - if `:length local score' {
                                  = if 0 {
                                    SetupScore `"$ML_evaltype"' `"`score'"' $ML_n $ML_dim
                                    local scores "`s(scores)'"
                                    }
                                  - local tropts `log' `dots' `showtolerance' `showstep'
    > `trace' `coefdiffs'
                                  = local tropts      
                                  - if "`tropts'" != "nolog" {
                                  = if "" != "nolog" {
                                  - local tropts `tropts' `gradient' `hessian'
                                  = local tropts  
                                  - if "`skipline'" == "" {
                                  = if "" == "" {
                                  - if "`iterate'" != "0" | `:length local tropts' {
                                  = if "" != "0" | 0 {
                                  - di
                                  - }
                                  - }
                                  - }
                                  - else {
                                    local gradient
                                    local hessian
                                    local nolog nolog
                                    }
                                  - if "`search'" != "off" & "`iterate'" != "0" {
                                  = if "off" != "off" & "" != "0" {
                                    if "`search'" == "quietly" {
                                    local sopts nolog
                                    }
                                    else {
                                    if `:length local tropts' {
                                    if "`tropts'" != "nolog" {
                                    local sopts trace
                                    }
                                    else local sopts nolog
                                    }
                                    }
                                    if "`search'" == "norescale" {
                                    local sopts `sopts' norescale
                                    }
                                    Search `bounds', nopreserve `sopts' `repeat' `maxmin'
                                    }
                                  - tempname value b V iV
                                  - `vv' mata: Mopt_maxmin()
                                  = version 13: mata: Mopt_maxmin()
Furthermore, if I don't specify the random effect for id and use a model like
Code:
mi estimate, cmdok post: melogit outcome i.var1 i.var2 i.var3, difficult
instead of
Code:
mi estimate, cmdok post: melogit outcome i.var1 i.var2 i.var3, difficult || id:
the model converges with no issues. Why would specifying a random effect seemingly cause such problems? The values for ID are between 1 and approx 16,000. Could this be contributing to the problem?