# Chi-square test in Stata

May 13, 2019

In this tutorial we’ll look at performing a **chi-square test** in **Stata**. We’ll use the **nlsw88** dataset for this, so

`sysuse nlsw88, clear`

In order to perform a chi-square test we’ll use the **tabulate** command, by way of tabulating two categorical variables against eachother. For instance, we can get an initial overview of the relationship of two categorical by tabulating them against one another:

`tab collgrad south`

Here we just tabulated two variables against each other to get an indication whether there might be a statistical relationship between the two, ie. are women from the south represented in the survey less likely to have a college degree or not. Let’s perform a chi-square test to verify if this is the case, by appending the **chi2** option to the tabulate command:

`tab collgrad south, chi2 `

The null hypothesis we’re testing against basically says that there’s no significant difference. We can see in the result window that we’re getting a rather high value for **p**, (0.606) which is way higher than 0.05 which would be the cut off when using the 95% confidence interval. Therefore we should not reject the null hypothesis, and assume that there is no difference between college degrees between women living in the south or not.

Written by **Johan Osterberg** who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin