Wednesday, August 15, 2007

Get estimates of group levels in a multilevel model in Stata

Appendix C in Data Analysis Using Regression and Multilevel/Hierarchical Models of professor Gelman and Hill has documented commands and codes for fitting multilevel models in various software (R, SAS, SPSS, STATA and ADMB).

I once took a class called analysis of time series cross sectional data. In class, we have a demo of how to fit a linear mixed model (varying intercepts and slopes). The command is xtmixed. I remember instructor told us one pity thing about stata's xtmixed model is that it cannot give us the estimates for group levels. He thus suggests us an alternative package in R. The package of which was used a lot in the aforementioned book is lme4. I took the instructor's word for granted.

But one day, I tried to challenge his word and did a research on xtmixed. Apparently, he was wrong. We can get the estimates for random effects in stata. Here is the sample code (the fake data is here):

* fit a varying intercept and slope model
xtmixed y x, || group: x

* get estimates for the group level
predict u0 u1, reffects
list u0 u1

2 comments:

Vivien said...

I heard State 11 has improved a lot on multilevel analysis. Have you tried the new version yet?

Vivien

Yu-Sung Su said...

No. Unfortunately, I have no access to the new stata, yet. I would like to test on the newly improved multilevel functions.