reffadjustsim helpfile examples

Examples 1 & 2 assume the path to the MLwiN executable is set in global MLwiN_path; see help runmlwin

Example 1: Two level continuous response model

(see page 59 of the MLwiN User Manual)

  • read in data
use https://www.bristol.ac.uk/cmm/media/runmlwin/tutorial, clear
  • fit model using MLwiN via runmlwin
runmlwin normexam cons standlrt, level1(student: cons) ///
    level2(school: cons standlrt) batch
 
 --- Begin MLwiN error log --- 
MLN - Software for N-level analysis.   Mon 20 Oct 2025 08:54:48

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.000003

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.000007
 --- End MLwiN error log --- 

Warning: getversion plugin could not be loaded
MLwiN 3.16 multilevel model                     Number of obs      =      4059
Normal response model (hierarchical)
Estimation algorithm: IGLS

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
         school |       65          2       62.4        198
-----------------------------------------------------------

Run time (seconds)   =       0.06
Number of iterations =          4
Log likelihood       =  -4658.435
Deviance             =    9316.87
------------------------------------------------------------------------------
    normexam |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        cons |  -.0115051    .039783   -0.29    0.772    -.0894783     .066468
    standlrt |   .5567305    .019937   27.92    0.000     .5176547    .5958062
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 2: school              |
                   var(cons) |   .0904446    .017924      .0553142    .1255749
          cov(cons,standlrt) |   .0180414   .0067229      .0048649     .031218
               var(standlrt) |   .0145361   .0044139      .0058851    .0231872
-----------------------------+------------------------------------------------
Level 1: student             |
                   var(cons) |   .5536575   .0124818      .5291937    .5781214
------------------------------------------------------------------------------
/nogui option ignored
ECHO 0

Execution completed
  • report coefficient as median with 2.5 & 97.5 percentiles
reffadjustsim cons standlrt, eqn(RP2) seed(12345)

------------------------------------------------------------------------------
        cons |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
    standlrt |   1.242541                 .4311653            2.607229
------------------------------------------------------------------------------
  • report coefficient as mean & Wald-type confidence interval
  • Warning: mean and Wald-type confidence are inaccurate in this example
reffadjustsim cons standlrt, eqn(RP2) seed(12345) waldtype

------------------------------------------------------------------------------
        cons |      Coef.   Std. Err.                     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    standlrt |   1.319134    1.22225                     -1.076431      3.7147
------------------------------------------------------------------------------
Warning: Coef. & Wald-type conf. interval limits may be inaccurate.
Please compare with default output which reports median & centiles.
  • compare with delta-method confidence interval (first refit model)
runmlwin normexam cons standlrt, level1(student: cons) ///
    level2(school: cons standlrt) batch
