Table of Contents
An Introduction to Repeated Measures ANOVA in Stata
The repeated measures ANOVA is a sophisticated statistical methodology utilized by researchers to evaluate differences in the mean scores of three or more related groups. Unlike a standard one-way ANOVA, which assumes that the groups being compared are independent of one another, the repeated measures variant is specifically designed for instances where the same subjects are measured multiple times. This technique is fundamentally rooted in the within-subjects design, providing a powerful way to control for individual differences between participants, thereby increasing the statistical power of the analysis.
When conducting research in Stata, this analysis becomes invaluable for interpreting complex datasets where temporal or conditional changes are the primary focus. By using the same individuals across all levels of the independent variable, researchers can effectively isolate the effect of the treatment or time from the inherent variability present between different people. This allows for a more precise estimation of the F-statistic, as the error term in the model is partitioned to remove the variance attributable to individual subject differences.
To successfully perform a repeated measures ANOVA within the Stata environment, the data must be meticulously organized. Typically, Stata expects data in a specific orientation—often referred to as the wide format or long format depending on the specific command used—to correctly identify which observations belong to the same subject. Once organized, the software executes complex calculations to determine if the observed differences in means are statistically significant or if they could have occurred by chance, as indicated by the p-value.
Theoretical Framework: Within-Subjects vs. Between-Subjects Designs
Understanding the distinction between within-subjects and between-subjects designs is crucial for any statistical practitioner. In a between-subjects design, different participants are assigned to different groups, and the analysis focuses on the variance between those groups. However, in a within-subjects design, every participant experiences every condition or is measured at every time point. This approach is highly efficient because it requires fewer participants to achieve the same level of statistical power, making it a staple in clinical trials and psychological research.
The primary advantage of the repeated measures ANOVA is its ability to reduce the “noise” or unsystematic variance within the data. Since the same person is providing data for every condition, their baseline characteristics—such as personality traits, genetics, or previous experiences—remain constant across those conditions. Consequently, any observed changes in the dependent variable are more likely to be the result of the experimental manipulation rather than individual idiosyncrasies. This leads to a more robust test of the null hypothesis.
In Stata, navigating these designs involves understanding how the software treats “factor variables” and “repeated factors.” The software is designed to handle these relationships with precision, provided the user correctly specifies the model structure. By partitioning the variance into components associated with the subjects, the treatments, and the interaction between them, the repeated measures ANOVA provides a comprehensive view of the data’s underlying patterns.
Practical Applications and Research Scenarios
There are two primary scenarios where a researcher would opt for a one-way repeated measures ANOVA over other statistical tests. The first scenario involves a longitudinal study where the objective is to track changes over time. For instance, a healthcare researcher might monitor the resting heart rate of a cohort of individuals at three distinct intervals: prior to a fitness intervention, during the intervention, and following its completion. This allow the researcher to see if the intervention had a lasting impact on cardiovascular health.
As illustrated in the image above, the key characteristic of this data is that the subjects are identical across all three columns. We are repeatedly collecting data from the same pool of participants. This consistency is what necessitates the use of the repeated measures ANOVA rather than an independent samples test, as the observations are inherently correlated.
The second common scenario is when subjects are exposed to multiple different conditions or stimuli. A classic example in media psychology might involve asking participants to watch three different films and provide a rating for each. Because each participant provides three different scores—one for each movie—the data points are not independent. The repeated measures ANOVA accounts for the fact that a “harsh” critic might give low scores to all three movies, while a “lenient” critic might give high scores across the board, thereby filtering out this individual bias.
This tutorial will provide a comprehensive, step-by-step walkthrough of how to execute this analysis in Stata, using a practical example to clarify the process. We will explore how to manage the interface, interpret the F-statistic, and ensure that your conclusions are statistically sound.
Step-by-Step Guide: Loading the Dataset for Analysis
To demonstrate the repeated measures ANOVA, let us consider a study where researchers measure the reaction times of five patients across four different pharmaceutical drugs. The goal is to determine if the type of drug significantly influences reaction speed. Since each of the five patients is tested on all four drugs, we have a perfectly balanced repeated measures design. This allows us to control for the baseline reaction speeds of each patient.
The first step in our Stata workflow is to import the necessary data. Stata provides several ways to load data, but for this example, we will use a dataset hosted on the official Stata website. This ensures that you can follow along with the exact same numbers used in this guide. Open your Stata application and locate the command console at the bottom of the interface.
In the command box, type the following instruction: use http://www.stata-press.com/data/r14/t43 and press the Enter key. This command fetches the dataset directly from the server and loads it into Stata‘s active memory, preparing it for subsequent statistical manipulation.

Exploratory Data Analysis and Data Inspection
Before diving into the complex ANOVA calculations, it is essential to inspect the raw data to ensure its integrity and structure. This stage of exploratory data analysis helps the researcher understand the relationship between the variables and identify any potential anomalies or missing values that could skew the results. In Stata, the most efficient way to do this is through the Data Editor.
Navigate to the top menu bar and select Data > Data Editor > Data Editor (Browse). This action opens a spreadsheet-like view of your current dataset. Here, you will observe the response times (the “score” variable) for each of the five patients across the four drug categories. You will see that each row represents a unique combination of a patient and a drug, which is typical of the “long format” required for certain Stata commands.

