Page 1 of 1

Syntax Errors Running Cross-Classified 3-Level Model via runmlwin in Stata

Posted: Sat Jun 21, 2025 10:28 am
by BrodyHannan
Hi all,

I'm hoping someone can help me troubleshoot what I suspect is a simple syntax issue.

I'm trying to run a three-level multilevel model with cross-classification using the runmlwin command in Stata, calling MLwiN v3.14. My goal is to calculate the variance components so I can compute intraclass correlation coefficients for the following structure:
  • Students (Level 1)
  • Nested within Classes (Level 2)
  • Teachers are cross-classified at Level 2 (i.e., a class may have multiple teachers and teachers teach multiple classes)
  • Schools (Level 3)
A simplified version of the syntax I’m trying is:

runmlwin achievement_score cons,
level3(school_id: )
level2(class_id: )
level2(teacher_id: )
level1(student_id: )

However, I keep getting errors such as:
  • command level3() not recognised
  • option level1() is required
I don't encounter these issues when running smaller, simpler models using just Stata's mixed command (e.g., mixed achievement_score || class_id: || teacher_id:), but unfortunately my dataset is large enough that I need to use runmlwin and MLwiN for estimation.

I’ve already:
  • Set the MLwiN path using a global macro (global MLwiN_path)
  • Installed MLwiN v3.14
  • Installed runmlwin via SSC
I'm hoping this is just a simple syntax issue - I'd be very grateful for any guidance or example syntax to point me in the right direction.

Thank you in advance,
Brody

Re: Syntax Errors Running Cross-Classified 3-Level Model via runmlwin in Stata

Posted: Thu Jun 26, 2025 1:58 pm
by ChrisCharlton
The first thing to check would be that your command is conceptually on one line. You can split it across several lines to aid readability, however you would need to put /// at the end of each line to indicate a line continuation.

You can only specify each level once in runmlwin, so you can't have level2() twice as in your example. Although called level2, level3, etc in the syntax when you turn on cross-classification the meaning changes to level2=classification 1, level3=classification 2, etc. As these are no longer nested the ordering no longer matters (although level1 must stay the same as this defines the individual units).

Unless you want to use constraints to implement cross-classification in (R)IGLS (see https://www.bristol.ac.uk/cmm/media/run ... ed_Data.do) then cross-classification in only implemented for MCMC estimation. See https://www.bristol.ac.uk/cmm/media/run ... _Models.do and the corresponding chapter in the manual for examples using this.

You will need to make sure that the ID value for each unit of classification is unique, unlike in nested models where a new unit is assumed wherever the ID value is different to the one above.

runmlwin does not automatically include an intercept term (represented as a column of ones for the predictor), so you probably want to add this to your specification.

If each pupil can attend more than one class, and/or have more than one teacher then you may well want to fit this as multiple-membership (see https://www.bristol.ac.uk/cmm/media/run ... _Models.do). This will require specifying weights to indicate the proportion of the students outcome associated with each of these.