3  Cross-Classified Models

3.1 Introduction

A two level multilevel model imagines that Level 1 units are nested in Level 2 units. A three level multilevel model imagines that Level 1 units are nested in Level 2 units, which are in turn nested in Level 3.

A cross-classified model imagines that the nesting is not hierarchical, but rather that there are two sets of clusters or nestings in which individuals may be nested.

3.2 Get Data


use "simulated_multilevel_longitudinal_data.dta", clear

3.3 Cross Classified Model

We can treat these random effects as being cross classified.

This might be useful if we had data where individuals lived in different countries at different times.

However, because id is in fact nested inside country, in this case, estimating the random effects as cross classified will be more time consuming, but will give us equivalent results to a three level model.

3.3.1 Standard (Less Computationally Efficient) Syntax

The below syntax will take a very long time to run with the full sample, and thus we have commented it out.

    
* mixed outcome t warmth physical_punishment || _all: R.country || _all: R.id
    
* est store crossed1

The documentation notes that we can use a much more computationally efficient version of the above command, which is what we do in these notes. The user can verify that both versions of the command will produce equivalent results.

In fact, at the end of handout we verify the similarity of both sets of syntax using a random sample.

3.3.2 Cross Classified With Computationally Efficient Syntax


mixed outcome t warmth physical_punishment || _all: R.country || id:
    
est store crossed2 // store crossed effects result
Performing EM optimization ...

Performing gradient-based optimization: 
Iteration 0:  Log likelihood = -28516.314  
Iteration 1:  Log likelihood = -28516.277  
Iteration 2:  Log likelihood = -28516.277  

Computing standard errors ...

Mixed-effects ML regression                            Number of obs =   9,000

        Grouping information
        -------------------------------------------------------------
                        |     No. of       Observations per group
         Group variable |     groups    Minimum    Average    Maximum
        ----------------+--------------------------------------------
                   _all |          1      9,000    9,000.0      9,000
                     id |      3,000          3        3.0          3
        -------------------------------------------------------------

                                                       Wald chi2(3)  = 1168.69
Log likelihood = -28516.277                            Prob > chi2   =  0.0000

-------------------------------------------------------------------------------------
            outcome | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
--------------------+----------------------------------------------------------------
                  t |   .9434605    .065866    14.32   0.000     .8143654    1.072556
             warmth |   .9053924   .0380439    23.80   0.000     .8308277    .9799572
physical_punishment |  -1.014385   .0499354   -20.31   0.000    -1.112257    -.916514
              _cons |    50.8301   .4123007   123.28   0.000       50.022    51.63819
-------------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
_all: Identity               |
              var(R.country) |   3.429974    .930313      2.015668    5.836634
-----------------------------+------------------------------------------------
id: Identity                 |
                  var(_cons) |   8.608872   .4757699      7.725107     9.59374
-----------------------------+------------------------------------------------
               var(Residual) |   26.02862   .4752444      25.11363    26.97695
------------------------------------------------------------------------------
LR test vs. linear model: chi2(2) = 1260.84               Prob > chi2 = 0.0000

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

3.4 Three Level Model


mixed outcome t warmth physical_punishment || country: || id:  // 3 level w/ random intercepts only
    
est store threelevel // store random intercept model
Performing EM optimization ...

Performing gradient-based optimization: 
Iteration 0:  Log likelihood = -28516.314  
Iteration 1:  Log likelihood = -28516.277  
Iteration 2:  Log likelihood = -28516.277  

Computing standard errors ...

Mixed-effects ML regression                            Number of obs =   9,000

        Grouping information
        -------------------------------------------------------------
                        |     No. of       Observations per group
         Group variable |     groups    Minimum    Average    Maximum
        ----------------+--------------------------------------------
                country |         30        300      300.0        300
                     id |      3,000          3        3.0          3
        -------------------------------------------------------------

                                                       Wald chi2(3)  = 1168.69
Log likelihood = -28516.277                            Prob > chi2   =  0.0000

-------------------------------------------------------------------------------------
            outcome | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
--------------------+----------------------------------------------------------------
                  t |   .9434605    .065866    14.32   0.000     .8143654    1.072556
             warmth |   .9053924   .0380439    23.80   0.000     .8308277    .9799572
physical_punishment |  -1.014385   .0499354   -20.31   0.000    -1.112257    -.916514
              _cons |    50.8301   .4123007   123.28   0.000       50.022    51.63819
-------------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects parameters  |   Estimate   Std. err.     [95% conf. interval]
-----------------------------+------------------------------------------------
country: Identity            |
                  var(_cons) |   3.429974    .930313      2.015668    5.836634
-----------------------------+------------------------------------------------
id: Identity                 |
                  var(_cons) |   8.608872   .4757699      7.725107     9.59374
-----------------------------+------------------------------------------------
               var(Residual) |   26.02862   .4752444      25.11363    26.97695
------------------------------------------------------------------------------
LR test vs. linear model: chi2(2) = 1260.84               Prob > chi2 = 0.0000

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

3.5 Nice Table of Results of Three Level and Cross Classified Model


etable, estimates(threelevel crossed2), ///
showstars showstarsnote /// show stars and note
column(estimate) // column is modelname
invalid 'showstars' 
r(198);

r(198);

3.6 Verification of Syntax Equivalence for Cross Classified Model


keep if family <= 5 // random sample of families
    
quietly mixed outcome t warmth physical_punishment || _all: R.country || _all: R.id
    
est store crossed1A // less efficient syntax
    
quietly mixed outcome t warmth physical_punishment || _all: R.country || id:
    
est store crossed2A // more efficient syntax
    
etable, estimates(crossed1A crossed2A) ///
showstars showstarsnote /// show stars and note
column(estimate) // column is modelname
(8,550 observations deleted)






------------------------------------------------------
                                  crossed1A  crossed2A
------------------------------------------------------
time                               0.745 **   0.745 **
                                 (0.281)    (0.281)   
parental warmth in past week       0.871 **   0.871 **
                                 (0.160)    (0.160)   
physical punishment in past week  -1.262 **  -1.262 **
                                 (0.206)    (0.206)   
Intercept                         51.755 **  51.755 **
                                 (1.009)    (1.009)   
var(R_country)                     2.245      2.245   
                                 (1.319)    (1.319)   
var(R_id)                          5.425              
                                 (1.843)              
var(e)                            23.638     23.638   
                                 (1.933)    (1.933)   
var(_cons)                                    5.425   
                                            (1.843)   
Number of observations               450        450   
------------------------------------------------------
** p<.01, * p<.05

3.7 QUESTIONS???