Announcement

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

  • Predict command after mixed null model error

    Hi,

    I have a 2-level linear model that I am running with 250,000 people and 185 level 2 clusters. There are at least 5 people in each cluster. I have run a series of 5 sequential models with increasing complexity no problem. However, I am having issues with post-estimation commands.

    For example, I run the following null model:

    mixed bmi_real || stratum_all :
    estimates save "m1A.ster", replace

    *store the between stratum variance
    scalar m1Asigma2 = exp(_b(lns1_1_1:_cons)^2

    *predict the mean outcome
    predict m1Am, fitted

    After the predict command I get the following error message: variable stratum_ _ 00006 not found

    Any insight or help would be most welcome.

  • #2
    Are you sure that's the exact code you are using? -scalar m1Asigma2 = exp(_b(lns1_1_1:_cons)^2- should produce an error message "unknown function _b()" because the index lns_1_1_1:_cons should be wrapped in square brackets, [...], not parentheses.

    You don't provide example data with which to try to troubleshoot this. When I try to do something analogous using the pig data set, it runs without errors and produces the expected results:
    Code:
    . clear*
    
    .
    . webuse pig
    (Longitudinal analysis of pig weights)
    
    .
    . mixed weight || id:
    
    Performing EM optimization ...
    
    Performing gradient-based optimization:
    Iteration 0:  Log likelihood = -1828.2965  
    Iteration 1:  Log likelihood =  -1827.213  
    Iteration 2:  Log likelihood = -1827.2118  
    Iteration 3:  Log likelihood = -1827.2118  
    
    Computing standard errors ...
    
    Mixed-effects ML regression                             Number of obs    = 432
    Group variable: id                                      Number of groups =  48
                                                            Obs per group:
                                                                         min =   9
                                                                         avg = 9.0
                                                                         max =   9
                                                            Wald chi2(0)     =   .
    Log likelihood = -1827.2118                             Prob > chi2      =   .
    
    ------------------------------------------------------------------------------
          weight | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
           _cons |   50.40509   .7997195    63.03   0.000     48.83767    51.97251
    ------------------------------------------------------------------------------
    
    ------------------------------------------------------------------------------
      Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
    -----------------------------+------------------------------------------------
    id: Identity                 |
                      var(_cons) |   1.10e-13   1.43e-10             0           .
    -----------------------------+------------------------------------------------
                   var(Residual) |   276.2861   18.79889      241.7921     315.701
    ------------------------------------------------------------------------------
    LR test vs. linear model: chibar2(01) = 0.00          Prob >= chibar2 = 1.0000
    
    .
    . scalar m1Asigma2 = exp(_b[lns1_1_1:_cons])^2
    
    .
    . predict fitted, fitted
    
    .
    . summ fitted
    
        Variable |        Obs        Mean    Std. dev.       Min        Max
    -------------+---------------------------------------------------------
          fitted |        432    50.40509           0   50.40509   50.40509
    
    .
    Can you post back with an example data set and exact code that reproduces the problem you are having?

    Comment


    • #3
      Yes of course. Thanks so much for the quick reply. I'm attaching the log file and do file. I'm having trouble uploading the dataset because it is so large. What is the best way to reduce to give you an example?
      Attached Files

      Comment


      • #4
        Well, I think it's going to be very difficult to reduce the data set in a way that will still be helpful and also be feasible. I became intrigued by the error message's reference to "stratum_ _ 00006," which seems unusual, like a hybrid between your variable named stratum_all, the group identifier, and a temporary variable _00006 that Stata might create when doing calculations. So I tried this:

        Code:
        . clear*
        
        . webuse pig
        (Longitudinal analysis of pig weights)
        
        .
        . rename id stratum_all
        
        .
        . replace stratum_all = . if stratum_all > 30
        (162 real changes made, 162 to missing)
        
        .
        . mixed weight || stratum_all:
        
        Performing EM optimization ...
        
        Performing gradient-based optimization:
        Iteration 0:  Log likelihood = -1135.2447  
        Iteration 1:  Log likelihood = -1134.5656  
        Iteration 2:  Log likelihood = -1134.5647  
        Iteration 3:  Log likelihood = -1134.5647  
        
        Computing standard errors ...
        
        Mixed-effects ML regression                             Number of obs    = 270
        Group variable: stratum_all                             Number of groups =  30
                                                                Obs per group:
                                                                             min =   9
                                                                             avg = 9.0
                                                                             max =   9
                                                                Wald chi2(0)     =   .
        Log likelihood = -1134.5647                             Prob > chi2      =   .
        
        ------------------------------------------------------------------------------
              weight | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
               _cons |   49.30926   .9840701    50.11   0.000     47.38052      51.238
        ------------------------------------------------------------------------------
        
        ------------------------------------------------------------------------------
          Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
        -----------------------------+------------------------------------------------
        stratum_all: Identity        |
                          var(_cons) |   4.48e-13   6.94e-10             0           .
        -----------------------------+------------------------------------------------
                       var(Residual) |   261.4664   22.50344      220.8799    309.5107
        ------------------------------------------------------------------------------
        LR test vs. linear model: chibar2(01) = 0.00          Prob >= chibar2 = 1.0000
        
        .
        . scalar m1Asigma2 = exp(_b[lns1_1_1:_cons])^2
        
        .
        . predict fitted, fitted
        variable stratum__000006 not found
        r(111);
        I have reproduced your error message using the pig.dta. Some experimentation revealed that to trigger this error one must both have missing values in the variable stratum_all, and the variable name change is also required. I have not figured out the generalization about what variable names will cause this bug to bite. It seems that inclusion of an underscore character is required to trigger this error, but not all names containing an underscore do it.

        Anyway, this gives you a workaround: rename your variable stratum_all to something else that doesn't contain any underscore characters.

        But more important, this is a bug in Stata, and you should report it to Stata Technical Support.
        Last edited by Clyde Schechter; 21 Nov 2024, 13:27.

        Comment


        • #5
          That was exactly it! It is now running. Thank you so much for your help. I will report to Stata Technical support as well

          Comment

          Working...
          X