A paired t-test is used to compare the means of two samples when each observation in one sample can be paired with an observation in the other sample.
This tutorial explains how to conduct a paired samples t-test in Stata.
Example: Paired t-test in Stata
Researchers want to know if a new fuel treatment leads to a change in the average mpg of a certain car. To test this, they conduct an experiment in which they measure the mpg of 12 cars with and without the fuel treatment.
Since each car receives the treatment, we can conduct a paired t-test in which each car is paired with itself to determine if there is a difference in average mpg with and without the fuel treatment.
Perform the following steps to conduct a paired t-test in Stata.
Step 1: Load the data.
First, load the data by typing use http://www.stata-press.com/data/r13/fuel in the command box and clicking Enter.
Step 2: View the raw data.
Before we perform a paired t-test, let’s first view the raw data. Along the top menu bar, go to Data > Data Editor > Data Editor (Browse). The first column, mpg1, shows the mpg for the first car without fuel treatment while the second column, mpg2, shows the mpg for the first car with the fuel treatment.
Step 3: Perform a paired t-test.
Along the top menu bar, go to Statistics > Summaries, tables, and tests > Classical tests of hypotheses > t test (mean-comparison test).
Choose Paired. For First variable, choose mpg1. For Second variable, choose mpg2. For Confidence level, choose any level you’d like. A value of 95 corresponds to a significance level of 0.05. We will leave this at 95. Lastly, click OK.
The results of the paired t-test will be displayed:
We are given the following information for each group:
Obs: The number of observations. There are 12 observations in each group.
Mean: The mean mpg. In group 0, the mean is 21. In group 1, the mean is 22.75.
Std. Err: The standard error, calculated as σ / √n
Std. Dev: The standard deviation of mpg.
95% Conf. Interval: The 95% confidence interval for the true population mean of mpg.
t: The test statistic of the paired t-test.
degrees of freedom: The degrees of freedom to be used for the test, calculated as #pairs-1 = 12-1 = 11.
The p-values for three different two sample t-tests are displayed at the bottom of the results. Since we are interested in understanding if the average mpg is simply different between the two groups, we will look at the results of the middle test (in which the alternative hypothesis is Ha: diff !=0) which has a p-value of 0.0463.
Since this value is smaller than our significance level of 0.05, we reject the null hypothesis. We have sufficient evidence to say that the true mean mpg is different between the two groups.
Step 5: Report the results.
Lastly, we will report the results of our paired t-test. Here is an example of how to do so:
A paired t-test was conducted on 12 cars to determine if a new fuel treatment lead to a difference in mean miles per gallon.
Results showed that the mean mpg was statistically significantly different between the two groups (t = -2.2444 w/ df=11, p = .0463) at a significance level of 0.05.
A 95% confidence interval for the true difference in population means resulted in the interval of (-3.466, -.034).
Based on these results, the new fuel treatment leads to a statistically significantly higher mpg for cars.