How to Run a One-Way ANOVA in Stata
So you’ve mastered the T-test, survived the Chi-Squared, and now you’ve reached… the One-Way ANOVA.
Don’t panic.
A One-Way ANOVA is really just a statistical test used to compare the means of three or more independent groups.
For example, maybe we want to know whether sperm count differs depending on how many soy meals someone eats each week.
- Dependent Variable (DV): Sperm count
- Independent Variable (IV): Number of soy meals eaten each week
Because there are four groups (No Soy, 1 Soy Meal, 4 Soy Meals and 7 Soy Meals), we use a One-Way ANOVA instead of a T-test.
The actual Stata commands are surprisingly straightforward. The hardest part is simply remembering the order to run everything.
Here’s the workflow I use.
One-Way ANOVA Stata Commands
| Task | Command |
|---|---|
| Check group frequencies | tabulate group |
| Means and standard deviations | tabstat DV, by(group) statistics(n mean sd) |
| Create boxplot | graph box DV, over(group) |
| Test normality | by group, sort: swilk DV |
| Plot histograms | histogram DV, by(group) |
| Test equal variances | robvar DV, by(group) |
| Run One-Way ANOVA | anova DV group |
| Alternative ANOVA output | oneway DV group, tabulate |
| Tukey post hoc comparisons | pwcompare group, mcompare(tukey) |
Step 1: Check your descriptives
Before running any statistical test, it’s always a good idea to understand your data first.
Run these commands:
tabulate grouptabstat DV, by(group) statistics(n mean sd)graph box DV, over(group)
Replace DV with your dependent variable and group with your grouping variable.
For example:
tabulate smealtabstat spcount, by(smeal) statistics(n mean sd)graph box spcount, over(smeal)
These commands tell you:
- How many participants are in each group
- Each group’s mean
- Each group’s standard deviation
- Whether one group already appears noticeably higher or lower than the others
- Whether there are any obvious outliers
The boxplot is especially useful because it gives you a quick visual summary of your data before you move on.
Example

Step 2: Check the assumptions
| Assumption | Stata Command | Good Result | Bad Result |
|---|---|---|---|
| Normality | by group, sort: swilk DV | p > .05 | p < .05 |
| Visual normality | histogram DV, by(group) | Rough bell shape | Strong skew or unusual shape |
| Equal variances | robvar DV, by(group) | p > .05 | p < .05 |
Normality
Run:
by group, sort: swilk DV
Example:
by smeal, sort: swilk spcount

The Shapiro-Wilk test checks whether each group’s data is approximately normally distributed.
Good: p > .05
Bad: p < .05
Remember that ANOVA is generally fairly robust to mild violations of normality, particularly when group sizes are similar.
Visual normality
It’s always worth checking the distributions visually too.
Run:
histogram DV, by(group)
You’re looking for distributions that are reasonably bell-shaped.
Small departures from normality are usually fine, but severe skewness or unusual shapes may be worth mentioning.
Equality of variances
Run:
robvar DV, by(group)
Example:
robvar spcount, by(smeal)

This checks whether the spread of scores is similar across all groups.
You’re hoping for:
p > .05
If the result is significant (p < .05), the assumption has been violated.
Step 3: Run the One-Way ANOVA
Once you’ve checked the assumptions, running the ANOVA itself is easy.
Use the command:
anova DV group
Example:
anova spcount smeal

Alternatively, you can run:
oneway DV group, tabulate
This produces a slightly different output that includes a useful summary table.

Step 4: Interpret your results
The main values you’ll be interested in are:
- F statistic – the ANOVA test statistic
- Prob > F – your p-value
- R-squared – proportion of variance explained by the model (sometimes reported)
- Degrees of freedom (df)
The decision is simple.
If p < .05
→ There is a statistically significant difference between at least one of the group means.
If p > .05
→ There is no statistically significant difference between the groups.
Remember that ANOVA only tells you that a difference exists somewhere.
It does not tell you which groups differ.
For that, you’ll need post hoc tests.
Step 5: Run post hoc tests
If your ANOVA is statistically significant, run Tukey pairwise comparisons.
pwcompare group, mcompare(tukey)
Example:
pwcompare smeal, mcompare(tukey)
Tukey compares every group against every other group while controlling for Type I error.
If your ANOVA wasn’t significant, you generally don’t interpret the post hoc tests.

Example Write-Up
A one-way ANOVA was conducted to examine whether sperm count differed according to the number of soy meals consumed each week. The analysis showed that there was no statistically significant difference in sperm count between the four soy meal groups, F(df₁, df₂) = X.XX, p = .XXX.
If your result is significant, simply change the wording to:
A one-way ANOVA showed a statistically significant effect of soy meal consumption on sperm count, F(df₁, df₂) = X.XX, p = .XXX.
You would then report your Tukey post hoc results to explain which groups differed.One-Way ANOVA Stata Commands
And that’s it!
Once you’ve run it a couple of times, One-Way ANOVA becomes one of the quickest analyses to perform in Stata. The actual commands are simple—the only real challenge is remembering to check your assumptions before jumping straight to the results.