Table of Contents
A Repeated Measures ANOVA (Analysis of Variance) in Stata is a powerful statistical tool designed to analyze differences in means across two or more conditions when the exact same subjects or participants are measured repeatedly. This design is also known as a within-subjects design. In Stata, this analysis is performed using the anova command in conjunction with the within option, which clearly specifies the factor being tested across the repetitions.
To successfully execute this analysis, your dataset must be structured in the wide format, meaning that each measurement or occasion must occupy its own distinct variable column. The primary output provides the crucial F statistic and its corresponding p-value (Prob > F), allowing researchers to determine whether the observed differences between the group means are statistically significant or merely due to random chance.
Understanding the Repeated Measures ANOVA
The Repeated Measures ANOVA represents a specialized form of the general ANOVA structure. Its primary function is to test the null hypothesis that the population means across three or more measurement points or conditions are equal. What differentiates it from a standard independent groups ANOVA is the core requirement that the same subjects are present in every single condition being compared.
This method is highly advantageous because it controls for individual differences between subjects, thereby increasing statistical power. Since the same individuals serve as their own controls, any variability due to inherent individual characteristics is effectively partitioned out of the error term, resulting in a more sensitive test for the treatment effect. Researchers typically employ this analysis when efficiency is paramount and when measuring subjects multiple times is feasible and appropriate for the study design.
When to Apply One-Way Repeated Measures ANOVA
A one-way Repeated Measures ANOVA is utilized in two fundamental types of research designs. In both situations, the defining characteristic is that the independent variable has three or more levels, and all participants experience every level of that independent variable.
The first and most common application involves measuring the dependent variable across three or more specific time points. This longitudinal approach allows researchers to track changes or development over time. For instance, a researcher might investigate the impact of a novel training regimen on physiological metrics. This involves repeated measurements on the same individuals at different stages of the intervention.
Scenario 1: Measuring Mean Scores Across Multiple Time Points. Consider a study assessing resting heart rate. Measurements might be taken one month prior to program initiation (Baseline), mid-way through the program, and one month after completion (Follow-up). The goal is to determine if the mean resting heart rate significantly changes across these three temporal stages.
In this example, the repeated measurement on the same subjects at distinct points in time justifies the use of the one-way Repeated Measures ANOVA. The repeated nature of the data collection is critical for this analysis.
The second primary scenario involves exposing subjects to three or more distinct experimental conditions or treatments. While not strictly longitudinal, the logic remains the same: the subject serves as their own control across all levels of the factor.
Scenario 2: Measuring Mean Scores Under Three or More Different Conditions. Imagine a study where subjects are asked to watch three different types of movies—e.g., Action, Comedy, and Drama—and then rate their enjoyment level for each movie immediately afterward. The movie type serves as the within-subjects factor with three levels.
Since the same group of subjects provides a rating for every movie type, we employ a one-way Repeated Measures ANOVA to test if there is a statistically significant difference in mean enjoyment ratings across the three movie conditions. This tutorial will walk you through the practical steps of conducting this analysis using Stata.
Example Scenario: Drug Reaction Times
To illustrate the procedure, we will analyze a classic experimental design. A team of researchers is interested in comparing the efficacy of four different pharmaceutical drugs (Drug A, Drug B, Drug C, and Drug D) on human reaction time. Five individual patients participate in the study, and critically, each patient is tested under the influence of all four drugs, administered sequentially with appropriate washout periods.
The dependent variable is the measured reaction time, and the independent variable is the drug type (four levels). Because we have the same five patients measured across the four conditions, this necessitates the use of a Repeated Measures ANOVA. Our objective is to determine whether the mean reaction time shows a statistically significant variance depending on which drug the patient has taken.
Preparing and Loading Data in Stata (Steps 1 & 2)
The first step in any statistical analysis within Stata is to load the necessary dataset. For this specific example, we utilize a standard dataset provided by Stata Press, which is formatted appropriately for repeated measures analysis.
Step 1: Load the Data.
To load the required dataset directly from the web, navigate to the Command window in Stata and execute the following command:
First, load the data by typing use http://www.stata-press.com/data/r14/t43 in the command box and clicking Enter.

This command loads a dataset named t43, which contains the reaction time scores (the dependent variable) for the five patients across the four drug conditions.
Step 2: View the Raw Data Structure.
Before proceeding with the analysis, it is essential to inspect the data structure. Unlike some other statistical software packages that require “long” format for repeated measures, the Stata command for repeated measures ANOVA requires the data to be in “long” format where variables are listed by subject and condition. To view the data, go to the top menu bar: Data > Data Editor > Data Editor (Browse).
This view displays the response times (score) for each of the five patients (person) under each of the four drug conditions (drug). Notice that there are 20 total observations (5 patients * 4 drugs), with a row for every person-drug combination, which is the required long format structure for the anova command in Stata when using the appropriate options.

