Login

One-Way Repeated Measures ANOVA using Stata

Introduction

A one-way repeated measures ANOVA (also known as a within-subjects ANOVA) is used to determine whether three or more group means are different where the participants are the same in each group. For this reason, the groups are sometimes called "related" groups. You will most often come across this situation for two reasons: (a) participants have been measured over multiple time points to see if there have been any changes, usually in response to an intervention; or (b) participants have been subjected to more than one condition/trial and the response to each of these conditions is to be compared.

For example, you could use a one-way repeated measures ANOVA to understand whether there is a difference in anxiety levels amongst moderately anxious participants after a hypnotherapy programme aimed at reducing anxiety (e.g., with three time points: anxiety immediately before, 1 month after and 6 months after the hypnotherapy programme). In this example, "anxiety level" is your dependent variable, whilst your independent variable is "time" (i.e., with three related groups, where each of the three time points is considered a "related group"). Alternately, you could use a one-way repeated measures ANOVA to understand whether there is a difference in downhill skiing performance based on three different coloured tints of ski goggles (e.g., ski performance under three conditions: wearing brown, blue and red tinted ski goggles). In this example, "ski performance" is your dependent variable, whilst your independent variable is "condition" (i.e., with three related groups, where each of the three conditions is considered a "related group").

In this guide, we show you how to carry out a one-way repeated measures ANOVA using Stata, as well as interpret and report the results from this test. However, before we introduce you to this procedure, you need to understand the different assumptions that your data must meet in order for a one-way repeated measures ANOVA to give you a valid result. We discuss these assumptions next.

Stata

Assumptions

There are five assumptions that underpin the one-way repeated measures ANOVA. If any of these five assumptions are not met, you might not be able to analyse your data using a one-way repeated measures ANOVA because you might not get a valid result. Since assumptions #1 and #2 relate to your study design and choice of variables, they cannot be tested for using Stata. However, you should decide whether your study meets these assumptions before moving on.

Fortunately, you can check assumptions #3, #4 and #5 using Stata. However, do not be surprised if your data fails one or more of these assumptions since this is fairly typical when working with real-world data rather than textbook examples, which often only show you how to carry out a one-way repeated measures ANOVA when everything goes well. However, don’t worry because even when your data fails certain assumptions, there can be a solution to overcome this (e.g., transforming your data or using another statistical test instead). Just remember that if you do not check that your data meets these assumptions or you test for them incorrectly, the results you get when running a one-way repeated measures ANOVA might not be valid.

In practice, checking for assumptions #3, #4 and #5 will probably take up most of your time when carrying out a one-way repeated measures ANOVA. However, it is not a difficult task, and Stata provides all the tools you need to do this.

In the section, Test Procedure in Stata, we illustrate the Stata procedure required to perform a one-way repeated measures ANOVA assuming that no assumptions have been violated. First, we set out the example we use to explain the one-way repeated measures ANOVA procedure in Stata.

Stata

Example

Current research shows that long-term, low-level inflammation can be a cause and predictor of heart disease, which is the leading cause of premature death in the Western world. One measure of long-term, low-level inflammation that can be used to assess the risk of heart disease is called C-Reactive Protein (CRP for short). It can be measured in the blood and research shows that higher levels of CRP are associated with a higher risk of heart disease. Simultaneously, it is known that if you are overweight or obese you are at an increased risk of heart disease and that dieting (i.e., reducing your body fat percentage) can lead to reductions in traditional markers of heart disease, such as cholesterol concentration.

As such, a researcher wanted to know whether dieting might also reduce low-level inflammation as assessed by CRP concentration in the blood. In order to investigate this idea, the researcher recruited 10 overweight participants who underwent a four-month dietary programme to reduce their body fat levels. CRP concentration was measured at the beginning of the dietary programme (i.e., at zero months), at the mid point (i.e., two months into dieting), and immediately after the dietary intervention (i.e., at four months). Essentially, the researcher wants to discover whether CRP concentrations decrease over the period of the dietary programme (i.e., over the three time points).

Stata

Setup in Stata

In Stata, we created three variables: (1) id, which is the case identifier variable (i.e., the variable that identifies each specific participant); (2) the independent variable, time, which indicates the time point in the study (i.e., pre-, mid- and post-dieting programme); and (3) the dependent variable, crp, which is the participants' CRP concentrations at the different time points. For time, we coded the level of the within-subjects factor (i.e., the time points) as "1" for pre-, "2" for mid-, and "3" for post-dietary programme.

After creating these three variables you can enter the data in the Data Editor (Edit) window (by clicking on the Data Editor (Edit) button just below the top menu). You will end up with the screen below:

Data editor for the repeated measures ANOVA in Stata

Published with written permission from StataCorp LP.

Stata

Test Procedure in Stata

