How To Run A One-Way ANOVA In Stata

✦ ✦ ✦
Descriptive alt text here

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

TaskCommand
Check group frequenciestabulate group
Means and standard deviationstabstat DV, by(group) statistics(n mean sd)
Create boxplotgraph box DV, over(group)
Test normalityby group, sort: swilk DV
Plot histogramshistogram DV, by(group)
Test equal variancesrobvar DV, by(group)
Run One-Way ANOVAanova DV group
Alternative ANOVA outputoneway DV group, tabulate
Tukey post hoc comparisonspwcompare 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 group
tabstat 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 smeal
tabstat 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

AssumptionStata CommandGood ResultBad Result
Normalityby group, sort: swilk DVp > .05p < .05
Visual normalityhistogram DV, by(group)Rough bell shapeStrong skew or unusual shape
Equal variancesrobvar DV, by(group)p > .05p < .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.

Hi, I’m Daisy!

I created The Psych Diaries to make studying psychology a little less overwhelming. Here you’ll find study guides, Stata tutorials, psychology resources, and everything I’m learning along the way!

About Me →

Popular Guides


🤍 Thanks for stopping by. I hope you find something here that helps!

Discover more from The Psych Diaries

Subscribe now to keep reading and get access to the full archive.

Continue reading