Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: Xtmixed specification for rmANOVA with 2 within-subject factors

From   Jared Saletin <>
Subject   st: Xtmixed specification for rmANOVA with 2 within-subject factors
Date   Sun, 3 Apr 2011 15:30:30 -0700

Dear Stata users and experts,

I'm new to Stata and trying to learn xtmixed in a two-way within-subjects anova situation, and was hoping to ask a couple questions.

I have an psychological experimental design measuring performance on a cognitive task "y" with two controlled within-subject factors:  b - 3 levels (repeated conditions), and c - 2 levels (task manipulation, e.g. memory for two different word-types during the task), with subjects coded "s".

In an ANOVA setting I would typically do: 

(1) anova y s b / b#s c / c#s b#c, repeated(b c).

We have some missing data for a few subjects, so I hoped to move to a mixed model analysis. However,  I'm slightly confused as to the proper model specification.

Because both factors are experimentally controlled across subjects, I first presumed a random-intercept only model with fixed effects for a and b, and fit:

(2) xi: xtmixed y b##c || s:, var.

And then tested the effects of a, b, and a#b using the margins command (with asbalanced option, as the experiment was intended to be balanced), followed by tests of the main effects and interaction.

However, I've noticed on the ucla page,  a similar design (except also with a between-subject factor a) using what I believe are crossed random-intercepts for b,c and the interaction, respectively:

(3) xi: xtmixed y a##b##c || _all: || _all: R.cs || _all: R.bcs || s:, var.

I was hoping that the stats and Stata experts here could help me decide which is the better alternative to the rmANOVA, the former simple random-intercept model (model #2), seems to made more immediate sense to me.

Also, am I correct that to test the anova-style omnibus effects for b (or any factor), I would simply do: "margins b, post asbalanced" followed by "test (1.b=2.b=3.b)", for instance?


As a final question, and thank you for your patience,

If I wanted to include a random-slope into the model for say factor b, and would typically adapted model (2) above to be:

xi: xtmixed y b##c || s: b, var.

How would I best do the same for crossed model (3)?

Apologies if some of this is basic, I'm just attempting to integrate all my reading and find the ideal analyses.

Thank you all for your help!

Jared Saletin
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index