Executing the Repeated Measures ANOVA Command (Step 3)
The analysis can be performed either through the command line or via the graphical user interface (GUI). For clarity and ease of use, we will utilize the GUI method, which correctly sets up the within-subjects parameters necessary for the analysis.
To access the ANOVA dialog box, go to Statistics > Linear models and related > ANOVA/MANOVA > Analysis of variance and covariance (ANOVA, one-way, two-way, and N-way). The critical step is specifying the correct model and identifying the repeated measure.
Within the dialog box, you must specify the following parameters: For the Dependent variable, select score (reaction time). For the Model, choose person and drug as the two explanatory variables. The variable person serves as the blocking factor to account for individual variability, and drug is the factor of interest. Crucially, check the box labeled Repeated-measures variables and specify drug as the variable that repeats, indicating the within-subjects factor. After configuring these settings, click OK.

Executing this command generates two primary tables in the Stata output viewer, providing the results of the Repeated Measures ANOVA. These tables contain all the necessary statistics for interpreting the main effect of the drug condition.
Interpreting the Primary ANOVA Output
The first table presented summarizes the conventional ANOVA results, listing the Sum of Squares, Degrees of Freedom (df), Mean Square, the F statistic, and the associated probability value (Prob > F) for the specified factors (person, drug, and the residuals).

The primary result of interest is the row corresponding to the drug variable, which represents the main effect across the four conditions. In this specific output, we look for the calculated F statistic and the corresponding p-value. Here, the F value is 24.76, and the probability (Prob > F) is 0.000. Since the p-value (0.000) is significantly less than the conventional alpha level of 0.05, we reject the null hypothesis. This finding indicates that there is a statistically significant difference in the mean reaction times across the four different drugs.
Handling the Assumption of Sphericity
The second table generated in the Stata output addresses a critical requirement unique to repeated measures designs: the sphericity assumption. This assumption posits that the variances of the differences between all possible pairs of within-subject conditions (e.g., Drug A minus Drug B, Drug B minus Drug C, etc.) must be equal. When this assumption is violated, the calculated F-ratio becomes inflated, leading to an increased risk of Type I error (false positive).
If the sphericity assumption is violated (often checked via Mauchly’s test, though Stata’s output immediately provides corrected p-values), the researcher must apply a correction factor to adjust the degrees of freedom used in the F-test calculation. The second table provides the results based on three widely accepted correction methods:
The p-value for the variable drug is presented for each of these three correction factors:
The Hunyh-Feldt (H-F) p-value: This is typically the least conservative correction. For our data, H-F p-value = 0.000.
The Greenhouse-Geisser (G-G) p-value: This is generally considered more conservative than H-F. For our data, G-G p-value = 0.0006.
Box’s conservative (Box) p-value: This is the most conservative correction, treating the degrees of freedom as if there were only two conditions. For our data, Box p-value = 0.0076.
In this specific example, notice that every one of the corrected p-values (0.000, 0.0006, 0.0076) remains less than the 0.05 significance level. Therefore, even if the sphericity assumption were severely violated, the conclusion would remain the same: there is a highly statistically significant difference among the mean reaction times due to the type of drug administered.
Reporting the Final Results (Step 4)
The final and most crucial step in the analysis is to formally report the findings of the Repeated Measures ANOVA in an academic or formal style, typically adhering to APA guidelines. A proper report includes context, the statistical test used, the degrees of freedom, the calculated F-ratio, and the p-value.
When reporting, the degrees of freedom for the F-test are denoted as F(df effect, df error). For the main effect of drug, this corresponds to F(3, 12) from the primary ANOVA table (df for drug = 3, and residual df = 12).
Here is an example demonstrating how to formally present these results:
A one-way Repeated Measures ANOVA was conducted on 5 individuals to examine the effect that four different pharmaceutical drugs had on patient response time. The analysis demonstrated that the type of drug administered resulted in statistically significant differences in mean response time, F(3, 12) = 24.75, p < 0.001. Due to the high significance, post-hoc analysis would be required to determine which specific drug pairs differed from each other.
Cite this article
stats writer (2025). How to Run a Repeated Measures ANOVA in Stata: A Step-by-Step Guide. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-to-perform-a-repeated-measures-anova-in-stata/
stats writer. "How to Run a Repeated Measures ANOVA in Stata: A Step-by-Step Guide." PSYCHOLOGICAL SCALES, 29 Dec. 2025, https://scales.arabpsychology.com/stats/how-to-perform-a-repeated-measures-anova-in-stata/.
stats writer. "How to Run a Repeated Measures ANOVA in Stata: A Step-by-Step Guide." PSYCHOLOGICAL SCALES, 2025. https://scales.arabpsychology.com/stats/how-to-perform-a-repeated-measures-anova-in-stata/.
stats writer (2025) 'How to Run a Repeated Measures ANOVA in Stata: A Step-by-Step Guide', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-to-perform-a-repeated-measures-anova-in-stata/.
[1] stats writer, "How to Run a Repeated Measures ANOVA in Stata: A Step-by-Step Guide," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, December, 2025.
stats writer. How to Run a Repeated Measures ANOVA in Stata: A Step-by-Step Guide. PSYCHOLOGICAL SCALES. 2025;vol(issue):pages.


