Announcement

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

  • Feature or bug: No r(table) after running a mixed model with multiple imputation

    I am running a mixed model on multiple imputed data and would like to extract the results via r(table) for reporting. I am not getting r(table) outputted however. This is different to other commands, eg regress, or when running mixed without muliple imputation. Below is a reproducible example (I am running v18.0 on Mac osx).

    Does anyone know if this an ommision in Stata or a feature due to some quirk of combining multiple imputation and mixed models?

    Code:
    version 18.0
    
    clear
    set obs 10000
    
    gen x = rnormal(0,1)
    gen cluster = round(_n/1000)
    gen y = rnormal(0,1) + x + cluster
    
    replace x = . if _n < 1000
    
    mi set wide
    mi register imputed y x
    mi impute mvn y x, add(5)
    
    regress y x
    mat list r(table) // shows a table
    
    mi estimate: regress y x
    mat list r(table) // shows a table
    
    mixed y x || cluster:
    mat list r(table) // shows a table
    
    
    mi estimate: mixed y x || cluster:
    mat list r(table) // error: matrix r(table) not found
    
    return list // an empty return
    Last edited by Gordon Forbes; 27 Sep 2024, 05:30.

  • #2
    I don't know about this specific issue, Gordon. However, I have successfully used mixed with multiply imputed data and the estout set of commands (from SSC) to create tables of model results. To do so, you have to add the post option to mi estimate.
    Code:
    version 18.0
    
    clear
    set obs 10000
    
    gen x = rnormal(0,1)
    gen cluster = round(_n/1000)
    gen y = rnormal(0,1) + x + cluster
    
    replace x = . if _n < 1000
    
    mi set wide
    mi register imputed y x
    mi impute mvn y x, add(5)
    
    mi estimate, post: mixed y x || cluster:
    
    eststo m1 
    
    esttab m1, se wide b(3) replace ///
        transform(ln*: exp(@) exp(@)) //

    Comment


    • #3
      I can confirm that the same thing happens on my setup, StataNow 18.5 MP4 on Windows 10 64-bit.

      I can't think of any reason why r(table) would be invalid in this context. I do understand that it could not be calculated in exactly the same way that it is done in the non-mi context, but I'm sure it is within the ability of StataCorp's programmers to code around this problem as they have done so for regress. So I think this is a bug, and I suggest contacting TechSupport about this.

      Added: Crossed with #2. I find that adding the -post- option to -mi estimate- does not solve this problem.

      Code:
      . mi estimate, post: mixed y x || cluster:
      
      Multiple-imputation estimates                   Imputations       =          5
      Mixed-effects ML regression                     Number of obs     =     10,000
      
      Group variable: cluster                         Number of groups  =         11
                                                      Obs per group:
                                                                    min =        499
                                                                    avg =      909.1
                                                                    max =      1,000
                                                      Average RVI       =     0.1493
                                                      Largest FMI       =     0.2926
      DF adjustment:   Large sample                   DF:     min       =      55.83
                                                              avg       =   4.77e+09
                                                              max       =   1.83e+10
      Model F test:       Equal FMI                   F(   1,   55.8)   =    5513.54
                                                      Prob > F          =     0.0000
      
      ------------------------------------------------------------------------------
                 y | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
                 x |   .9299334   .0125238    74.25   0.000     .9048435    .9550233
             _cons |   5.061363    .930292     5.44   0.000     3.238024    6.884701
      ------------------------------------------------------------------------------
      
      ------------------------------------------------------------------------------
        Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
      -----------------------------+------------------------------------------------
      cluster: Identity            |
                         sd(_cons) |   3.085179   .6578957      2.031266     4.68591
      -----------------------------+------------------------------------------------
                      sd(Residual) |   1.071551   .0084128      1.055013    1.088348
      ------------------------------------------------------------------------------
      
      . mat list r(table) // error: matrix r(table) not found
      matrix r(table) not found
      r(111);
      Also Added: The -help file- for -mi estimate- specifically states that r(table) is returned and it mentions no exceptions. So this is definitely a bug.
      Last edited by Clyde Schechter; 27 Sep 2024, 09:44.

      Comment


      • #4
        Thanks Erik and Clyde for your responses - very helpful

        Comment


        • #5
          Gordon has found a bug in mi estimate:mixed; and so, Clyde is correct. mi estimate:mixed should return the r(table) matrix. We will fix this in a future update to Stata.

          Comment


          • #6
            I came across this issue today -- I'm working on Stata in a FISMA moderate environment and don't get regular updates. Any word on whether this has been resolved? If so I'll have to ask for Stata to be updated. If not, I'll work on a work-around. Thanks!

            Comment


            • #7
              I can confirm that this has not yet been fixed in the most recent Stata 18 (26 Feb 2025). Miguel Dorta (StataCorp)

              An unrelated bug in -mi: mixed- is that Stata does not display variance estimates in the random-effects table, and only shows standard deviations. This behavior is not modified by the -variance- option, as indicated in the manual. Further, the change in default behaviour is not expected from plain -mixed- when there is no rationale I can think of for the difference in behaviour.

              Comment


              • #8
                I just came across this same issue. Thanks Gordon Forbes and Clyde Schechter for documenting this bug.

                Comment


                • #9
                  I just tried this in Stata 18.5 and at the end got

                  Code:
                  . mat list r(table) // error: matrix r(table) not found
                  matrix r(table) not found
                  r(111);
                  But, I also tried it in my brand new fresh off the lot copy of Stata 19.5 and got

                  Code:
                  . return list // an empty return
                  
                  matrices:
                                r(table) :  9 x 4
                  
                  . mat list r(table)
                  
                  r(table)[9,4]
                                  y:         y:   cluster:  Residual:
                                  x      _cons   sd(_cons)      sd(e)
                       b  .95599204  5.0799582  3.0714617  1.0728484
                      se  .01140298   .9261721  .65500253  .00779529
                       t  83.837055  5.4848966         .b         .b
                  pvalue          0  4.137e-08         .b         .b
                      ll  .93361016  3.2646942  2.0221934  1.0576659
                      ul  .97837393  6.8952221  4.6651706  1.0882488
                      df  834.57886  2.187e+09  1.451e+08  1485.7345
                    crit  1.9628105   1.959964   1.959964   1.961562
                   eform          0          0          0          0
                  Assuming that is correct, the problem has been fixed, but only in Stata 19. Given that the bug has been know for a while and a fix was promised, it would be nice to fix it in Stata 18.
                  -------------------------------------------
                  Richard Williams, Notre Dame Dept of Sociology
                  StataNow Version: 19.5 MP (2 processor)

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

                  Comment


                  • #10
                    Thanks for updating this, Richard.

                    I would also appreciate if this fix was made retroactive for Stata 18.0 and 18.5 since it was a bug in those versions.

                    Comment

                    Working...
                    X