Sometimes, we would like to test the equivalence of two sample means, but we do not have the raw data. We can use summary statistics to calculate a two-sample t test using Stata's ttesti command followed by six numbers:
The number of observations in group 1 (20)
The mean in group 1 (20)
The standard deviation in group 1 (5)
The number of observations in group 2 (32)
The mean in group 2 (15)
The standard deviation in group 2 (4)
. ttesti 20 20 5 32 15 4 Two-sample t test with equal variances
Obs Mean Std. err. Std. dev. [95% conf. interval] | ||
x | 20 20 1.118034 5 17.65993 22.34007 | |
y | 32 15 .7071068 4 13.55785 16.44215 | |
Combined | 52 16.92308 .6943785 5.007235 15.52905 18.3171 | |
diff | 5 1.256135 2.476979 7.523021 | |
The output gives us a lot of information.
Group 1 is labeled "x", and group 2 is labeled "y". The top of the output echoes the number of observations, mean, and standard deviation in both groups and estimates the standard error and 95% confidence interval for both groups.
The output also reports the same information for the combined groups as well as the difference between the two groups.
The bottom section of the output displays the results of the t test. The t statistic is 3.98 with 50 degrees of freedom. The null hypothesis is that there is no difference between the sample means. The output displays three possible alternative hypotheses. The p-value of 0.9999 on the bottom left is for the one-sided alternative hypothesis that the difference between the means is less than zero. The p-value of 0.0002 in the bottom middle is for the two-sided alternative hypothesis that the difference between the means is not equal to zero. The p-value of 0.0001 on the bottom right is for the one-sided alternative hypothesis that the difference between the means is greater than zero.
There are several options that may be useful under different circumstances. You can use the unequal option to conduct a t test assuming unequal variances in the two groups using Satterthwaite's (1946) approximation formula for the degrees of freedom.
. ttesti 20 20 5 32 15 4, unequal Two-sample t test with unequal variances
Obs Mean Std. err. Std. dev. [95% conf. interval] | ||
x | 20 20 1.118034 5 17.65993 22.34007 | |
y | 32 15 .7071068 4 13.55785 16.44215 | |
Combined | 52 16.92308 .6943785 5.007235 15.52905 18.3171 | |
diff | 5 1.322876 2.311343 7.688657 | |
You can use the welch option to conduct a t test assuming unequal variances in the two groups using Welch's (1947) approximation formula for the degrees of freedom.
. ttesti 20 20 5 32 15 4, welch Two-sample t test with unequal variances
Obs Mean Std. err. Std. dev. [95% conf. interval] | ||
x | 20 20 1.118034 5 17.65993 22.34007 | |
y | 32 15 .7071068 4 13.55785 16.44215 | |
Combined | 52 16.92308 .6943785 5.007235 15.52905 18.3171 | |
diff | 5 1.322876 2.315387 7.684613 | |
You can use the level() option to change the level of the confidence interval.
. ttesti 20 20 5 32 15 4, level(90) Two-sample t test with unequal variances
Obs Mean Std. err. Std. dev. [95% conf. interval] | ||
x | 20 20 1.118034 5 18.06677 21.93323 | |
y | 32 15 .7071068 4 13.80109 16.19891 | |
Combined | 52 16.92308 .6943785 5.007235 15.7598 18.08636 | |
diff | 5 1.256135 2.894837 7.105163 | |
You can watch a demonstration of these commands by clicking on the link to the YouTube video below. You can read more about these commands by clicking on the links to the Stata manual entries below.
Read more in the Stata Base Reference Manual; see [R] ttest.