reffadjust4nlcom cons standlrt, eqn(RP2)
nlcom `r(beta_standlrt)'
 
 --- Begin MLwiN error log --- 
MLN - Software for N-level analysis.   Mon 20 Oct 2025 08:54:48

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.000004

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.000008
 --- End MLwiN error log --- 

Warning: getversion plugin could not be loaded
MLwiN 3.16 multilevel model                     Number of obs      =      4059
Normal response model (hierarchical)
Estimation algorithm: IGLS

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
         school |       65          2       62.4        198
-----------------------------------------------------------

Run time (seconds)   =       0.04
Number of iterations =          4
Log likelihood       =  -4658.435
Deviance             =    9316.87
------------------------------------------------------------------------------
    normexam |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        cons |  -.0115051    .039783   -0.29    0.772    -.0894783     .066468
    standlrt |   .5567305    .019937   27.92    0.000     .5176547    .5958062
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 2: school              |
                   var(cons) |   .0904446    .017924      .0553142    .1255749
          cov(cons,standlrt) |   .0180414   .0067229      .0048649     .031218
               var(standlrt) |   .0145361   .0044139      .0058851    .0231872
-----------------------------+------------------------------------------------
Level 1: student             |
                   var(cons) |   .5536575   .0124818      .5291937    .5781214
------------------------------------------------------------------------------

       _nl_1: [RP2]cov(cons\standlrt)/[RP2]var(standlrt)

------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       _nl_1 |   1.241144   .4275471     2.90   0.004     .4031675    2.079121
------------------------------------------------------------------------------
/nogui option ignored
ECHO 0

Execution completed
  • compare with Bayesian posterior distribution
runmlwin normexam cons standlrt, level1(student: cons) ///
    level2(school: cons standlrt) batch mcmc(on) initsprevious seed(121211)
mcmcsum, getchains
reffadjustsim cons standlrt, eqn(RP2) mcmcsum
 
/nogui option ignored
ECHO 0

BURNING IN...
Burning in for 50 iterations out of 500
Burning in for 100 iterations out of 500
Burning in for 150 iterations out of 500
Burning in for 200 iterations out of 500
Burning in for 250 iterations out of 500
Burning in for 300 iterations out of 500
Burning in for 350 iterations out of 500
Burning in for 400 iterations out of 500
Burning in for 450 iterations out of 500
Burning in for 500 iterations out of 500

Actual update 50 of 5000, Stored update 50 of 5000
Actual update 100 of 5000, Stored update 100 of 5000
Actual update 150 of 5000, Stored update 150 of 5000
Actual update 200 of 5000, Stored update 200 of 5000
Actual update 250 of 5000, Stored update 250 of 5000
Actual update 300 of 5000, Stored update 300 of 5000
Actual update 350 of 5000, Stored update 350 of 5000
Actual update 400 of 5000, Stored update 400 of 5000
Actual update 450 of 5000, Stored update 450 of 5000
Actual update 500 of 5000, Stored update 500 of 5000
Actual update 550 of 5000, Stored update 550 of 5000
Actual update 600 of 5000, Stored update 600 of 5000
Actual update 650 of 5000, Stored update 650 of 5000
Actual update 700 of 5000, Stored update 700 of 5000
Actual update 750 of 5000, Stored update 750 of 5000
Actual update 800 of 5000, Stored update 800 of 5000
Actual update 850 of 5000, Stored update 850 of 5000
Actual update 900 of 5000, Stored update 900 of 5000
Actual update 950 of 5000, Stored update 950 of 5000
Actual update 1000 of 5000, Stored update 1000 of 5000
Actual update 1050 of 5000, Stored update 1050 of 5000
Actual update 1100 of 5000, Stored update 1100 of 5000
Actual update 1150 of 5000, Stored update 1150 of 5000
Actual update 1200 of 5000, Stored update 1200 of 5000
Actual update 1250 of 5000, Stored update 1250 of 5000
Actual update 1300 of 5000, Stored update 1300 of 5000
Actual update 1350 of 5000, Stored update 1350 of 5000
Actual update 1400 of 5000, Stored update 1400 of 5000
Actual update 1450 of 5000, Stored update 1450 of 5000
Actual update 1500 of 5000, Stored update 1500 of 5000
Actual update 1550 of 5000, Stored update 1550 of 5000
Actual update 1600 of 5000, Stored update 1600 of 5000
Actual update 1650 of 5000, Stored update 1650 of 5000
Actual update 1700 of 5000, Stored update 1700 of 5000
Actual update 1750 of 5000, Stored update 1750 of 5000
Actual update 1800 of 5000, Stored update 1800 of 5000
Actual update 1850 of 5000, Stored update 1850 of 5000
Actual update 1900 of 5000, Stored update 1900 of 5000
Actual update 1950 of 5000, Stored update 1950 of 5000
Actual update 2000 of 5000, Stored update 2000 of 5000
Actual update 2050 of 5000, Stored update 2050 of 5000
Actual update 2100 of 5000, Stored update 2100 of 5000
Actual update 2150 of 5000, Stored update 2150 of 5000
Actual update 2200 of 5000, Stored update 2200 of 5000
Actual update 2250 of 5000, Stored update 2250 of 5000
Actual update 2300 of 5000, Stored update 2300 of 5000
Actual update 2350 of 5000, Stored update 2350 of 5000
Actual update 2400 of 5000, Stored update 2400 of 5000
Actual update 2450 of 5000, Stored update 2450 of 5000
Actual update 2500 of 5000, Stored update 2500 of 5000
Actual update 2550 of 5000, Stored update 2550 of 5000
Actual update 2600 of 5000, Stored update 2600 of 5000
Actual update 2650 of 5000, Stored update 2650 of 5000
Actual update 2700 of 5000, Stored update 2700 of 5000
Actual update 2750 of 5000, Stored update 2750 of 5000
Actual update 2800 of 5000, Stored update 2800 of 5000
Actual update 2850 of 5000, Stored update 2850 of 5000
Actual update 2900 of 5000, Stored update 2900 of 5000
Actual update 2950 of 5000, Stored update 2950 of 5000
Actual update 3000 of 5000, Stored update 3000 of 5000
Actual update 3050 of 5000, Stored update 3050 of 5000
Actual update 3100 of 5000, Stored update 3100 of 5000
Actual update 3150 of 5000, Stored update 3150 of 5000
Actual update 3200 of 5000, Stored update 3200 of 5000
Actual update 3250 of 5000, Stored update 3250 of 5000
Actual update 3300 of 5000, Stored update 3300 of 5000
Actual update 3350 of 5000, Stored update 3350 of 5000
Actual update 3400 of 5000, Stored update 3400 of 5000
Actual update 3450 of 5000, Stored update 3450 of 5000
Actual update 3500 of 5000, Stored update 3500 of 5000
Actual update 3550 of 5000, Stored update 3550 of 5000
Actual update 3600 of 5000, Stored update 3600 of 5000
Actual update 3650 of 5000, Stored update 3650 of 5000
Actual update 3700 of 5000, Stored update 3700 of 5000
Actual update 3750 of 5000, Stored update 3750 of 5000
Actual update 3800 of 5000, Stored update 3800 of 5000
Actual update 3850 of 5000, Stored update 3850 of 5000
Actual update 3900 of 5000, Stored update 3900 of 5000
Actual update 3950 of 5000, Stored update 3950 of 5000
Actual update 4000 of 5000, Stored update 4000 of 5000
Actual update 4050 of 5000, Stored update 4050 of 5000
Actual update 4100 of 5000, Stored update 4100 of 5000
Actual update 4150 of 5000, Stored update 4150 of 5000
Actual update 4200 of 5000, Stored update 4200 of 5000
Actual update 4250 of 5000, Stored update 4250 of 5000
Actual update 4300 of 5000, Stored update 4300 of 5000
Actual update 4350 of 5000, Stored update 4350 of 5000
Actual update 4400 of 5000, Stored update 4400 of 5000
Actual update 4450 of 5000, Stored update 4450 of 5000
Actual update 4500 of 5000, Stored update 4500 of 5000
Actual update 4550 of 5000, Stored update 4550 of 5000
Actual update 4600 of 5000, Stored update 4600 of 5000
Actual update 4650 of 5000, Stored update 4650 of 5000
Actual update 4700 of 5000, Stored update 4700 of 5000
Actual update 4750 of 5000, Stored update 4750 of 5000
Actual update 4800 of 5000, Stored update 4800 of 5000
 --- Begin MLwiN error log --- 
MLN - Software for N-level analysis.   Mon 20 Oct 2025 08:54:48

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.000006

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.00000a

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.000004
 --- End MLwiN error log --- 
Actual update 4850 of 5000, Stored update 4850 of 5000
Actual update 4900 of 5000, Stored update 4900 of 5000
Actual update 4950 of 5000, Stored update 4950 of 5000
Actual update 5000 of 5000, Stored update 5000 of 5000
Execution completed
Warning: getversion plugin could not be loaded
MLwiN 3.16 multilevel model                     Number of obs      =      4059
Normal response model (hierarchical)
Estimation algorithm: MCMC

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
         school |       65          2       62.4        198
-----------------------------------------------------------

Burnin                     =        500
Chain                      =       5000
Thinning                   =          1
Run time (seconds)         =       .627
Deviance (dbar)            =    9122.42
Deviance (thetabar)        =    9031.09
Effective no. of pars (pd) =      91.34
Bayesian DIC               =    9213.76
------------------------------------------------------------------------------
    normexam |      Mean    Std. Dev.     ESS     P       [95% Cred. Interval]
-------------+----------------------------------------------------------------
        cons |   -.010594    .040224      189   0.395    -.0908355    .0678323
    standlrt |   .5568075   .0200344      839   0.000     .5167302    .5960792
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |     Mean   Std. Dev.   ESS     [95% Cred. Int]
-----------------------------+------------------------------------------------
Level 2: school              |
                   var(cons) |  .0961163  .0199991   2715   .0644542  .1421674
          cov(cons,standlrt) |  .0190683  .0072205   1713   .0065699   .034989
               var(standlrt) |  .0153485  .0046893    978   .0078805  .0261361
-----------------------------+------------------------------------------------
Level 1: student             |
                   var(cons) |  .5542075  .0123209   4645   .5309043   .578929
------------------------------------------------------------------------------

------------------------------------------------------------------------------
        cons |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
    standlrt |   1.266334                 .4572121            2.281147
------------------------------------------------------------------------------

Example 2: Multivariate response model

(see page 214 of the MLwiN User Manual)

  • read in data
use https://www.bristol.ac.uk/cmm/media/runmlwin/gcsemv1, clear
  • fit model using MLwiN via runmlwin
runmlwin (written cons female, eq(1)) (csework cons female, eq(2)), ///
        level1(student: (cons, eq(1)) (cons, eq(2))) ///
        level2(school: (cons, eq(1)) (cons, eq(2))) ///
        batch
 
 --- Begin MLwiN error log --- 
MLN - Software for N-level analysis.   Mon 20 Oct 2025 08:54:50

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.000005

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.000009

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.00000a
 --- End MLwiN error log --- 

Warning: getversion plugin could not be loaded
MLwiN 3.16 multilevel model                     Number of obs      =      1905
Multivariate response model (hierarchical)
Estimation algorithm: IGLS

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
         school |       73          2       26.1        104
-----------------------------------------------------------

Run time (seconds)   =       0.12
Number of iterations =          4
Log likelihood       = -13400.244
Deviance             =  26800.488
------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
written      |
      cons_1 |   49.45213   .9338433   52.96    0.000     47.62183    51.28243
    female_1 |   -2.50295   .5607219   -4.46    0.000    -3.601945   -1.403955
-------------+----------------------------------------------------------------
csework      |
      cons_2 |   69.67166   1.171786   59.46    0.000       67.375    71.96831
    female_2 |   6.751393   .6706493   10.07    0.000     5.436944    8.065841
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 2: school              |
                 var(cons_1) |   46.81298    9.18733      28.80615    64.81982
          cov(cons_1,cons_2) |   24.87783   8.880358       7.47265    42.28301
                 var(cons_2) |   75.16623   14.56485      46.61965    103.7128
-----------------------------+------------------------------------------------
Level 1: student             |
                 var(cons_1) |   124.6343   4.349834      116.1088    133.1598
          cov(cons_1,cons_2) |   73.00323    4.17829      64.81393    81.19252
                 var(cons_2) |   180.0982   6.245801      167.8566    192.3397
------------------------------------------------------------------------------
/nogui option ignored
ECHO 0

Execution completed
  • report coefficient as median with 2.5 and 97.5 percentiles
reffadjustsim cons_1 cons_2, eqn(RP2) seed(12345)

------------------------------------------------------------------------------
      cons_1 |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
      cons_2 |   .3308853                 .1231026            .5395364
------------------------------------------------------------------------------
  • report coefficient as mean with Wald-type confidence interval
reffadjustsim cons_1 cons_2, eqn(RP2) seed(12345) waldtype

------------------------------------------------------------------------------
      cons_1 |      Coef.   Std. Err.                     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      cons_2 |    .330939   .1065639                      .1220777    .5398003
------------------------------------------------------------------------------
Warning: Coef. & Wald-type conf. interval limits may be inaccurate.
Please compare with default output which reports median & centiles.
  • compare with delta-method confidence interval (first refit model)
runmlwin (written cons female, eq(1)) (csework cons female, eq(2)), ///
        level1(student: (cons, eq(1)) (cons, eq(2))) ///
        level2(school: (cons, eq(1)) (cons, eq(2))) ///
        batch
reffadjust4nlcom cons_1 cons_2, eqn(RP2)
nlcom `r(beta_cons_2)'
 
 --- Begin MLwiN error log --- 