In this section, we show you how to analyse your data using a one-way repeated measures ANOVA in Stata when the five assumptions in the Assumptions section have not been violated. You can carry out a one-way repeated measures ANOVA using code or Stata's graphical user interface (GUI). After you have carried out your analysis, we show you how to interpret your results. First, choose whether you want to use code or Stata's graphical user interface (GUI).


Code

The code to carry out a one-way repeated measures ANOVA on your data takes the form:

anova DependentVariable CaseIdentifier IndependentVariable, repeated(IndependentVariable)

In the code above, CaseIdentifier is the variable in your data set that identifies each specific case (e.g., each unique participant). In this example, this is id, which is the participant id. This code is entered into the Command box below:

Command box in Stata

Using our example where the dependent variable is crp and the independent variable (i.e., within-subjects factor) is time with three time points (coded "1", "2" and "3"), the required code would be:

anova crp id time, repeated(time)

Note: By default, Stata assumes that the independent variable(s) you enter into the anova command are categorical. As such, you do not need to add the prefix "i." to these variables (e.g., you can simply enter time rather than i.time, as we have done in this example).

Therefore, enter the code anova crp id time, repeated(time) into the Command box and press the "Return/Enter" key on your keyboard.

Command box for the repeated measures ANOVA in Stata

You can see the Stata output that will be produced here.


Graphical User Interface (GUI)

The three steps required to carry out a one-way repeated measures ANOVA in Stata are shown below:

  1. Click Statistics > Linear models and related > ANOVA/MANOVA > Analysis of variance and covariance on the main menu, as shown below:
    One-way repeated measures ANOVA menu in Stata

    Published with written permission from StataCorp LP.


    You will be presented with the anova - Analysis of variance and covariance dialogue box, as shown below:
    One-way repeated measures ANOVA dialogue box in Stata

    Published with written permission from StataCorp LP.

  2. Transfer the dependent variable, crp, into the Dependent variable: box by using the Drop-down drop-down button and then transfer the case identifier variable, id, and the independent variable, time, into the Model: box, using the Drop-down drop-down button and selecting both variables. Finally, tick the Repeated-measures variables checkbox and transfer the independent variable, time, into the box using the Drop-down drop-down button. You will be presented with the following screen:
    One-way repeated measures ANOVA dialogue box in Stata with example

    Published with written permission from StataCorp LP.

  3. Click on the OK button. This will generate the output.
Stata

Stata Output of the One-Way Repeated Measures ANOVA

Stata generates two tables in its one-way repeated measures ANOVA analysis. The first table is presented below:

First result from ANOVA with repeated measures analysis in Stata

Published with written permission from StataCorp LP.

This table provides all the information we require to report the result of the one-way repeated measures ANOVA if the assumption of sphericity is not violated. To do this, you need to consider the information displayed in the "time" and "Residual" rows. From the "time" row you require the values under the "df" (i.e., "2"), "F" (i.e., "26.94") and "Prob > F" (i.e., "0.0000") columns and the value under the "df" (i.e., "18") column from the "Residual" row. Using this information you can report the result of the one-way repeated measures ANOVA. You can see that the statistical significance of the test (i.e., the "Prob > F" column) is .0000, which we can state as p < .0005. As such, the result is statistically significant.

Alternatively, if the assumption of sphericity was violated, you can choose one of three correction factors so that the result from the one-way repeated measures ANOVA is still valid. These corrections are presented in the table below:

Second result from ANOVA with repeated measures analysis in Stata

Published with written permission from StataCorp LP.

For example, if we chose to use the Greenhouse-Geisser correction, we would need to consult the statistical significance value (i.e., p-value) under the "G-G" column, which is itself under the "Prob > F" column, in this table rather than the p-value from the first table. You can see that, even with this correction, the result is still statistically significant because p = .0001.

Note: We present the output from the one-way repeated measures ANOVA above. However, since you should have tested your data for the assumptions we explained earlier in the Assumptions section, you will also need to interpret the Stata output that was produced when you tested for them. This includes: (a) the boxplots you used to check if there were any significant outliers; and (b) the output Stata produces for your Shapiro-Wilk test for normality to determine normality. Also, remember that if your data failed any of these assumptions, the output that you get from the one-way repeated measures ANOVA procedure (i.e., the output we discuss above) might no longer be valid, and you will need to interpret the Stata output that is produced when they fail (i.e., this includes different results).

Stata

Reporting the Output of the One-Way Repeated Measures ANOVA

You could report the output of the test above as follows (not including the tests of assumptions or introduction to the analysis):

  • General

A one-way repeated measures ANOVA was run on a sample of 10 overweight participants to determine if there were differences in CRP concentration due to a four-month dietary programme. The results showed that the dietary programme elicited statistically significant differences in mean CRP concentration over its time course, F(2, 18) = 26.94, p < 0.005.

1