Week 8 Assignment

 This week we will begin our unit on mean testing! For this exercise, you will need a few combinations of variables that are nominal and interval/ratio. I will be using “mntlhlth,” a ratio measure of “days of poor mental health in past month,” and “sexornt,” a nominal measure of sexual orientation. You should follow along with me, and complete the activity using these variables. When you are finished, you must go back and re-trace your steps with your own variables. Submit both in your log and do file for this week’s assignment, but copy only your work on your own variable into your ongoing portfolio do file.

Imagine that I’m interested in the relationship between sexual orientation and mental health.

To do this, we will use a mean-testing strategy. In particular we will be calculating confidence intervals and using t-tests.

Let’s begin by looking at the variables on their own. We’ll run a quick tabulation of each, and retrieve some descriptive statistics:

tab1 mntlhlth sexornt
sum mntlhlth
sum sexornt
tab mntlhlth sexornt, col

Some of this information is easier to metabolize than others. But take some time to evaluate the descriptive information. Interpret the mean and standard deviation of both variables.

Next, let’s quickly consider the normality of the variable mntlhlth by producing a histogram. Does this variable appear to be normally distributed? Why or why not?

Let’s try a normality test in Stata. One option is the sktest command (we won’t use this much):

sktest mntlhlth

*Legit data analysts don’t love the way Stata evaluates normality with this command. What you’re looking at here aren’t the skewness and kurtosis values, but values that test whether you can reject the null hypothesis of normality. We don’t have the skills to interpret this yet. But we’ll be back.

A more familiar way to look at our variable is with a more involved descriptive statistic:

sum mntlhlth, det

Remember, a perfectly normal curve has a skewness of 0 and a kurtosis of 3. Would you describe this variable as normal? Positively skewed? Negatively skewed? Leptokurtic? Platykurtic? Mesokurtic?


So let’s examine the central tendency of mntlhlth more carefully. We know that the mean of the sample is about 3.9. But we do not know the mean of the population. And we cannot know the population mean exactly, but we can make an inference! Confidence intervals allow us to make these kinds of inferences.

We’re going to use a new command (found in “Relationships between Different Measurement Levels” under the “Testing Means” subheading in the Longest text). This command is “ci” for “confidence interval.” We are going to use the “means” option, thought you can run confidence interval tests on other values.

ci means mntlhlth

The output looks similar to the output of the sum command, but it includes “Std. Error” and “95% Confidence Interval” as well. The way we interpret this value is by saying that we can say with 95% confidence that the true population mean of American adults is between the two listed values. In this case, “we can say with 95% confidence that the mean number of days of poor mental health for American adults is between 3.5 and 4.3.”

*For 99% confidence, use the “level(99)” option at the end of your command.

Another way to test the population mean, is with a T-test. There are two kinds of T-tests and they serve different functions: one-sample t tests, and two-sample t tests. We’ll begin with a one sample t-test, which allows us to consider the likelihood that the mean of a population is a particular value.

Imagine that you are developing a national public health program, offering subsidized therapy online. Your team wants to maximize impact, while minimizing costs, and you’d like to move forward with some confidence that the average number of poor mental health days for American adults is less than 5. You would use the following command

ttest mntlhlth

Focus on the three results at the bottom of the output. These represent three tests:

 “Ha: mean < 5”     “Ha: mean != 5”     “Ha: mean > 5”

The first is a test of the likelihood that the population mean is less than 5, the second, a test of the likelihood that the pop. mean is not 5, and the third is a test of the possibility that the pop. mean is greater than 5. Each has lifted its own t-test, which produces what we call a “p value.” The way we interpret these can be a bit counter-intuitive, so pay close attention.

The three output values range from 0.000 to 1.000, and you would say that you can confidently “reject the null hypothesis” if that value is less than “.05.” Put another way, there is less than a 5% probability that the null hypothesis is true.

So let’s look at the middle test. The p value is 0.000, which is less than .05. We can say, then, with 95% confidence (or “with statistical significance”) that the population mean does not equal 5.

Now consider the test to the left. The p value is 0.000, which is less than .05. We can say, then, with 95% confidence (or “with statistical significance”) that the population mean is less than 5. Literally, it is only 5% likely that the null hypothesis is true.

And finally, consider the test to the right. The p value is 1.000, which is much greater than .05. We cannot report statistical significance on this hypothesis, as we do not have enough confidence to reject the null hypothesis.

(When attempting this test with your own variable, interpret all outputs, and imagine a real-world situation as I did above, where this test might be valuable)


Next, we’ll work on a two-group t-test, or an “independent samples t-test.” Imagine we’re interested in whether population means on the variable mntlhlth are significantly different for populations with different sexual orientations. For this, we need to convert our nominal variable (sexornt) into a binary variable so that we have two groups to compare. You may do this however you like with your own variables. I compiled the categories for gay and bisexual respondents to create an LGB group (1) and a heterosexual group (2).

recode sexornt (1/2=1)(3=2), gen(binarysexuality)  

We can then use the ttest command again…

ttest mntlhlth, by(binarysexuality)

For me, it looks like this:

ttest output.png

Your output may be different because I offered you two years of GSS data when you were downloading. That’s ok! Follow along with me, and feel free to interpret my output or your own. For one of the years there are significant results ;)

This produces a lot of information. You can see the means, standard deviations, and confidence intervals listed for each of the two sexual orientation groups. And you can see the combined scores. What is particularly helpful for us, is the row titled “diff.” You can see here that the difference in means between groups is about .22. Beneath it, is a measure of whether that difference in means is statistically significant. Specifically, you have three measures of significance, in whether the difference in means is less than, different from, or greater than 0. << This is how you will interpret the p values. If the p value is less than .05, that value is significant. In this case, none of the values are less than .05, so none of the results are significant. We cannot reject the null hypothesis and conclude that the means are significantly different.

Let’s consider another example where there’s something significant to interpret. Let’s make a binary race variable to compare white and “non-white,” and run another ttest:

recode race (1=1)(2/3=2), gen(racebinary)
ttest mntlhlth, by(racebinary)

Here we have something we can interpret more meaningfully. How would you interpret the output?

(What you’re doing is new and scary. Just try. I’ll walk you through it on Thursday step by step)