[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: non-nested random effects

From   Jacob Wegelin <>
Subject   st: non-nested random effects
Date   Mon, 6 Apr 2009 18:54:15 -0400

I am looking for a way to fit a linear mixed-effects model with
non-nested, as distinguished from crossed, random effects. I know how
to do this in a competing software package (R,, the
lme4 library), and would like to do it in Stata instead. My attempt
with xtmixed does not reproduce what I am able to do in R.


Suppose that a group of individuals ran a yearly race over 22 years.
Some ran it only once; some ran it many times. The outcome is the time
they took to finish. Because almost 3000 people participated over the
years, the data contain over 5000 observations.

I want to fit a linear mixed-effects model with two, non-nested,
random intercepts: NAME (the runner's ID) and Year.

Fixed effects include the runner's age and sex and the ambient
temperature on the day of the run. Note that Year, as a random effect,
is categorical and is distinct from runner's age. I believe that the
Year random effect is necessary because years differ from each other
in ways not captured by the data.

I assume that the Year and NAME random effects are independent from
each other, and that errors are independent conditioned on the model.

The following code does not yield the desired result:

-xtmixed FinishTime Sex01F PL2Age2 Sex01FxPL2Age2 PL2Age3
nFin1974toPrev MinCC PzCDrp MinCCxPzCDrp || NAME: || Year:  -

because it "thinks" that Year takes on as many levels as there are
rows in the data, rather than 22 levels. This is shown by the
following fragment of output from the above command:

Mixed-effects REML regression                   Number of obs      =      5276

                |   No. of       Observations per Group
 Group Variable |   Groups    Minimum    Average    Maximum
           NAME |     2933          1        1.8         21
           Year |     5276          1        1.0          1

In R (, the lme4 library) I am able to fit the model
I want. The output includes 2933 BLUPs (best linear unbiased
predictors) for NAME random effects and only 22 BLUPs for Year random
effects. In particular, the software does not think that Year takes on
5276 levels.

Is there a way to fit such a model in Stata?

Rabe-Hesketh (2005), Multilevel and Longitudinal Modeling Using Stata,
has a chapter on "crossed random effects." But this appears to lead to
the kind of model fit above by xtmixed.

Thanks for any advice

*   For searches and help try:

© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index