Hello everyone,

Someone might be able to help me. The issue has not been addressed in prior posts.

I am running a simulation of a two-level model. The simulation environment is simulate and the multi-level environment is xtmixed. My target is the usual 1,000 reps but the software never reaches that mark, sometimes stopping at 200, sometimes at 300, other times at 10 iterations. It just depends on the seed. I exclude this to be: a) a problem with the simulated dataset because this works fine with regression; b) a problem with xtmixed because Stata is able to run the two-level model outside of the simulation environment.

The simulated outcome is student achievement (score_hat) which is a linear combination of a level-1 variable (IQ), a level-2 variable (urban), a cross-level interaction (urbIQ), a level-1 error (e_ij), and a level-2 error (u_i). I do not show how I create the variables to save some space, but I am doing it correctly.

Thank you.

Code:
### Creating simulation
set seed 123
program define montecarlo, rclass
drop _all
tempvar IQ urban schoolID studID u_i e_ij score_hat

# Creating dataset [NOT SHOWN...]

# Running HLM model
quietly xtmixed score_hat IQ urban urbIQ || schoolID:, var reml
return scalar b0HLM=_b[_cons]
return scalar bIQHLM=_b[IQ]
return scalar burbanHLM=_b[urban]
return scalar burbIQHLM=_b[urbIQ]

end


### Requiring 1,000 reps
simulate b0HLM=r(b0HLM) bIQHLM=r(bIQHLM) burbanHLM=r(burbanHLM) burbIQHLM=r(burbIQHLM), reps(1000): montecarlo