You are on page 1of 1

School of Health Systems and Public Health

HME 712 Week 1 Fact sheet bos_05

The steps to take when performing a paired t-test using Stata

a. Context:
Data are quantitative
Both observations are made on the same individual or unit of analysis
The units and scales of both observations are the same
Is the mean of one observation = mean of the other observation?
b. Conditions:
Data are quantitative and the difference between the readings ~N (may be less strict if n>30)
Do not use for non-numerical data
Data must be presented in the WIDE format with each pair of observations placed next to
one another:
unique_id reading_a reading_b
1. 12.5 12.7
2. 13.1 13.2
Etc ………. Etc ……… Etc ……..

Note in the table above that the readings for person, with unique_id = 1, are 12.5 and 12.7.
These two readings for person 1 must be next to one another, as they are in the table.
c. Create a new variable
Since the difference between the two readings must be ~N we need to create a new variable
for the difference. We can then test this new variable objectively to see if it is in fact ~N.
This new variable is defined as reading_a – reading_b (the order is unimportant for the test
that will follow). You may call it by any name. I usually call it “diff”.
d. Stata commands:
First generate a new variable for the difference between the means:

<gen diff = reading_a – reading_b>

Then test to see if “diff” is in fact ~N:

<swilk diff> (if the number of pairs is 30 or less); or


<histogram diff> if the number of pairs is greater than 30

Fail to reject H0, assume data ~N if swilk p-value > 0.05 or histogram unimodal, not too skew
Only go ahead with the paired t-test if your variable “diff” passes the ~N test, if so, then:
<ttest reading_a = reading_b>
e. Interpretation of output:
Focus on p-value (is there statistical significance?); and on
95% CI for the difference between µa and µb
If t-test p-value ≤ 0.05; reject H0 and conclude the population means are different.

NB: As this is a 2-tail test be sure to use the appropriate 2-tail p-value (the one in the middle!)

You might also like