Introduction
A paired t test in Stata compares two columns that represent matched subjects who are measured on a continuous variable. In this blog entry, we’ll show you how to run a paired t test in Stata and combine with it appropriate graphics.
Load Data
Let’s use one of Stata’s built-in datasets. Try:
use http://www.stata-press.com/data/r13/fuel
describe
These are data on 12 cars whose mpg capacity is tested twice, once without fuel treatment (mpg1) and once with fuel treatment (mpg2).
Run the Paired T Test
You can use the following code for a paired-samples t test:
ttest mpg2=mpg1
Here’s what you get:
Thus, we see that the mean mpg for cars once they receive the fuel treatment is 1.75 higher.
Interpret the Results
In a paired samples t test, there is one p value for a two-tailed hypothesis and another for a one-tailed hypothesis. Let’s say that your hypotheses were as follows:
H0: The mean mpg for fuel treatment is lower than, or equal to, the mean mpg without fuel treatment.
HA: The mean mpg for fuel treatment is higher than the mean mpg without fuel treatment.
For this kind of hypothesis structure, you would look at Stata’s column for Ha: mean(diff > 0), because the alternative hypothesis claims that the difference between mpg2 and mpg1 will be positive (which, of course, means that getting fuel treatment results in higher mpg than not getting fuel treatment). Here, p = .0323, so you would reject the null hypothesis.
However, you could also have the following hypothesis structure:
H0: The mean mpg for fuel treatment is equal to the mean mpg without fuel treatment.
HA: The mean mpg for fuel treatment is unequal to the mean mpg without fuel treatment.
In this case, you would look at Ha: mean(diff) != 0 (note that != is Stata’s equivalent of not equal to), where p is .0463., so you would still reject the null. Note, however, that, depending on the number of tails in the hypothesis structure, there are contexts in which Ha: mean(diff) != 0 might not be significant while either Ha: mean(diff > 0) or Ha: mean(diff < 0) could be significant.
Graphics
Try the following code to visualize the results of the paired samples t test:
ciplot mpg2 mpg1
Or, if you prefer,
graph box mpg2 mpg1
BridgeText can help you with all of your statistical analysis needs.