How do you perform a Two-Way ANOVA in Stata?

To perform a Two-Way ANOVA in Stata, you first need to set up the data in a wide or long format. Once the data is set up, you need to use the anova command, followed by the dependent variable and two independent variables, separated by asterisks. This will generate a table of results that display the sum of squares, degrees of freedom, F statistic, and p-value for each variable, as well as the overall F statistic and p-value.


A  is used to determine whether or not there is a statistically significant difference between the means of three or more independent groups that have been split on two factors.

The purpose of a two-way ANOVA is to determine how two factors impact a response variable, and to determine whether or not there is an interaction between the two factors on the response variable.

This tutorial explains how to conduct a two-way ANOVA in Stata.

Example: Two-Way ANOVA in Stata

In this example we will use the built-in Stata dataset called systolic to perform a two-way ANOVA. This dataset contains the following three variables for 58 different individuals:

  • Drug used
  • Patient’s disease
  • Change in systolic blood pressure

We will use the following steps to perform a two-way ANOVA to find out if the type of drug used and the patient’s disease type has a significant impact in the change in systolic blood pressure.

Step 1: Load the data.

First, load the data by typing webuse systolic in the command box and clicking Enter.

Systolic dataset in Stata example

Step 2: View the raw data.

Before we perform a two-way ANOVA, let’s first view the raw data. Along the top menu bar, go to Data > Data Editor > Data Editor (Browse). This will show us the actual data for all 58 patients:

Two-way ANOVA example in Stata

Step 3: Perform a two-way ANOVA.

Along the top menu bar, go to Statistics > Linear models and related > ANOVA/MANOVA > Analysis of variance and covariance.

For Dependent variable, choose systolic. Then, click the three dots  …  next to the dropdown arrow under Model.

Example of a two-way ANOVA in Stata

Two-way ANOVA in Stata

The original window will appear with drug##disease now filled in under Model. You don’t need to do anything here again. Simply click OK.

Two-way ANOVA in Stata

The results of the two-way ANOVA will automatically appear:

Two-Way ANOVA results in Stata

From the output we can observe the following:

  • There is no significant interaction between drug and disease (p-value = 0.3958)
  • Disease has no significant effect on systolic blood pressure (p-value = 0.1637)
  • Drug has a statistically significant effect on systolic blood pressure (0.0001)

Step 4: Report the results.

Lastly, we will report the results of our two-way ANOVA analysis. Here is an example of how to do so:

A two-way ANOVA was conducted on 58 individuals to examine the effect that drug and disease has on systolic blood pressure.

 

There was no significant interaction between the effects of drug and disease on systolic blood pressure (p = 0.3958). There was no significant effect of disease on systolic blood pressure (p = 0.1637). There was a significant effect of drug on systolic blood pressure (0.0001). 

x