MLN - Software for N-level analysis.   Mon 20 Oct 2025 08:54:50

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.000006

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.00000a

/var/folders/1l/w0qjrymd3hb44s3skrzn4w4w0000gn/T//St94086.00000b
 --- End MLwiN error log --- 

Warning: getversion plugin could not be loaded
MLwiN 3.16 multilevel model                     Number of obs      =      1905
Multivariate response model (hierarchical)
Estimation algorithm: IGLS

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
         school |       73          2       26.1        104
-----------------------------------------------------------

Run time (seconds)   =       0.10
Number of iterations =          4
Log likelihood       = -13400.244
Deviance             =  26800.488
------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
written      |
      cons_1 |   49.45213   .9338433   52.96    0.000     47.62183    51.28243
    female_1 |   -2.50295   .5607219   -4.46    0.000    -3.601945   -1.403955
-------------+----------------------------------------------------------------
csework      |
      cons_2 |   69.67166   1.171786   59.46    0.000       67.375    71.96831
    female_2 |   6.751393   .6706493   10.07    0.000     5.436944    8.065841
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 2: school              |
                 var(cons_1) |   46.81298    9.18733      28.80615    64.81982
          cov(cons_1,cons_2) |   24.87783   8.880358       7.47265    42.28301
                 var(cons_2) |   75.16623   14.56485      46.61965    103.7128
