Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# RE: st: non-nested random effects

 From Raf Van Gestel To statalist@hsphsun2.harvard.edu Subject RE: st: non-nested random effects Date Fri, 12 Aug 2011 10:28:46 +0200

```Dear all,

I have a statistical question concerning the analysis made in the previous
question (see below) which I cannot figure out myself, it would be very
helpful to me to know how it works as I am working on a similar research
design.

As it is clear from the structure of the data there is maximum 1
observation per combination of NAME and Year. Reading in the book of
Gelman and Hill (data analysis using regression and
multilevel/hierarchical Models), there is a section explaining that adding
an explanatory variable which has information on each observation is in
essence the same as fitting a separate regression model for each
combination of NAME and Year in this case (p.290) . Now I wonder how this
can work with only 1 observation for each combination. In other words, how
is the effect of such a variable calculated? i.e. the effect of one of the
following variables in the example below Sex01F PL2Age2 Sex01FxPL2Age2
PL2Age3
nFin1974toPrev MinCC PzCDrp MinCCxPzCDrp

Thanks for any response

Raf

----------------------------------------------------------------
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, www.r-project.org, 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.

Details:

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 (www.r-project.org, 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.

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 6369 (20110811) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 6370 (20110811) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 6370 (20110811) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus
signature database 6370 (20110811) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```