By reviewing the data in this format, you can confirm that each patient has a score for each drug. If there were gaps in the data, the repeated measures ANOVA might require different handling, such as a mixed-effects model. However, for this structured dataset, we are ready to proceed with the standard analysis of variance.
Executing the Analysis of Variance in Stata
With the data loaded and verified, we can now perform the repeated measures ANOVA. This can be done via the command line or through Stata’s intuitive graphical user interface (GUI). To use the GUI, go to Statistics > Linear models and related > ANOVA/MANOVA > Analysis of variance and covariance. This will open a dialog box where you must define the parameters of your model.
Within this dialog box, follow these specific settings to ensure the model is calculated correctly:
- For the Dependent variable, select score from the dropdown menu, as this represents the reaction times we are comparing.
- In the Model section, you must include both person and drug as the explanatory variables to account for both the subject variance and the treatment effect.
- Crucially, navigate to the Repeated-measures variables tab or checkbox. Select drug as the variable that repeats, as this tells Stata to treat the drug levels as correlated within each patient.
Once these parameters are set, click the OK button to generate the output.

Stata will process the request and immediately display two primary tables in the results window. These tables contain the core statistical findings, including the degrees of freedom, sum of squares, and the significance tests required to validate your research hypothesis.
Interpreting the Primary ANOVA Results
The output of the repeated measures ANOVA is comprehensive, but most researchers focus on a few key metrics within the first table. Specifically, you should look for the row labeled drug. This row provides the F-statistic and the associated Prob > F (the p-value). In our example, the F-value is 24.76, and the p-value is listed as 0.000. This extremely low p-value indicates that the differences in mean reaction times between the four drugs are statistically significant.

When the p-value is less than the standard alpha level of 0.05, we reject the null hypothesis that all drug means are equal. This result suggests that at least one of the drugs produces a reaction time that is significantly different from the others. However, the ANOVA itself does not tell us which specific drugs differ; for that, you would need to perform post-hoc tests or planned comparisons.
It is also important to note the “person” row in the output. This represents the variance accounted for by the individual patients. By including “person” in the model, we have effectively “cleaned” the data of individual patient differences, allowing us to see the drug effects more clearly. This is the primary reason why the repeated measures ANOVA is often more sensitive than an independent ANOVA.
Addressing the Assumption of Sphericity
A critical requirement for the validity of a repeated measures ANOVA is the assumption of sphericity. Sphericity refers to the condition where the variances of the differences between all possible pairs of within-subject conditions are equal. If this assumption is violated, the F-statistic may be positively biased, leading to an increased risk of a Type I error (falsely claiming a significant result).
In the second table provided by Stata, the software offers several correction factors to use if sphericity is not met. These include the Huynh-Feldt (H-F) epsilon, the Greenhouse-Geisser (G-G) epsilon, and Box’s conservative epsilon. These corrections adjust the degrees of freedom to produce a more accurate p-value.
Review the adjusted p-values for our drug study:
- Huynh-Feldt (H-F): p = 0.000
- Greenhouse-Geisser (G-G): p = 0.0006
- Box’s conservative (Box): p = 0.0076
Even when applying the most conservative corrections, the p-value remains well below the 0.05 threshold. Therefore, we can confidently conclude that the drug effect is robust and not an artifact of violated statistical assumptions. In professional research, it is common practice to report the Greenhouse-Geisser corrected values if there is any doubt regarding sphericity.
Synthesizing and Reporting Your Findings
The final stage of the process is to translate the statistical output into a formal report suitable for academic publication or clinical documentation. When reporting a repeated measures ANOVA, you must include the F-statistic, the degrees of freedom for both the effect and the error, and the p-value. This provides the reader with all the necessary information to evaluate the strength and reliability of your findings.
A professional summary of our drug study results might be structured as follows:
A one-way repeated measures ANOVA was conducted on 5 individuals to examine the effect that four different drugs had on response time. The analysis aimed to determine if pharmaceutical intervention significantly altered the speed of patient reactions.
Results showed that the type of drug used led to statistically significant differences in response time (F(3, 12) = 24.75, p < 0.001). These findings suggest that the drugs tested have varying impacts on cognitive or motor performance, warranting further post-hoc investigation to identify the most effective medication.
By following these steps in Stata, you ensure that your analysis is not only technically accurate but also grounded in a clear understanding of the underlying statistical theory. Whether you are tracking patient recovery over time or comparing the efficacy of different treatments, the repeated measures ANOVA remains one of the most versatile and powerful tools in the researcher’s arsenal.
Cite this article
stats writer (2026). How to Run a Repeated Measures ANOVA in Stata: A Step-by-Step Guide. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-do-you-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, 8 Mar. 2026, https://scales.arabpsychology.com/stats/how-do-you-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, 2026. https://scales.arabpsychology.com/stats/how-do-you-perform-a-repeated-measures-anova-in-stata/.
stats writer (2026) 'How to Run a Repeated Measures ANOVA in Stata: A Step-by-Step Guide', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-do-you-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, March, 2026.
stats writer. How to Run a Repeated Measures ANOVA in Stata: A Step-by-Step Guide. PSYCHOLOGICAL SCALES. 2026;vol(issue):pages.