-----------------------------+------------------------------------------------
Level 1: student             |
                 var(cons_1) |   124.6343   4.349834      116.1088    133.1598
          cov(cons_1,cons_2) |   73.00323    4.17829      64.81393    81.19252
                 var(cons_2) |   180.0982   6.245801      167.8566    192.3397
------------------------------------------------------------------------------

       _nl_1: [RP2]cov(cons_1\cons_2)/[RP2]var(cons_2)

------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       _nl_1 |   .3309709   .0986417     3.36   0.001     .1376367    .5243051
------------------------------------------------------------------------------
/nogui option ignored
ECHO 0

Execution completed
  • compare with Bayesian posterior distribution

runmlwin (written cons female, eq(1)) (csework cons female, eq(2)), /// level1(student: (cons, eq(1)) (cons, eq(2))) /// level2(school: (cons, eq(1)) (cons, eq(2))) /// batch mcmc(on) initsprevious seed(121211) mcmcsum, getchains reffadjustsim cons_1 cons_2, eqn(RP2) mcmcsum


## Example 3: based on xtmixed helpfile

::: {#915cc68e .cell execution_count=13}
``` {.stata .cell-code}
webuse nlswork, clear
version 12: xtmixed ln_w grade age c.age#c.age ttl_exp tenure c.tenure#c.tenure || ///
    idcode: tenure, cov(uns) var
version 12: reffadjustsim _cons tenure, eqn(idcode) seed(12345)
(National Longitudinal Survey of Young Women, 14-24 years old in 1968)

Performing EM optimization: 

Performing gradient-based optimization: 

Iteration 0:  Log likelihood = -8985.3816  
Iteration 1:  Log likelihood = -8966.2878  
Iteration 2:  Log likelihood =  -8965.819  
Iteration 3:  Log likelihood =  -8965.819  

Computing standard errors:

Mixed-effects ML regression                         Number of obs    =  28,099
Group variable: idcode                              Number of groups =   4,697
                                                    Obs per group:
                                                                 min =       1
                                                                 avg =     6.0
                                                                 max =      15
                                                    Wald chi2(6)     = 6767.13
Log likelihood =  -8965.819                         Prob > chi2      =  0.0000

------------------------------------------------------------------------------
     ln_wage | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       grade |   .0690318   .0017885    38.60   0.000     .0655264    .0725372
         age |   .0321872   .0027908    11.53   0.000     .0267174     .037657
             |
 c.age#c.age |  -.0006574   .0000466   -14.09   0.000    -.0007488    -.000566
             |
     ttl_exp |   .0350762   .0011352    30.90   0.000     .0328513     .037301
      tenure |   .0393576   .0017198    22.88   0.000     .0359868    .0427284
             |
    c.tenure#|
    c.tenure |  -.0019926   .0001232   -16.18   0.000    -.0022341   -.0017512
             |
       _cons |    .162264    .044888     3.61   0.000     .0742851    .2502429
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
idcode: Unstructured         |
                 var(tenure) |   .0005174   .0000566      .0004176    .0006411
                  var(_cons) |   .0632497   .0020808      .0593001    .0674624
           cov(tenure,_cons) |   .0007165   .0002809      .0001658    .0012671
-----------------------------+------------------------------------------------
               var(Residual) |   .0815016   .0007978      .0799529    .0830803
------------------------------------------------------------------------------
LR test vs. linear model: chi2(3) = 9168.36               Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

------------------------------------------------------------------------------
       _cons |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
      tenure |   1.377053                 .2240176            2.619103
------------------------------------------------------------------------------

:::

mixed ln_w grade age c.age#c.age ttl_exp tenure c.tenure#c.tenure || ///
    idcode: tenure, cov(uns)
reffadjustsim _cons tenure, eqn(idcode) seed(12345)

Performing EM optimization ...

Performing gradient-based optimization: 
Iteration 0:  Log likelihood = -8985.3816  
Iteration 1:  Log likelihood = -8966.3961  
Iteration 2:  Log likelihood =  -8965.819  
Iteration 3:  Log likelihood =  -8965.819  

Computing standard errors ...

Mixed-effects ML regression                         Number of obs    =  28,099
Group variable: idcode                              Number of groups =   4,697
                                                    Obs per group:
                                                                 min =       1
                                                                 avg =     6.0
                                                                 max =      15
                                                    Wald chi2(6)     = 6767.13
Log likelihood =  -8965.819                         Prob > chi2      =  0.0000

------------------------------------------------------------------------------
     ln_wage | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       grade |   .0690318   .0017885    38.60   0.000     .0655264    .0725372
         age |   .0321872   .0027908    11.53   0.000     .0267174     .037657
             |
 c.age#c.age |  -.0006574   .0000466   -14.09   0.000    -.0007488    -.000566
             |
     ttl_exp |   .0350762   .0011352    30.90   0.000     .0328513     .037301
      tenure |   .0393576   .0017198    22.88   0.000     .0359868    .0427284
             |
    c.tenure#|
    c.tenure |  -.0019926   .0001232   -16.18   0.000    -.0022341   -.0017512
             |
       _cons |    .162264    .044888     3.61   0.000     .0742851    .2502429
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
idcode: Unstructured         |
                 var(tenure) |   .0005174   .0000566      .0004176    .0006411
                  var(_cons) |   .0632497   .0020808      .0593001    .0674624
           cov(tenure,_cons) |   .0007165   .0002809      .0001658    .0012671
-----------------------------+------------------------------------------------
               var(Residual) |   .0815016   .0007978      .0799529    .0830803
------------------------------------------------------------------------------
LR test vs. linear model: chi2(3) = 9168.36               Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

------------------------------------------------------------------------------
       _cons |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
      tenure |   1.377053                  .224019            2.619103
------------------------------------------------------------------------------

Example 4: based on xtmelogit helpfile

webuse bangladesh, clear
version 12: xtmelogit c_use urban age child* || district: urban , ///
    cov(uns) var
version 12: reffadjustsim _cons urban, eqn(district) seed(12345)
(Bangladesh Fertility Survey, 1989)
note: children omitted because of collinearity.

Refining starting values: 

Iteration 0:  Log likelihood = -1215.8594  (not concave)
Iteration 1:  Log likelihood = -1204.0802  
Iteration 2:  Log likelihood = -1199.7968  

Performing gradient-based optimization: 

Iteration 0:  Log likelihood = -1199.7968  
Iteration 1:  Log likelihood = -1199.4726  
Iteration 2:  Log likelihood = -1199.3158  
Iteration 3:  Log likelihood =  -1199.315  
Iteration 4:  Log likelihood =  -1199.315  

Mixed-effects logistic regression               Number of obs     =      1,934
Group variable: district                        Number of groups  =         60

                                                Obs per group:
                                                              min =          2
                                                              avg =       32.2
                                                              max =        118

Integration points =   7                        Wald chi2(5)      =      97.50
Log likelihood =  -1199.315                     Prob > chi2       =     0.0000

------------------------------------------------------------------------------
       c_use | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       urban |   .8157872   .1715519     4.76   0.000     .4795516    1.152023
         age |   -.026415    .008023    -3.29   0.001    -.0421398   -.0106902
      child1 |    1.13252   .1603285     7.06   0.000      .818282    1.446758
      child2 |   1.357739   .1770522     7.67   0.000     1.010724    1.704755
      child3 |   1.353827   .1828801     7.40   0.000     .9953882    1.712265
    children |          0  (omitted)
       _cons |   -1.71165   .1605617   -10.66   0.000    -2.026345   -1.396954
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
district: Unstructured       |
                  var(urban) |   .6663221   .3224714      .2580709      1.7204
                  var(_cons) |   .3897434   .1292458      .2034723    .7465387
            cov(urban,_cons) |  -.4058846   .1755418     -.7499402   -.0618289
------------------------------------------------------------------------------
LR test vs. logistic model: chi2(3) = 58.42               Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

------------------------------------------------------------------------------
       _cons |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
       urban |  -.5931825                -.9623632           -.2892334
------------------------------------------------------------------------------
webuse bangladesh, clear
meqrlogit c_use urban age child* || district: urban, cov(uns)
reffadjustsim _cons urban, eqn(district) seed(12345)
(Bangladesh Fertility Survey, 1989)
note: children omitted because of collinearity.

Refining starting values: 

Iteration 0:  Log likelihood = -1215.8594  (not concave)
Iteration 1:  Log likelihood = -1204.0802  
Iteration 2:  Log likelihood = -1199.7968  

Performing gradient-based optimization: 

Iteration 0:  Log likelihood = -1199.7968  
Iteration 1:  Log likelihood = -1199.4726  
Iteration 2:  Log likelihood = -1199.3158  
Iteration 3:  Log likelihood =  -1199.315  
Iteration 4:  Log likelihood =  -1199.315  

Mixed-effects logistic regression               Number of obs     =      1,934
Group variable: district                        Number of groups  =         60

                                                Obs per group:
                                                              min =          2
                                                              avg =       32.2
                                                              max =        118

Integration points =   7                        Wald chi2(5)      =      97.50
Log likelihood =  -1199.315                     Prob > chi2       =     0.0000

------------------------------------------------------------------------------
       c_use | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       urban |   .8157872   .1715519     4.76   0.000     .4795516    1.152023
         age |   -.026415    .008023    -3.29   0.001    -.0421398   -.0106902
      child1 |    1.13252   .1603285     7.06   0.000      .818282    1.446758
      child2 |   1.357739   .1770522     7.67   0.000     1.010724    1.704755
      child3 |   1.353827   .1828801     7.40   0.000     .9953882    1.712265
    children |          0  (omitted)
       _cons |   -1.71165   .1605617   -10.66   0.000    -2.026345   -1.396954
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
district: Unstructured       |
                  var(urban) |   .6663221   .3224714      .2580709      1.7204
                  var(_cons) |   .3897434   .1292458      .2034723    .7465387
            cov(urban,_cons) |  -.4058846   .1755418     -.7499402   -.0618289
------------------------------------------------------------------------------
LR test vs. logistic model: chi2(3) = 58.42               Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

------------------------------------------------------------------------------
       _cons |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
       urban |  -.5931825                -.9623632           -.2892334
------------------------------------------------------------------------------

Example 5: based on xtmepoisson helpfile

webuse epilepsy, clear
version 12: xtmepoisson seizures treat lbas lbas_trt lage visit || ///
        subject: visit, cov(uns) var intpoints(9)
version 12: reffadjustsim _cons visit, eqn(subject) seed(12345)
(Epilepsy data; progabide drug treatment)

Refining starting values: 

Iteration 0:  Log likelihood = -672.17188  (not concave)
Iteration 1:  Log likelihood = -660.46056  
Iteration 2:  Log likelihood = -655.86888  

Performing gradient-based optimization: 

Iteration 0:  Log likelihood = -655.86888  
Iteration 1:  Log likelihood = -655.68217  
Iteration 2:  Log likelihood = -655.68103  
Iteration 3:  Log likelihood = -655.68103  

Mixed-effects Poisson regression                Number of obs     =        236
Group variable: subject                         Number of groups  =         59

                                                Obs per group:
                                                              min =          4
                                                              avg =        4.0
                                                              max =          4

Integration points =   9                        Wald chi2(5)      =     115.56
Log likelihood = -655.68103                     Prob > chi2       =     0.0000

------------------------------------------------------------------------------
    seizures | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       treat |  -.9286588   .4021638    -2.31   0.021    -1.716885   -.1404323
        lbas |   .8849767   .1312519     6.74   0.000     .6277277    1.142226
    lbas_trt |   .3379757   .2044442     1.65   0.098    -.0627276     .738679
        lage |   .4767192    .353622     1.35   0.178    -.2163672    1.169806
       visit |  -.2664098   .1647096    -1.62   0.106    -.5892347    .0564151
       _cons |   2.099555   .2203709     9.53   0.000     1.667636    2.531474
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
subject: Unstructured        |
                  var(visit) |   .5314808   .2293851      .2280931    1.238406
                  var(_cons) |   .2514928   .0587892      .1590552    .3976522
            cov(visit,_cons) |   .0028715   .0887018     -.1709808    .1767238
------------------------------------------------------------------------------
LR test vs. Poisson model: chi2(3) = 324.54               Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

------------------------------------------------------------------------------
       _cons |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
       visit |   .0044339                -.3128618            .3397986
------------------------------------------------------------------------------
meqrpoisson seizures treat lbas lbas_trt lage visit || subject: visit, ///
        cov(uns) intpoints(9)
reffadjustsim _cons visit, eqn(subject) seed(12345)

Refining starting values: 

Iteration 0:  Log likelihood = -672.17188  (not concave)
Iteration 1:  Log likelihood = -660.46056  
Iteration 2:  Log likelihood = -655.86888  

Performing gradient-based optimization: 

Iteration 0:  Log likelihood = -655.86888  
Iteration 1:  Log likelihood = -655.68217  
Iteration 2:  Log likelihood = -655.68103  
Iteration 3:  Log likelihood = -655.68103  

Mixed-effects Poisson regression                Number of obs     =        236
Group variable: subject                         Number of groups  =         59

                                                Obs per group:
                                                              min =          4
                                                              avg =        4.0
                                                              max =          4

Integration points =   9                        Wald chi2(5)      =     115.56
Log likelihood = -655.68103                     Prob > chi2       =     0.0000

------------------------------------------------------------------------------
    seizures | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       treat |  -.9286588   .4021638    -2.31   0.021    -1.716885   -.1404323
        lbas |   .8849767   .1312519     6.74   0.000     .6277277    1.142226
    lbas_trt |   .3379757   .2044442     1.65   0.098    -.0627276     .738679
        lage |   .4767192    .353622     1.35   0.178    -.2163672    1.169806
       visit |  -.2664098   .1647096    -1.62   0.106    -.5892347    .0564151
       _cons |   2.099555   .2203709     9.53   0.000     1.667636    2.531474
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
subject: Unstructured        |
                  var(visit) |   .5314808   .2293851      .2280931    1.238406
                  var(_cons) |   .2514928   .0587892      .1590552    .3976522
            cov(visit,_cons) |   .0028715   .0887018     -.1709808    .1767238
------------------------------------------------------------------------------
LR test vs. Poisson model: chi2(3) = 324.54               Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

------------------------------------------------------------------------------
       _cons |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
       visit |   .0044339                -.3128618            .3397986
------------------------------------------------------------------------------

Example 6: repeated group variable

webuse nlswork, clear
version 12: xtmixed ln_w grade age || idcode: tenure union, cov(uns) || ///
    idcode: race, cov(uns) var
version 12: reffadjustsim tenure union, eqn(idcode) sub(1) seed(12345)
version 12: reffadjustsim race _cons, eqn(idcode) sub(2) seed(12345)
(National Longitudinal Survey of Young Women, 14-24 years old in 1968)

Performing EM optimization: 

Performing gradient-based optimization: 

Iteration 0:  Log likelihood = -5208.9293  
Iteration 1:  Log likelihood = -5196.8989  (not concave)
Iteration 2:  Log likelihood = -5176.1013  
Iteration 3:  Log likelihood = -5174.4196  
Iteration 4:  Log likelihood = -5171.2001  
Iteration 5:  Log likelihood = -5171.0595  
Iteration 6:  Log likelihood = -5171.0493  
Iteration 7:  Log likelihood = -5171.0492  

Computing standard errors:

Mixed-effects ML regression                         Number of obs    =  19,008
Group variable: idcode                              Number of groups =   4,132
                                                    Obs per group:
                                                                 min =       1
                                                                 avg =     4.6
                                                                 max =      12
                                                    Wald chi2(2)     = 2164.18
Log likelihood = -5171.0492                         Prob > chi2      =  0.0000

------------------------------------------------------------------------------
     ln_wage | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       grade |    .083625   .0022067    37.90   0.000        .0793      .08795
         age |   .0104518   .0004215    24.80   0.000     .0096256    .0112779
       _cons |   .2739857   .0306868     8.93   0.000     .2138407    .3341308
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
idcode: Unstructured         |
                 var(tenure) |   .0007758   .0000666      .0006556    .0009181
                  var(union) |   .0514475   .0041886      .0438594    .0603483
           cov(tenure,union) |   .0016667   .0004909      .0007044    .0026289
-----------------------------+------------------------------------------------
idcode: Unstructured         |
                   var(race) |   .0202217   .0139137      .0052498    .0778921
                  var(_cons) |   .1578058    .031278      .1070066    .2327211
             cov(race,_cons) |  -.0401861    .022046     -.0833954    .0030232
-----------------------------+------------------------------------------------
               var(Residual) |   .0583641   .0007602      .0568929    .0598732
------------------------------------------------------------------------------
LR test vs. linear model: chi2(6) = 10154.21              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

------------------------------------------------------------------------------
      tenure |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
       union |   .0321253                 .0121897            .0521846
------------------------------------------------------------------------------

------------------------------------------------------------------------------
        race |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
       _cons |  -.2544331                 -.476558           -.1166022
------------------------------------------------------------------------------
mixed ln_w grade age || idcode: tenure union, cov(uns) || idcode: race, ///
    cov(uns)
reffadjustsim tenure union, eqn(idcode) sub(1) seed(12345)
reffadjustsim race _cons, eqn(idcode) sub(2) seed(12345)

Performing EM optimization ...

Performing gradient-based optimization: 
Iteration 0:  Log likelihood = -5208.9293  
Iteration 1:  Log likelihood = -5199.2605  (not concave)
Iteration 2:  Log likelihood =   -5175.53  (not concave)
Iteration 3:  Log likelihood = -5173.8245  
Iteration 4:  Log likelihood = -5171.2707  
Iteration 5:  Log likelihood = -5171.0525  
Iteration 6:  Log likelihood = -5171.0492  
Iteration 7:  Log likelihood = -5171.0492  

Computing standard errors ...

Mixed-effects ML regression                         Number of obs    =  19,008
Group variable: idcode                              Number of groups =   4,132
                                                    Obs per group:
                                                                 min =       1
                                                                 avg =     4.6
                                                                 max =      12
                                                    Wald chi2(2)     = 2164.18
Log likelihood = -5171.0492                         Prob > chi2      =  0.0000

------------------------------------------------------------------------------
     ln_wage | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       grade |    .083625   .0022067    37.90   0.000        .0793      .08795
         age |   .0104518   .0004215    24.80   0.000     .0096256    .0112779
       _cons |   .2739857   .0306868     8.93   0.000     .2138407    .3341307
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
idcode: Unstructured         |
                 var(tenure) |   .0007758   .0000666      .0006556    .0009181
                  var(union) |   .0514475   .0041886      .0438595    .0603483
           cov(tenure,union) |   .0016667   .0004909      .0007044    .0026289
-----------------------------+------------------------------------------------
idcode: Unstructured         |
                   var(race) |   .0202217   .0139134      .0052499      .07789
                  var(_cons) |   .1578059   .0312773      .1070075    .2327191
             cov(race,_cons) |  -.0401862   .0220455     -.0833945    .0030222
-----------------------------+------------------------------------------------
               var(Residual) |   .0583641   .0007602      .0568929    .0598732
------------------------------------------------------------------------------
LR test vs. linear model: chi2(6) = 10154.21              Prob > chi2 = 0.0000

Note: LR test is conservative and provided only for reference.

------------------------------------------------------------------------------
      tenure |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
       union |   .0321253                 .0121897            .0521846
------------------------------------------------------------------------------

------------------------------------------------------------------------------
        race |     Median              2.5 Percentile      97.5 Percentile
-------------+----------------------------------------------------------------
       _cons |  -.2544335                -.4765523           -.1166046
------------------------------------------------------------------------------