How to perform a One Sample t-test in Stata?

To perform a One Sample t-test in Stata, first enter the data into the program and then use the ttest command, followed by the desired data and the hypothesized mean. The output of the command will show the t-statistic, degrees of freedom, and p-value, which can be used to determine the statistical significance of the results.


A  is used to test whether or not the mean of a population is equal to some value.

This tutorial explains how to conduct a one sample t-test in Stata.

Example: One Sample t-test in Stata

Researchers want to know if automobiles, on average, get 20 miles per gallon. They collect a sample of 74 cars and wish to conduct a one sample t-test to determine if the true average mpg is 20 or not.

Perform the following steps to conduct a one sample t-test.

Step 1: Load the data.

First, load the data by typing use http://www.stata-press.com/data/r13/auto in the command box and clicking Enter.

One sample t-test in Stata example

Step 2: View the raw data.

Before we perform a one sample t-test, let’s first view the raw data. Along the top menu bar, go to Data > Data Editor > Data Editor (Browse). This will show us a bunch of information about each of the 74 cars, but keep in mind we’re only interested in miles per gallon (the mpg column):

Viewing raw data in Stata

Step 3: Perform a one sample t-test.

Along the top menu bar, go to Statistics > Summaries, tables, and tests > Classical tests of hypotheses > t test (mean-comparison test).

Keep One-sample selected. For Variable name, choose mpg. For Hypothesized mean, type in 20. For Confidence level, choose any level you’d like. A value of 95 corresponds to a significance level of 0.05. We will leave this at 95. Lastly, click OK.

One sample t-test with Stata

The results of the one sample t-test will be displayed:

One sample t-test interpretation in Stata.

Obs: The number of observations. In this case, there are 74 total cars.

Mean: The mean mpg of all cars. In this case, the mean is 21.2973 miles per gallon.

Std. Err: Calculated as σ / √n = 5.785503 / √74 = .6725511.

Std. Dev: The standard deviation of mpg. In this case, it’s 5.785503.

95% Conf. Interval: The 95% confidence interval for the true population mean.

t: The test statistic, calculated as (x – u) / (σ / √n)= (21.2973-20) / 5.785503 / √74 = 1.9289.

degrees of freedom: The degrees of freedom to be used for the t-test, calculated as n-1 = 74-1 = 73.

The p-values for three different one sample t-tests are displayed at the bottom of the results. Since we are interested in understanding if the true average mpg is 20 or not, we will look at the results of the middle test (in which the alternative hypothesis is Ha: mean !=20) which has a p-value of 0.0576.

Since this value is not smaller than our significance level of 0.05, we fail to reject the null hypothesis. We do not have sufficient evidence to say that the true mean mpg for this population of cars is different than 20 mpg.

Step 4: Report the results.

Lastly, we will report the results of our one sample t-test. Here is an example of how to do so:

A one sample t-test was conducted on 74 cars to determine if the true population mean mpg was different than 20 mpg.

 

Results showed that the true population mean was not different than 20 mpg (t = 1.9289 w/ df = 73, p = .0576) at a significance level of 0.05.

 

A 95% confidence interval for the true population mean resulted in the interval of (19.9569, 22.63769).

x