Mon - Fri : 08:00 AM - 5:00 PM
734.544-8038

Estimating HLM Models Using Stata: Part 1

Estimating HLM Models Using Stata: Part 1

///
Comment0

Note: For a fuller treatment, download our series of lectures Hierarchical Linear Models.

The Empty Model

As a first step, R&B begin with an empty model containing no covariates.

hlm16-95

Each school’s intercept, β0j, is then set equal to a grand mean, γ00, and a random error u0j.

hlm17-96

Substituting (2) into (1) produces

hlm18-97

The syntax to estimate this in Stata is


. xtmixed mathach || id:   , var

 

The .xtmixed command estimates multilevel models (or any model with a mix of fixed and random effects) in Stata. Due to the lack of any predictors, only the dependent variable appears after the command. The double bars || separate the random effects portion of the model from the fixed effects portion. The clustering variable (plus a colon) is listed first following the double bars, with the default being to automatically include a random intercept. The names of any variables with random slopes would follow the grouping variable; there are none in the empty model. The var option is not required. It tells Stata to report random effects as variances rather than as standard deviations.

The output is the following:


. xtmixed mathach || id:   , var

Performing EM optimization: 

Performing gradient-based optimization: 

Iteration 0:   log restricted-likelihood = -23558.397  
Iteration 1:   log restricted-likelihood = -23558.397  

Computing standard errors:

Mixed-effects REML regression                   Number of obs      =      7185
Group variable: id                              Number of groups   =       160

                                                Obs per group: min =        14
                                                               avg =      44.9
                                                               max =        67


                                                Wald chi2(0)       =         .
Log restricted-likelihood = -23558.397          Prob > chi2        =         .

------------------------------------------------------------------------------
     mathach |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   12.63697   .2443943    51.71   0.000     12.15797    13.11598
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
id: Identity                 |
                  var(_cons) |   8.614081   1.078813      6.739162    11.01062
-----------------------------+------------------------------------------------
               var(Residual) |   39.14832   .6606445      37.87466    40.46481
------------------------------------------------------------------------------
LR test vs. linear regression: chibar2(01) =   986.12 Prob >= chibar2 = 0.0000

These results correspond to Table 4.2 in R&B.

The next step is to estimate a means-as-outcomes model.

Still have questions? Contact us!