Announcement

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

  • Ereturn Scalar on MI Estimate?

    Hi All,

    I currently am trying to perform a bootstrap on mi estimate: logistic. However, when I run my code, I get the following error:

    Bootstrap replications (20)
    ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
    xxxxxxxxxxxxxxxxxxxx
    insufficient observations to compute bootstrap standard errors
    no results will be saved


    My code is as follows:

    Code:
    mi set flong
    mi register imputed asd age sex bmi smoke numlevels dosym
        
    set seed 54321
        
        capture program drop myboot
        program myboot, eclass properties(mi)
            mi impute chained (logit) asd sex smoke (pmm) bmi dosym (ologit) numlevels, augment force add(60) 
            mi estimate: logistic asd age sex bmi smoke numlevels dosym
                
            ereturn scalar b_a = el(e(b_mi),1,1)
            ereturn scalar b_b = el(e(b_mi),1,2)
            ereturn scalar b_c = el(e(b_mi),1,3)
            ereturn scalar b_d = el(e(b_mi),1,4)
            ereturn scalar b_e = el(e(b_mi),1,5)
            ereturn scalar b_f = el(e(b_mi),1,6)
            ereturn scalar b_g = el(e(b_mi),1,7)
            
        end
    
    bootstrap b_age=e(b_a) b_sex=e(b_b) b_bmi=e(b_c) b_smoke=e(b_d) b_lvls=e(b_e) b_dosym=e(b_f) b_int=e(b_g), reps(20) nodrop :myboot
    I tried to look into why this might be happening and believe it is due to the ereturn function not recognizing my mi estimates as an eclass program for the following bootstrap command.

    Any advice on how to address this or what else may be the issue? Thanks for your help in advance!

  • #2
    Those 20 x's mean that each of your bootstrap repetitions failed.

    Have you have tried
    Code:
    myboot
    ereturn list
    to verify that myboot is (or is not) returning the values you expect, or for that matter, is completing successfully?

    If that does't help, try adding the noisily option to the other options on the bootstrap command to see what the results look like when bootstrap runs myboot.

    Comment


    • #3
      Thank you for the reply! I actually have tried ereturn list but I can't seem to use any other ereturn command besides this on the estimated results. Output is as follows:
      Code:
      scalars:
                        e(p) =  .
                     e(df_m) =  .
                       e(ic) =  .
                       e(ll) =  .
                e(k_autoCns) =  0
                e(converged) =  1
                     e(k_dv) =  1
                        e(k) =  7
                       e(rc) =  0
               e(k_eq_model) =  1
                        e(N) =  861
                    e(N_cds) =  0
                     e(ll_0) =  .
                     e(r2_p) =  .
                     e(rank) =  .
                     e(chi2) =  .
                    e(N_cdf) =  0
                     e(k_eq) =  1
               e(_dfnote_mi) =  0
                 e(k_exp_mi) =  0
             e(esampvary_mi) =  0
                     e(M_mi) =  60
                     e(N_mi) =  861
                  e(df_c_mi) =  .
                  e(df_r_mi) =  1032.966492991906
                  e(df_m_mi) =  6
                     e(F_mi) =  1.119199751013778
             e(rvi_avg_F_mi) =  1.391449126334141
                  e(ufmi_mi) =  0
                     e(p_mi) =  .3488535080488133
               e(rvi_avg_mi) =  1.889978545449096
               e(fmi_max_mi) =  .6492793770628655
                e(df_max_mi) =  239.7881296098761
                e(df_avg_mi) =  182.5667281786089
                e(df_min_mi) =  142.0925979502376
            e(k_eq_model_mi) =  1
             e(reparm_rc_mi) =  .
               e(cilevel_mi) =  95
                 e(N_max_mi) =  861
                 e(N_min_mi) =  861
               e(mcerror_mi) =  0
      
      macros:
          e(_sortseedcmd_mi) : "1734459145"
             e(_sortseed_mi) : "1734459145"
               e(cmdline_mi) : "mi estimate : logistic ASDXROVERALL age SexM0F1 BMI Smoker oflevels dosym"
            e(_estat_cmd_mi) : "logit_estat"
              e(_predict_mi) : "logistic_p"
                       e(mi) : "mi"
                      e(cmd) : "mi estimate"
                  e(ecmd_mi) : "logistic"
                   e(cmd_mi) : "logistic"
                e(prefix_mi) : "mi estimate"
                 e(title_mi) : "Multiple-imputation estimates"
                  e(wvce_mi) : "oim"
             e(modeltest_mi) : "Equal FMI"
              e(dfadjust_mi) : "Large sample"
                    e(rc_mi) : "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
                 e(m_est_mi) : "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50.."
                     e(m_mi) : "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50.."
             e(names_vvm_mi) : "mns gradient ilog"
             e(names_vvs_mi) : "p ic ll ll_0 r2_p chi2"
                  e(cmdline) : "logistic ASDXROVERALL age SexM0F1 BMI Smoker oflevels dosym"
                e(technique) : "nr"
                     e(user) : "mopt__logit_d2()"
                 e(crittype) : "log likelihood"
                      e(opt) : "moptimize"
                   e(depvar) : "ASDXROVERALL"
          e(singularHmethod) : "m-marquardt"
                e(ml_method) : "d2"
                 e(chi2type) : "LR"
             e(marginsnotok) : "stdp DBeta DEviance DX2 DDeviance Hat Number Residuals RStandard SCore"
                    e(title) : "Logistic regression"
                      e(vce) : "oim"
                    e(which) : "max"
      
      matrices:
                     e(b_mi) :  1 x 7
                     e(V_mi) :  7 x 7
                     e(B_mi) :  7 x 7
                     e(W_mi) :  7 x 7
                    e(df_mi) :  1 x 7
                   e(rvi_mi) :  1 x 7
                  e(pise_mi) :  1 x 7
                   e(fmi_mi) :  1 x 7
                    e(re_mi) :  1 x 7
                     e(ilog) :  1 x 1
                    e(rules) :  1 x 4
                 e(gradient) :  1 x 1
                      e(mns) :  1 x 1
      
      .  ereturn scalar (el(e(b_mi),1,1))
      non e-class program may not set e()
      r(152);

      Comment


      • #4
        Your seven scalars are not being displayed by ereturn, so they are not being returned from myboot. Consider the following example, which suggests to me that you did not run the "bare" myboot command as I suggested in post #2.
        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . capture program drop myboot
        
        . program myboot, eclass
          1. regress weight length
          2. ereturn scalar the_constant = el(e(b),1,2)
          3. end
        
        . myboot
        
              Source |       SS           df       MS      Number of obs   =        74
        -------------+----------------------------------   F(1, 72)        =    613.27
               Model |  39461306.8         1  39461306.8   Prob > F        =    0.0000
            Residual |  4632871.55        72  64345.4382   R-squared       =    0.8949
        -------------+----------------------------------   Adj R-squared   =    0.8935
               Total |  44094178.4        73  604029.841   Root MSE        =    253.66
        
        ------------------------------------------------------------------------------
              weight |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              length |   33.01988   1.333364    24.76   0.000     30.36187    35.67789
               _cons |  -3186.047   252.3113   -12.63   0.000     -3689.02   -2683.073
        ------------------------------------------------------------------------------
        matrix operators that return matrices not allowed in this context
        r(509);
        Now consider the following revision.
        Code:
         sysuse auto, clear
        (1978 Automobile Data)
        
        . capture program drop myboot
        
        . program myboot, eclass
          1. regress weight length
          2. matrix b = e(b)
          3. capture noisily ereturn scalar the_constant = b[1,2]
          4. end
        
        . myboot
        
              Source |       SS           df       MS      Number of obs   =        74
        -------------+----------------------------------   F(1, 72)        =    613.27
               Model |  39461306.8         1  39461306.8   Prob > F        =    0.0000
            Residual |  4632871.55        72  64345.4382   R-squared       =    0.8949
        -------------+----------------------------------   Adj R-squared   =    0.8935
               Total |  44094178.4        73  604029.841   Root MSE        =    253.66
        
        ------------------------------------------------------------------------------
              weight |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
              length |   33.01988   1.333364    24.76   0.000     30.36187    35.67789
               _cons |  -3186.047   252.3113   -12.63   0.000     -3689.02   -2683.073
        ------------------------------------------------------------------------------
        
        . ereturn list the_constant
        scalar e(the_constant)=  -3186.04657432053
        The lesson from this is to test programs before embedding them in other processes.

        Also, that the matrix function el() apparently doesn't work the way both you and I expected it does.
        Last edited by William Lisowski; 29 Jun 2019, 15:12.

        Comment


        • #5
          Gotcha-- thank you that definitely cleared a few things up. I'm still very much new to stata and trying to figure out how to troubleshoot these issues. I was able to get the estimates to display using -ereturn list-:

          Code:
          .        
          ereturn list b_a
          scalar e(b_a)      =  .0003248513998967
          However, the bootstrap replications are still failing:

          mi set flong
          mi register imputed asd age sex bmi smoke numlevels dosym

          set seed 54321

          capture program drop myboot
          program myboot, eclass
          mi impute chained (logit) asd sex smoke (pmm) bmi dosym (ologit) numlevels, augment force add(60)
          mi estimate: logistic asd sex smoke bmi dosym numlevels
          matrix b = e(b_mi)
          capture noisily ereturn scalar b_a = b[1,1]
          capture noisily ereturn scalar b_b = b[1,2]
          capture noisily ereturn scalar b_c = b[1,3]
          capture noisily ereturn scalar b_d = b[1,4]
          capture noisily ereturn scalar b_e = b[1,5]
          capture noisily ereturn scalar b_f = b[1,6]
          capture noisily ereturn scalar b_g = b[1,7]


          end

          bootstrap b_age=e(b_a) b_sex=e(b_b) b_bmi=e(b_c) b_smoke=e(b_d) b_lvls=e(b_e) b_dosym=e(b_f) b_int=e(b_g), reps(20) nodrop: myboot

          Bootstrap replications (20)
          ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
          xxxxxxxxxxxxxxxxxxxx
          insufficient observations to compute bootstrap standard errors
          no results will be saved
          Are there any other edits/recommendations you may have?

          Comment


          • #6
            I'm surprised to see capture noisily on all of your ereturn commands. Why is that?

            From post #4

            If that does't help, try adding the noisily option to the other options on the bootstrap command to see what the results look like when bootstrap runs myboot.
            and reduce the number of repetitions to 3 to reduce the amount of output.

            Comment


            • #7
              Thank you so much-- adding -capture noisily- to the -mi impute chained- and -mi estimate- lines ended up getting the whole thing to work, though I'm not exactly sure why; no error messages came back in the output.

              As for why I added it to the -ereturn scalar- commands... that was mostly a result of blindly copy/paste without thinking about what I was doing


              Code:
              mi set flong
              mi register imputed asd sex smoke bmi dosym numlevels
                  
              set seed 54321
                  
                  capture program drop myboot
                  program myboot, eclass
                      capture noisily mi impute chained (logit) asd sex smoke (pmm) bmi dosym (ologit) numlevels, augment force add(60)
                      capture noisily mi estimate: logistic asd sex smoke bmi dosym numlevels
                      matrix b = e(b_mi)
                      capture noisily ereturn scalar b_a = b[1,1]
                      capture noisily ereturn scalar b_b = b[1,2]
                      capture noisily ereturn scalar b_c = b[1,3]
                      capture noisily ereturn scalar b_d = b[1,4]
                      capture noisily ereturn scalar b_e = b[1,5]
                      capture noisily ereturn scalar b_f = b[1,6]
                      capture noisily ereturn scalar b_g = b[1,7]
              
                  end
              
              bootstrap b_age=e(b_a) b_sex=e(b_b) b_bmi=e(b_c) b_smoke=e(b_d) b_lvls=e(b_e) b_dosym=e(b_f) b_int=e(b_g), reps(3) nodrop: myboot

              Comment


              • #8
                I see that I mislead you with the code in post #4. The capture noisily in the second example was unnecessary and should have been removed.

                By applying capture noisily wholesale you haven't learned why it failed and you don't know if there are latent problems in your program. I am reasonably sure you have not seen the output from either mi impute or mi estimate necessary to understand your problem.

                I suggested adding the noisily option to the bootstrap command, thus
                Code:
                mi set flong
                mi register imputed asd sex smoke bmi dosym numlevels
                    
                set seed 54321
                    
                    capture program drop myboot
                    program myboot, eclass
                        mi impute chained (logit) asd sex smoke (pmm) bmi dosym (ologit) numlevels, augment force add(60)
                        mi estimate: logistic asd sex smoke bmi dosym numlevels
                        matrix b = e(b_mi)
                        ereturn scalar b_a = b[1,1]
                        ereturn scalar b_b = b[1,2]
                        ereturn scalar b_c = b[1,3]
                        ereturn scalar b_d = b[1,4]
                        ereturn scalar b_e = b[1,5]
                        ereturn scalar b_f = b[1,6]
                        ereturn scalar b_g = b[1,7]
                
                    end
                
                bootstrap b_age=e(b_a) b_sex=e(b_b) b_bmi=e(b_c) b_smoke=e(b_d) b_lvls=e(b_e) b_dosym=e(b_f) b_int=e(b_g), noisily reps(3) nodrop: myboot
                Look in the output of help bootstrap for the syntax of the command, and the list of options, including noisily, used with the
                Code:
                bootstrap
                command.

                That is different than the noisily command prefix that I misled you into using. You should never be using capture or capture noisily as indiscriminately as you have done: what it does is tell Stata to ignore all error conditions. You are expected to check the return code from the command yourself to confirm that it ran correctly or that the error it had was one you anticipated and can program around. We use capture program drop because a program definition stays loaded in Stata through your entire session, so you need to drop the definition before defining it again. But of course the program drop will fail the first time the code is run because the program has not been defined previously. So we capture the command to prevent the do-file from terminating early.

                So that I'm not misunderstood, I think that with what I misled you into doing, you have a disaster waiting to be discovered. Do try what I have shown above so that you can see the results of your mi impute and mi estimate commands. I think you will find there are problems.

                Comment


                • #9
                  Actually it looks like there's another issue here. The bootstrap isn't returning anything but the coefficients (additional variables have been added here, but the same result was true with the previously):


                  Code:
                  ------------------------------------------------------------------------------
                               |   Observed   Bootstrap                         Normal-based
                               |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                  -------------+----------------------------------------------------------------
                         b_age |   .0022952          .        .       .            .           .
                      b_female |  -.0608048          .        .       .            .           .
                         b_bmi |  -.0033542          .        .       .            .           .
                      b_smoker |  -.1468848          .        .       .            .           .
                         b_cci |  -.0772279          .        .       .            .           .
                        b_lvls |  -.2493112          .        .       .            .           .
                        b_ceph |  -.3568374          .        .       .            .           .
                       b_dosym |  -.0038128          .        .       .            .           .
                       b_modic |  -.1169676          .        .       .            .           .
                          b_ep |   .0038936          .        .       .            .           .
                       b_black |    .015854          .        .       .            .           .
                         b_hiz |  -.0506115          .        .       .            .           .
                       b_osteo |   .0550713          .        .       .            .           .
                       b_bulge |    .124812          .        .       .            .           .
                        b_dnar |   .1787215          .        .       .            .           .
                         b_int |   .2897452          .        .       .            .           .
                  ------------------------------------------------------------------------------
                  The values returned are identical to those produced by the mi estimate: logistic command. Any idea what could be going on here?

                  Comment


                  • #10
                    Our posts crossed, check my #8 posted while you were composing #9.

                    Comment


                    • #11
                      Thank you for the clarification, there were a few errors with the imputation model that were masked by the fact I used -force- and -augment-. This led to collinearity in different imputation models, which probably contributed to some of the issues. I've addressed this by using -omit- where appropriate.

                      However, now when I run the bootstrap this is the error I am receiving:

                      Code:
                      Bootstrap replications (3)
                      . myboot
                      (system variable _mi_id updated due to changed number of obs.)
                      (1007 m>0 obs. dropped due to dropped obs. in m=0)
                      variable _mi_id does not uniquely identify observations in the master data
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (system variable _mi_id updated due to changed number of obs.)
                      (880 m>0 obs. dropped due to dropped obs. in m=0)
                      variable _mi_id does not uniquely identify observations in the master data
                      an error occurred when bootstrap executed myboot, posting missing values
                      . myboot
                      (system variable _mi_id updated due to changed number of obs.)
                      (944 m>0 obs. dropped due to dropped obs. in m=0)
                      variable _mi_id does not uniquely identify observations in the master data
                      an error occurred when bootstrap executed myboot, posting missing values
                      insufficient observations to compute bootstrap standard errors
                      no results will be saved
                      r(2000);
                      Do the _mi_ids need to be unique in order to proceed?

                      Comment


                      • #12
                        At this point you're getting beyond my depth in bootstrap and mi.

                        I suspect your current problem might be solvable by switching from flong to wide. Consider the following examples, based on

                        https://stats.idre.ucla.edu/stata/fa...-imputed-data/

                        (Note that in these examples el() works perfectly fine, so something I don't understand was causing it not to work in the earlier examples.)

                        Code:
                        cls
                        capture program drop myboot
                        program define myboot, rclass
                           mi impute mvn read write math female = socst, add(5)
                           mi estimate: regress read write female
                           return scalar b_w = el(e(b_mi),1,1)
                           return scalar b_f = el(e(b_mi),1,2)
                           return scalar b_c = el(e(b_mi),1,3)
                        end
                        use https://stats.idre.ucla.edu/stat/stata/seminars/missing_data/hsb2_mar, clear
                        mi set wide
                        mi register imputed write read math female
                        set seed 23543
                        bootstrap b_write=r(b_w) b_female=r(b_f) intercept=r(b_c), reps(5): myboot
                        
                        use https://stats.idre.ucla.edu/stat/stata/seminars/missing_data/hsb2_mar, clear
                        mi set flong
                        mi register imputed write read math female
                        set seed 23543
                        bootstrap b_write=r(b_w) b_female=r(b_f) intercept=r(b_c), reps(5) noisily: myboot
                        Code:
                        . capture program drop myboot
                        
                        . program define myboot, rclass
                          1.    mi impute mvn read write math female = socst, add(5)
                          2.    mi estimate: regress read write female
                          3.    return scalar b_w = el(e(b_mi),1,1)
                          4.    return scalar b_f = el(e(b_mi),1,2)
                          5.    return scalar b_c = el(e(b_mi),1,3)
                          6. end
                        
                        . use https://stats.idre.ucla.edu/stat/stata/seminars/missing_data/hsb2_mar, clear
                        (highschool and beyond (200 cases))
                        
                        . mi set wide
                        
                        . mi register imputed write read math female
                        
                        . set seed 23543
                        
                        . bootstrap b_write=r(b_w) b_female=r(b_f) intercept=r(b_c), reps(5): myboot
                        (running myboot on estimation sample)
                        
                        Warning:  Because myboot is not an estimation command or does not set e(sample), bootstrap has
                                  no way to determine which observations are used in calculating the statistics and so
                                  assumes that all observations are used.  This means that no observations will be
                                  excluded from the resampling because of missing values or other reasons.
                        
                                  If the assumption is not true, press Break, save the data, and drop the observations
                                  that are to be excluded.  Be sure that the dataset in memory contains only the
                                  relevant data.
                        
                        Bootstrap replications (5)
                        ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
                        .....
                        
                        Bootstrap results                               Number of obs     =        200
                                                                        Replications      =          5
                        
                              command:  myboot
                              b_write:  r(b_w)
                             b_female:  r(b_f)
                            intercept:  r(b_c)
                        
                        ------------------------------------------------------------------------------
                                     |   Observed   Bootstrap                         Normal-based
                                     |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                             b_write |   .7184783   .0716873    10.02   0.000     .5779739    .8589827
                            b_female |  -4.250247   .9513046    -4.47   0.000     -6.11477   -2.385725
                           intercept |   16.66872    3.08933     5.40   0.000     10.61374     22.7237
                        ------------------------------------------------------------------------------
                        
                        .
                        . use https://stats.idre.ucla.edu/stat/stata/seminars/missing_data/hsb2_mar, clear
                        (highschool and beyond (200 cases))
                        
                        . mi set flong
                        
                        . mi register imputed write read math female
                        (55 m=0 obs. now marked as incomplete)
                        
                        . set seed 23543
                        
                        . bootstrap b_write=r(b_w) b_female=r(b_f) intercept=r(b_c), reps(5) noisily: myboot
                        bootstrap: First call to myboot with data as is:
                        
                        . myboot
                        
                        Performing EM optimization:
                          observed log likelihood = -1327.5197 at iteration 9
                        
                        Performing MCMC data augmentation ...
                        
                        Multivariate imputation                     Imputations =        5
                        Multivariate normal regression                    added =        5
                        Imputed: m=1 through m=5                        updated =        0
                        
                        Prior: uniform                               Iterations =      500
                                                                        burn-in =      100
                                                                        between =      100
                        
                        ------------------------------------------------------------------
                                           |               Observations per m            
                                           |----------------------------------------------
                                  Variable |   Complete   Incomplete   Imputed |     Total
                        -------------------+-----------------------------------+----------
                                      read |        191            9         9 |       200
                                     write |        183           17        17 |       200
                                      math |        185           15        15 |       200
                                    female |        182           18        18 |       200
                        ------------------------------------------------------------------
                        (complete + incomplete = total; imputed is the minimum across m
                         of the number of filled-in observations.)
                        
                        Multiple-imputation estimates                   Imputations       =          5
                        Linear regression                               Number of obs     =        200
                                                                        Average RVI       =     0.0825
                                                                        Largest FMI       =     0.1443
                                                                        Complete DF       =        197
                        DF adjustment:   Small sample                   DF:     min       =      95.21
                                                                                avg       =     124.92
                                                                                max       =     143.52
                        Model F test:       Equal FMI                   F(   2,  105.4)   =      60.07
                        Within VCE type:          OLS                   Prob > F          =     0.0000
                        
                        ------------------------------------------------------------------------------
                                read |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                        -------------+----------------------------------------------------------------
                               write |   .7184783   .0649939    11.05   0.000     .5899491    .8470075
                              female |  -4.250247   1.252511    -3.39   0.001    -6.736725    -1.76377
                               _cons |   16.66872   3.357453     4.96   0.000     10.03227    23.30516
                        ------------------------------------------------------------------------------
                        
                        Warning:  Because myboot is not an estimation command or does not set e(sample), bootstrap has
                                  no way to determine which observations are used in calculating the statistics and so
                                  assumes that all observations are used.  This means that no observations will be
                                  excluded from the resampling because of missing values or other reasons.
                        
                                  If the assumption is not true, press Break, save the data, and drop the observations
                                  that are to be excluded.  Be sure that the dataset in memory contains only the
                                  relevant data.
                        
                        Bootstrap replications (5)
                        . myboot
                        (system variable _mi_id updated due to changed number of obs.)
                        (363 m>0 obs. dropped due to dropped obs. in m=0)
                        variable _mi_id does not uniquely identify observations in the master data
                        an error occurred when bootstrap executed myboot, posting missing values
                        . myboot
                        (system variable _mi_id updated due to changed number of obs.)
                        (410 m>0 obs. dropped due to dropped obs. in m=0)
                        variable _mi_id does not uniquely identify observations in the master data
                        an error occurred when bootstrap executed myboot, posting missing values
                        . myboot
                        (system variable _mi_id updated due to changed number of obs.)
                        (383 m>0 obs. dropped due to dropped obs. in m=0)
                        variable _mi_id does not uniquely identify observations in the master data
                        an error occurred when bootstrap executed myboot, posting missing values
                        . myboot
                        (system variable _mi_id updated due to changed number of obs.)
                        (344 m>0 obs. dropped due to dropped obs. in m=0)
                        variable _mi_id does not uniquely identify observations in the master data
                        an error occurred when bootstrap executed myboot, posting missing values
                        . myboot
                        (system variable _mi_id updated due to changed number of obs.)
                        (352 m>0 obs. dropped due to dropped obs. in m=0)
                        variable _mi_id does not uniquely identify observations in the master data
                        an error occurred when bootstrap executed myboot, posting missing values
                        insufficient observations to compute bootstrap standard errors
                        no results will be saved
                        r(2000);

                        Comment


                        • #13
                          Thank you-- I wasn't able to figure it out with this code but may have found a work around. The overall goal I am trying to achieve is to build a model after creating multiple bootstrap samples, followed by MI for the missing data (as outlined in Schomaker and Heumann 2016). I may have found a workaround to the above but am unsure about the syntax:

                          Code:
                          capture program drop twoboot
                          program define twoboot, eclass
                          preserve
                          bsample
                          mi set mlong
                          mi register imputed ASDXROVERALL SexM0F1 BMI Smoker CCI oflevels dosym
                          mi register regular age modictypetotal endplatetotal blackdisctotal hiztotal osteophytetotal bulgetotal discnarrowtotal
                          mi impute chained (logit, omit(i.CCI i.oflevels)) ASDXROVERALL (logit, omit(i.CCI i.oflevels)) SexM0F1 (logit, omit(i.CCI i.oflevels)) Smoker (ologit) CCI (ologit) oflevels (pmm) BMI dosym = age modictypetotal endplatetotal blackdisctotal hiztotal osteophytetotal bulgetotal discnarrowtotal, noisily add(70)    
                          mi estimate, or: logistic ASDXROVERALL age SexM0F1 BMI Smoker CCI oflevels CervCephLevel dosym modictypetotal endplatetotal blackdisctotal hiztotal osteophytetotal bulgetotal discnarrowtotal
                          matrix b = e(b_mi)
                                  ereturn scalar b_a = b[1,1]
                                  ereturn scalar b_b = b[1,2]
                                  ereturn scalar b_c = b[1,3]
                                  ereturn scalar b_d = b[1,4]
                                  ereturn scalar b_e = b[1,5]
                                  ereturn scalar b_f = b[1,6]
                                  ereturn scalar b_g = b[1,7]
                                  ereturn scalar b_h = b[1,8]
                                  ereturn scalar b_i = b[1,9]
                                  ereturn scalar b_j = b[1,10]
                                  ereturn scalar b_k = b[1,11]
                                  ereturn scalar b_l = b[1,12]
                                  ereturn scalar b_m = b[1,13]
                                  ereturn scalar b_n = b[1,14]
                                  ereturn scalar b_o = b[1,15]
                                  ereturn scalar b_p = b[1,16]    
                          restore
                          
                          end
                          
                          simulate b_age=e(b_a) b_female=e(b_b) b_bmi=e(b_c) b_smoker=e(b_d) b_cci=e(b_e) b_lvls=e(b_f) b_ceph=e(b_g) b_dosym=e(b_h) b_modic=e(b_i) b_ep=e(b_j) b_black=e(b_k) b_hiz=e(b_l) b_osteo=e(b_m) b_bulge=e(b_n) b_dnar=e(b_o) b_int=e(b_p), reps(200) seed(12345): twoboot
                          bstat, stat(b) n(861)
                          
                          
                          Simulations (200)
                          ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
                          ........................................x.........    50
                          ..................................................   100
                          .......x..........x...............................   150
                          ............................x.....................   200
                          
                          . bstat, stat(b) n(861)
                          
                          Bootstrap results                               Number of obs      =       861
                                                                          Replications       =       196
                          
                          ------------------------------------------------------------------------------
                                       |   Observed   Bootstrap                         Normal-based
                                       |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
                          -------------+----------------------------------------------------------------
                                 b_age |   .0313903   .0145914     2.15   0.031     .0027916     .059989
                              b_female |   .0739792   .2820173     0.26   0.793    -.4787645     .626723
                                 b_bmi |  -.0116146    .020836    -0.56   0.577    -.0524524    .0292232
                              b_smoker |  -.3056552   .3705395    -0.82   0.409    -1.031899     .420589
                                 b_cci |  -.0060593   .0594864    -0.10   0.919    -.1226505    .1105319
                                b_lvls |   -.103752   .1010843    -1.03   0.305    -.3018737    .0943696
                                b_ceph |  -.1112652   .0896559    -1.24   0.215    -.2869876    .0644571
                               b_dosym |   -.002999   .0048222    -0.62   0.534    -.0124503    .0064522
                               b_modic |  -.0677327   .1078208    -0.63   0.530    -.2790576    .1435922
                                  b_ep |   .0370078   .0362922     1.02   0.308    -.0341237    .1081393
                               b_black |  -.0076526   .1173402    -0.07   0.948    -.2376351    .2223299
                                 b_hiz |    .009714   .4194109     0.02   0.982    -.8123162    .8317442
                               b_osteo |   .0301016   .0389241     0.77   0.439    -.0461883    .1063914
                               b_bulge |  -.0156271   .0974095    -0.16   0.873    -.2065462     .175292
                                b_dnar |   .0200634   .1425128     0.14   0.888    -.2592566    .2993834
                                 b_int |   -1.66681   1.138698    -1.46   0.143    -3.898617    .5649958
                          ------------------------------------------------------------------------------
                          Note: one or more parameters could not be estimated in some of the bootstrap
                                replicates; standard-error estimates include only complete replications.

                          The code seems to work fine, but I'm not sure if I am getting the correct output. From what you can tell, is this code appropriate?


                          Edit: Actually, changing the old code to wide also made it work! There was another small error I missed when running it the first few times.

                          Last edited by Garrett Harada; 30 Jun 2019, 11:13.

                          Comment

                          Working...
                          X