Stata Help

Run An Independent Means T-test in Stata

An independent means t-test compares two sets of scores from two different groups of people. The null hypothesis is that the two groups do not differ significantly from one another. The dependent variable is the score (for example, level of intrinsic motivation) and the independent variable is whatever differentiates the two scores (for example, gender).

To run an independent means t-test in Stata requires one grouping variable (a.k.a. the independent variable) and one continuous, discrete, normally distributed variable (the dependent variable). Once these are available, type ttest [dependent variablename], by([independent variable])

The output from this command is fairly simple. In the example below, we want to test if a made up sample of college students'  hours spent on homework each night significantly differs by class year (freshman vs. junior). 

Screenshot of two-sample t test with equal variances.

When Variances Aren't Equal

In addition to the basic t-test, Stata has options for cases where the variances aren't approximately equal (an assumption of the independent-test). To see whether the standard deviations are approximately equal, you can use the built-in Stata command, typing sdtest variable, by(sortingvariable) . Similar to the t-test output, this test yields the following result:

Screenshot of variance ratio test.

In addition to the sdtest, Stata will perform Levene's test of equal variances. It will report the initial result as well as the same test performed with a median replacement and a 10% trimmed mean replacement, based on the thoughts of two statisticians. To run this command type robvar variable, by(sorting variable) The output will yield the following result:

Screenshot of Levene’s test of equal variances.

If these tests come back with a significant result (meaning the variances are not equal) you can simply add unequal to the t-test-command. Doing so will cause Stata to run a Satterthwaite approximation on the data (calculating the t-statistic without equal variances) To see a nicely detailed example of the Satterthwaite, see here . Thus the whole command would look something like ttest intrinsi, by(gender) unequal

If you prefer, you can request that Stata run a Welch approximation, which can be useful in small sample-size situations (see here for a brief explanation of Welch's approximation). To run it, the command would simply become ttest intrinsi, by(gender) welch

Back