Stata Help

Running a Nested ANOVA in Stata

In addition to having within- and between-subject factors Stata can do nested ANOVAs with relative ease. As in the simpler repeated-measures example, nested ANOVAs require that the data be in a long format. Click here to learn a bit more about what makes a design nested.

With your data properly arranged, a nested ANOVA simply requires the proper specifications to the anova command. Stata uses the | (shift backslash) to indicate a nested term. For instance, if my variable, A, had three levels of B within it that I wanted to run an ANOVA on the command would be anova [dependent variable] B|A However, this would only test B within A .

To test B within A as well as A itself, the command becomes anova [dependent variable] A / B|A / The slashes tell Stata that the item following the slash is the error term for what precedes it. In this case A is tested with the error term of B nested in A. The final slash tells Stata to test B nested in A using the residual error. If no error term is specified, Stata tests against the residual error.

Stata can run this data with unequal cells, but such unbalancing makes the F-statistic less representative of the data. In the case of unequal cell sizes you may want to run a Satterthwaite approximation, though in some cases this will make for a less accurate p-value. If you cannot use a Satterthwaite approximation, your p-value is more conservative than reality, so this is likely only a concern for values that are nearly significant.

The output for the above example looks as follows:

As usual, the very first line echoes the inputted command. The actual results from the analysis follows in sections. Stata uses lines to differentiate between pieces tested with the same error term. The error term is the last thing listed. In this case, the output shows that factor A, tested using the error of B in A was significant and factor B, nested in A and tested against the residual error was also significant.

While this example only shows second level nesting, more complicated designs can have many layers of nesting. Just make sure you test against the right error term and Stata will handle complicated nested ANOVA designs with ease.

Back to ANOVA