I'm considering a model where children are nested within schools, but may change schools over time. So, I have data structured as `CHILDID, Y1, X1, SCHOOLID1, Y2, X2, SCHOOLID2, ...`

I initially considered having a single random effect value per school, and having $y_{i,t,school} = \mu_{school} + \dots$, but I'm not sure how to index the same random effect by different variables over time (i.e. `mu[SCHOOL1]`

, `mu[SCHOOL2]`

) in this way.

I then considered having a random effect per school *per time*, which seemed like a better idea, but it seems unclear to me how to account for dependency of the random effect within schools over time (similar issue to above, to correlate the random effects would require indexing by different values within the same model).

Anyone have any idea how I can estimate something like this?

It depends on the size of your dataset. If you have very small data then you can create any arbitrary model structure. However, it will get too slow for larger data. Consider Stan for such complex models.

Around 4k observations, so probably not "very small". I might go with Stan, but I'd be more likely to try TMB first.

Thanks