I am trying to estimate school effects on student scores. I ran a model with student effects as a random effect and school effects as fixed effects as follows:

xtreg studentscore lagstudentscore limitedEng poor `gradeyeardum' `schoolyeardum', re

where student score is regressed on lag of student score, student's language proficiency and poverty status, and a set of grade-year dummy variables and a set of school-year dummy variables. The coefficients on the school-year dummy variables are the key fixed effects of interest.

I want to estimate an equivalent model using xtmixed. I ran the code below but the MLE doesn't seem to converge - I got the "not concave" message for several iterations. Here's the code I ran:

xtmixed studentscore lagstudentscore limitedEng poor `gradeyeardum' schoolyeardum', || schnamyearid : || studentid:

I am not sure if I should estimate both the individual level and school level standard deviations for the variance component. I am interested in the school level variation, so perhaps the following model makes more sense?

xtmixed studentscore lagstudentscore limitedEng poor `gradeyeardum' schoolyeardum', || schnamyearid :

1 Answer 1


If prior to running the xtreg command you have xtset the data with the student as the panel, then your xtreg model is assuming random student effects but fixed effects for everything else. To fit the corresponding model using xtmixed (or mixed, as it's called in Stata 13), you just swap xtmixed for xtreg, and put the variable which was your panel variable (studentid?) as a random effect:

xtmixed studentscore lagstudentscore limitedEng poor gradeyeardum'schoolyeardum' || studentid:

If you model schools' effects as fixed effect, you will get a coefficient estimate for the effect of each school (relative to some baseline school) on the students' scores. If you have lots of schools, and you are interested in the effects' of schools on students scores (or rather how much scores cluster by school), and you're not particularly interested in estimating the differences between particular schools, then it may well be better to model school as a random effect, using something like:

xtmixed studentscore lagstudentscore limitedEng poor gradeyeardum'schoolyeardum' || schooldid: || studentid:
  • $\begingroup$ Thanks for the comment Jonathan. I actually tried running both models. The first one yields estimates of school effects so that is great. When I run the second model, I get a message, "numerical derivatives are approximate - nearby values are missing", by the log likelihood it reads "not concave". I am not too worried as I get the estimates from the first model. However, I do have a followup question. I am new to the Hierarchical Linear Models. Here's my follow-up question - I apologize in advance if it's too rudimentary. Please find the question below: $\endgroup$
    – Robbie
    Sep 13, 2014 at 23:27
  • $\begingroup$ How can I account for the autocorrelation and heteroskedasticity at the first level or student level? In other words, I have repeat observations for each student (over several years), so the student level errors are going to be certainly autocorrelated and potentially hetoroskedastic. I should probably modify the above code don't I? Or, does the above command address both of these issues? Please let me know. Thanks. $\endgroup$
    – Robbie
    Sep 13, 2014 at 23:32
  • $\begingroup$ The second model allows for correlation between the measurements from the same student, by virtue of having a student random-effect. But it assumes a very simplistic correlation structure - that the correlation between any two measurements on the same student is the same, irrespective of which years they took place in. If the measurements are taken at a small number of distinct time points, e.g. year 1 - year t, you could allow for the correlation in a less restrictive manor, by removing the student random effect but modelling the residual errors using an unstructured covariance matrix... $\endgroup$ Sep 13, 2014 at 23:41
  • $\begingroup$ The syntax for this would be: xtmixed studentscore lagstudentscore limitedEng poor gradeyeardum'schoolyeardum' || schooldid: || studentid:, nocons resid(unstructured, t(year)) where year is the variable indicating the year of measurement. You will then get a variance for the school random effect and an estimate of the variances and covariances (or correlations) for the residual errors. $\endgroup$ Sep 13, 2014 at 23:44
  • $\begingroup$ If I use the second model, I won't get the get a coefficient estimate for the effect of each school (which is what I want). Also, doesn't the first model also have student random-effect (which accounts for year-to-year correlation for students)? $\endgroup$
    – Robbie
    Sep 14, 2014 at 0:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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