I'm used to HLM 7 software and now I'd like to switch to Stata, for multilevel modelling (xtmixed).

To give an example imagine I have students(level1) nested within schools (level2). In HLM I can easily add a second level variable (for instance schools beauty) choosing the equation of a coefficient (or intercept) which is at level 2.

Imagine I want to include the effect of school beauty in B0 (intercept). How can I do that in Stata?


1 Answer 1


I found the solution here:


The answer is:

whereas HLM requires two separate data les (one corresponding to each level), SPSS, Stata, SAS, and R rely on only a single file. The level-2 observations are common to each case within the same macro-unit, so that if there are 50 students in one school the corresponding school-level score appears 50 times. Each program also requires an id variable identifying the group membership of each individual.

So, adding a second level variable to the model, like the school sector (Sector), can be easily done via the xtmixed command. For instance:

xtmixed MatGrade Intelligence Sector || SchoolId:

Where "MatGrade" is the outcome variable, "Intelligence" is a level 1 variable reflecting the intelligence of the scholars. Scholars are nested within schools.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.