MLwiN Manual Chapter 18 Cross-classified code

Welcome to the forum for runmlwin users. Feel free to post your question about runmlwin here. The Centre for Multilevel Modelling take no responsibility for the accuracy of these posts, we are unable to monitor them closely. Do go ahead and post your question and thank you in advance if you find the time to post any answers!

Go to runmlwin: Running MLwiN from within Stata >> http://www.bristol.ac.uk/cmm/software/runmlwin/
Post Reply
erikruzek
Posts: 16
Joined: Tue May 21, 2019 3:57 pm

MLwiN Manual Chapter 18 Cross-classified code

Post by erikruzek »

Hello,

I am trying out the code provided for runmlwin to replicate the analyses in the MLwiN Users Manual (thank you for doing that, Chris and George!) and I have a question about some of the code for cross-classified models in Chapter 18.

To run the model in 18.4, the runmlwin .do file has the following code that comes after you create the school dummy variables:

Code: Select all

local c = 1
forvalues s=2/19 {
	constraint define `c' [RP3]var(s1) = [RP3]var(s`s')
	local c = `c' + 1	
}
And then it has the syntax to run the model using runmlwin.

However, if I do not run that bit of code and run the model, the results are exactly the same. Is this code needed? If so, what is it doing?

Thanks,
Erik
ChrisCharlton
Posts: 1351
Joined: Mon Oct 19, 2009 10:34 am

Re: MLwiN Manual Chapter 18 Cross-classified code

Post by ChrisCharlton »

These lines define the constraint that the level-3 variances are all equal and correspond to the numbers in the constraints option passed to runmlwin:

Code: Select all

constraints(1/18)
If you run the model without these then these then the variances will be estimated as different:

Code: Select all

. runmlwin attain cons, ///
>         level3(cons: s1-s19, diagonal) ///
>         level2(pid: cons) level1(pupil: cons) ///
>         nopause
 
MLwiN 3.03 multilevel model                     Number of obs      =      3435
Normal response model
Estimation algorithm: IGLS

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
           cons |        1       3435     3435.0       3435
            pid |      148          1       23.2         72
-----------------------------------------------------------

Run time (seconds)   =       1.73
Number of iterations =          7
Log likelihood       = -8566.0265
Deviance             =  17132.053
------------------------------------------------------------------------------
      attain |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        cons |   5.709704   .1181172    48.34   0.000     5.478199     5.94121
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 3: cons                |
                     var(s1) |          0          0             0           0
                     var(s2) |          0          0             0           0
                     var(s3) |   .5790943   1.032502     -1.444572    2.602761
                     var(s4) |          0          0             0           0
                     var(s5) |          0          0             0           0
                     var(s6) |   .1585827    .396016     -.6175945    .9347599
                     var(s7) |          0          0             0           0
                     var(s8) |    1.62833   2.651101     -3.567731    6.824392
                     var(s9) |   .7782774   1.379918     -1.926312    3.482867
                    var(s10) |    .132258   .4859599     -.8202059    1.084722
                    var(s11) |          0          0             0           0
                    var(s12) |   .6527393   1.072904     -1.450115    2.755593
                    var(s13) |          0          0             0           0
                    var(s14) |          0          0             0           0
                    var(s15) |          0          0             0           0
                    var(s16) |          0          0             0           0
                    var(s17) |   .1225453   .3672506     -.5972527    .8423433
                    var(s18) |          0          0             0           0
                    var(s19) |    4.30737    6.29295     -8.026587    16.64133
-----------------------------+------------------------------------------------
Level 2: pid                 |
                   var(cons) |    1.10217   .1892235      .7312989    1.473041
-----------------------------+------------------------------------------------
Level 1: pupil               |
                   var(cons) |   8.099678   .1994997      7.708665     8.49069
------------------------------------------------------------------------------
whereas including them sets the variances to be equal:

Code: Select all

. runmlwin attain cons, ///
>         level3(cons: s1-s19, diagonal) ///
>         level2(pid: cons) level1(pupil: cons) ///
>         constraints(1/18) nopause
 
 ( 1)  [RP3]var(s1) - [RP3]var(s2) = 0
 ( 2)  [RP3]var(s1) - [RP3]var(s3) = 0
 ( 3)  [RP3]var(s1) - [RP3]var(s4) = 0
 ( 4)  [RP3]var(s1) - [RP3]var(s5) = 0
 ( 5)  [RP3]var(s1) - [RP3]var(s6) = 0
 ( 6)  [RP3]var(s1) - [RP3]var(s7) = 0
 ( 7)  [RP3]var(s1) - [RP3]var(s8) = 0
 ( 8)  [RP3]var(s1) - [RP3]var(s9) = 0
 ( 9)  [RP3]var(s1) - [RP3]var(s10) = 0
 (10)  [RP3]var(s1) - [RP3]var(s11) = 0
 (11)  [RP3]var(s1) - [RP3]var(s12) = 0
 (12)  [RP3]var(s1) - [RP3]var(s13) = 0
 (13)  [RP3]var(s1) - [RP3]var(s14) = 0
 (14)  [RP3]var(s1) - [RP3]var(s15) = 0
 (15)  [RP3]var(s1) - [RP3]var(s16) = 0
 (16)  [RP3]var(s1) - [RP3]var(s17) = 0
 (17)  [RP3]var(s1) - [RP3]var(s18) = 0
 (18)  [RP3]var(s1) - [RP3]var(s19) = 0
MLwiN 3.03 multilevel model                     Number of obs      =      3435
Normal response model
Estimation algorithm: IGLS

-----------------------------------------------------------
                |   No. of       Observations per Group
 Level Variable |   Groups    Minimum    Average    Maximum
----------------+------------------------------------------
           cons |        1       3435     3435.0       3435
            pid |      148          1       23.2         72
-----------------------------------------------------------

Run time (seconds)   =       1.75
Number of iterations =          4
Log likelihood       = -8574.5656
Deviance             =  17149.131
------------------------------------------------------------------------------
      attain |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        cons |   5.504051   .1748762    31.47   0.000     5.161299    5.846802
------------------------------------------------------------------------------

------------------------------------------------------------------------------
   Random-effects Parameters |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
Level 3: cons                |
                     var(s1) |    .347889   .1622717      .0298423    .6659356
                     var(s2) |    .347889   .1622717      .0298423    .6659356
                     var(s3) |    .347889   .1622717      .0298423    .6659356
                     var(s4) |    .347889   .1622717      .0298423    .6659356
                     var(s5) |    .347889   .1622717      .0298423    .6659356
                     var(s6) |    .347889   .1622717      .0298423    .6659356
                     var(s7) |    .347889   .1622717      .0298423    .6659356
                     var(s8) |    .347889   .1622717      .0298423    .6659356
                     var(s9) |    .347889   .1622717      .0298423    .6659356
                    var(s10) |    .347889   .1622717      .0298423    .6659356
                    var(s11) |    .347889   .1622717      .0298423    .6659356
                    var(s12) |    .347889   .1622717      .0298423    .6659356
                    var(s13) |    .347889   .1622717      .0298423    .6659356
                    var(s14) |    .347889   .1622717      .0298423    .6659356
                    var(s15) |    .347889   .1622717      .0298423    .6659356
                    var(s16) |    .347889   .1622717      .0298423    .6659356
                    var(s17) |    .347889   .1622717      .0298423    .6659356
                    var(s18) |    .347889   .1622717      .0298423    .6659356
                    var(s19) |    .347889   .1622717      .0298423    .6659356
-----------------------------+------------------------------------------------
Level 2: pid                 |
                   var(cons) |   1.123741   .1979374      .7357908    1.511691
-----------------------------+------------------------------------------------
Level 1: pupil               |
                   var(cons) |   8.111626   .1999722      7.719688    8.503565
------------------------------------------------------------------------------
I suspect that when you are running for the second time you haven't cleared the constraints from the original run or removed the constraints option from your command, so it is able to pick them up without you having to explicitly define them again.
erikruzek
Posts: 16
Joined: Tue May 21, 2019 3:57 pm

Re: MLwiN Manual Chapter 18 Cross-classified code

Post by erikruzek »

Ah, I see. Yes, I did not clear the constraints when I re-ran the model after re-loading the data.

Thanks, Chris!
Post Reply