Internet Guide to Stata |
Print article |
The t distribution, developed by "Student" (a pseudonym of W. Gosset) more than 100 years ago, is used for a number of testing purposes. "The t-test", however, refers to a test of the difference between two means (one of which might be hypothetical value against which the mean of an observed variable is tested).
The t-test is often used to compare the means of two groups. This works as follows:
ttest income, by(married)
There are a few options that can be appended: unequal (or "un) informs Stata that the variances of the two groups are unequal; welch (or w) requests Stata to use Welch's approximation to the t-test (which has the nearly the same effect as unequal; only the d.f. are different) and finally, with level(99) (or l) you can, in this case, request a confidence level of 99 per cent instead of the default level of 95, which is used in the calculation of confidence intervals.
How do you know whether the two groups have the same variances? Use
sdtest income, by(married)
to obtain the Bartlett test for equality of variances, or
robvar income, by(married)
which delivers a robust test proposed by Levene in 1960 and two alternatives by Brown & Forsythe in 1974. One of these alternatives uses the median instead of the mean in Levene's original formula and the other one the 10 per cent trimmed mean. These robust tests are more appropriate in the case of skewed variables.
Sometimes the two means to be compared come from the same group of observations, for instance, from measurements at points in time t1 and t2. Here, The appropriate version of the t-test is:
ttest incomet1 == incomet2
The level(..) option described in the previous section is available as well.
Here, the command goes like this:
ttest IQ = 110
Again, the level(..) option is available.
Another interesting possibility is to do t-tests using information about group sizes, means, and standard deviations, instead of the raw data. This information may be entered immediately with the "ttesti" command, with "i" signalling the "immediate" variety of the t-test.
Finally, Stata offers the possibility of running Hotelling's generalized t-test. See Stata help for more detail.
© W. Ludwig-Mayerhofer, Stata Guide | Last update: 10 Sep 2013