A **one sample t-test** 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.

**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):

**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*.

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

Here is how to interpret the results:

**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

notdifferent 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).