Introduction
Spearman correlation is an alternative to Pearson correlation that can be used when the relationship between variables is monotonic—for example, in the context of two variables, when the variables rise or fall together, but not at a constant rate. In this blog, we’ll show you how to use Stata to conduct Spearman correlation and also offer some guidance on when to use Spearman correlation.
Load Initial Data
Let’s use one of the datasets Stata uses to illustrate Spearman correlation.
use https://www.stata-press.com/data/r17/states2
describe
Running Parallel Pearson and Spearman Regressions: Managing an Extreme Value
On this dataset, let’s start with:
pwcorr medage mrgrate, sig
We note that there is no significant Pearson correlation between marriage rate (per 100,000) and median age by state. However, we can also observe that there is an extreme outlier, Nevada, in the dataset (note that many people go to Nevada in order to get married):
scatter mrgrate medage
Let’s run that correlation again on all states except Nevada. We don’t have to drop Nevada; we can move it to row 50 by sorting on marriage rate, then excluding row 50 from the next Pearson correlation:
sort mrgrate
pwcorr medage mrgrate in 1/49, sig
The elimination of one state, Nevada, resulted in the emergence of a significant and negative correlation (r = -.48, p = .0005), whereas, when Nevada was included, the Pearson correlation was not significant.
Spearman’s correlation handles outlying values better than Pearson correlation, because Spearman’s correlation uses ranks instead of raw data. Try:
spearman medage mrgrate, stats(rho p)
Nevada is included in this Spearman’s correlation. Here’s what you get:
Thus, because of the outlying role of Nevada, Spearman’s correlation is probably better in this instance.
Spearman’s correlation should also be attempted when one or more variables in the correlation are ordinal (for example, when you are measuring the relationship between the order in which students finished a test and their score on the test).
BridgeText can help you with all of your statistical analysis needs.