Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

In Stata, how do I estimate mixed or multilevel linear models?

In Stata 11, you can use the .xtmixed command to estimate multilevel mixed-effects linear models, also known as mixed-effects, multilevel, or hierarchical models. Mixed models have both fixed effects and random effects, and are appropriate for cases when observations are clustered in some manner (e.g., students within schools, voters within districts, or workers within firms).

As an example, suppose you want to predict GRE verbal scores based on a student's GPA and hours spent preparing for the exam. If you have observations on students from multiple colleges, you may also explore how the expected outcome (average GRE score) and slopes of the predictors change across schools. This hypothetical data set would have five variables:

id: Identifies a particular student
college: Refers to the student's school
gre: The outcome variable
gpa: Measures the student's grade point average
prep: Number of hours spent studying for the exam

The following commands estimate different mixed models for this data set:

.xtmixed gre prep gpa || college: .xtmixed gre prep gpa || college: gpa .xtmixed gre prep gpa || college: prep gpa

A dependent variable gre is listed first and followed by the independent variables in the .xtmixed command. The || characters are followed by a grouping variable college, a colon, and a list of variables whose effects you wish to model as random. The first example estimates a random intercept model only. The second adds the random coefficients for the GPA variable, while the third model allows for the intercept and both slopes to change across groups.

For help with the .xtmixed command, enter help xtmixed in Stata, or consult "Longitudinal/Panel Data" in the Stata 11 manual.

For multilevel non-linear models, see the following commands: .xtlogit, .xtprobit, .xttobit, .xtpoisson, .xtnbreg, .xtmelogit and .xtmepoisson.

For more about statistical and mathematical software, email the UITS Stat/Math Center, visit the center's web page, or phone 812-855-4724 (IUB) or 317-278-4740 (IUPUI). The center is located in Bloomington at 410 N. Park Avenue, and is open for consultation by appointment Monday-Friday 9am-5pm.

This is document atdh in domain all.
Last modified on March 30, 2011.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.