Home  /  Resources & Support  /  Introduction to Stata basics  /  One-sample t-tests calculator

Sometimes, we would like to test the equivalence of a sample mean with a hypothetical mean, but we do not have the raw data. We can use summary statistics to calculate a one-sample t test using Stata's ttesti command command followed by four numbers:

The number of observations in the sample (50)
The sample mean (104)
The sample standard deviation (15)
The mean under the null hypothesis (100)

. ttesti 50 104 15 100

One-sample t test
Obs Mean Std. err. Std. dev. [95% conf. interval]
x 50 104 2.12132 15 99.73705 108.263
mean = mean(x) t = 1.8856 H0: mean = 100 Degrees of freedom = 49 Ha: mean < 100 Ha: mean != 100 Ha: mean > 100 Pr(T < t) = 0.9674 Pr(|T| > |t|) = 0.0653 Pr(T > t) = 0.0326

The output gives us a lot of information.

The sample is labeled "x", and the top of the output echoes the number of observations, mean, and standard deviation from the sample and estimates the standard error and 95% confidence interval. The output reminds us that the mean under the null hypothesis is 100.

The bottom section of the output displays the results of the t test. The t statistic is 1.89 with 49 degrees of freedom. The output then displays three possible alternative hypotheses. The p-value of 0.9674 on the bottom left is for the one-sided alternative hypothesis that the sample mean is less than 100. The p-value of 0.0653 in the bottom middle is for the two-sided alternative hypothesis that the sample mean is not equal to 100. The p-value of 0.0326 on the bottom right is for the one-sided alternative hypothesis that the sample mean is greater than 100.

You can use the level() option to change the level of the confidence interval.

. ttesti 50 104 15 100, level(90)

One-sample t test
Obs Mean Std. err. Std. dev. [95% conf. interval]
x 50 104 2.12132 15 100.4435 107.5565
mean = mean(x) t = 1.8856 H0: mean = 100 Degrees of freedom = 49 Ha: mean < 100 Ha: mean != 100 Ha: mean > 100 Pr(T < t) = 0.9674 Pr(|T| > |t|) = 0.0653 Pr(T > t) = 0.0326

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.

See it in action

Watch One-sample t-test calculator.

Tell me more

Read more in the Stata Base Reference Manual; see [R] ttest.