Opens in a new tab

Spearman's Rank Correlation in Stata
Options, Ties and Missing-Data Behavior

Spearman's rank correlation in Stata is a single spearman call, and its stats() option adds the sample size and p-value to rho. Missing values are dropped casewise unless pw is added, and no interval for rho is printed, so the report rests on several choices.

What You'll Need
Stata open on the dataset
Two or more ordered variables
Ordinal or skewed measurements

IN SHORT

What spearman Computes and Which Defaults Apply

Spearman’s rank correlation measures the strength and direction of a monotonic association by correlating the ranks of two variables, which suits ordinal scales and relationships that rise or fall without being straight. To run Spearman’s rank correlation in Stata, type spearman followed by the variables, adding stats(rho obs p) to show the coefficient, the sample size and the p-value together. Tied values receive average ranks, observations with a missing value on any listed variable are dropped for every pair unless pw is added, and no confidence interval for rho is printed. OnlineSPSS, a specialist statistical consultancy for academic, clinical and professional research, carries out and reviews this analysis through an in-house PhD-level statistician.

In This Guide

1
Describe Each Variable
2
Plot the Pair Before Ranking
3
Run spearman With stats()
4
Compare Casewise and Pairwise
5
Adjust or Mark Many Pairs
6
Add an Interval and Save

ANALYSIS SUPPORT

Analysis Support for This Method

A rank coefficient says whether values tend to rise together. It does not give the form of the relationship, which a model of the outcome on its predictors does.

Correlation Analysis (Pearson & Spearman)

Pearson and Spearman coefficients chosen by the shape of each pair, each reported with its own sample size, an interval and a note on tied values where they matter.

Explore Correlation Analysis (Pearson & Spearman)
Likert Scale Analysis

Ordinal ratings summarized and related to other variables with methods that respect their scale, from item-level checks to the reporting of scale scores.

Explore Likert Scale Analysis

BEFORE YOU RUN IT

What spearman Needs From the Variables

Ranks discard distances and keep order, which suits some variables well and others poorly, and the sample rule changes the n behind each cell.

A Monotonic Question Spearman's rho describes whether one variable tends to rise or fall with the other, not whether the pattern is a line. A U-shaped pattern still returns a value near zero, so the scatterplot is inspected.

Ordered or Continuous Values Rank measures need values that can be ordered, such as ratings, scores or counts. A nominal code with several categories has no order to correlate, however many numbers are used for it.

Heavy Ties Noted Likert items and short scales produce many tied values. Average ranks handle them, but the coefficient then rests on few distinct values, so the number of ties in each variable is checked.

A Sample Rule Chosen Early Casewise deletion gives one sample to every pair in a matrix, while the pw option gives each pair its own. The rule is chosen before the matrix is run, since switching after seeing the coefficients is a quiet form of selection.

IN STATA

How to Run Spearman's Rank Correlation in Stata

spearman ships with official Stata and accepts a variable list, so a single call gives one coefficient or a whole matrix, and options decide what is printed beside it.

1

Describe Each Variable

Inspect the values of each variable and the number of distinct scores, noting how many ties a ranking will create.

Check: codebook shows the number of unique values and of missing values per variable. A variable with only a few distinct values yields mostly tied ranks, and the report says so.

2

Plot the Pair Before Ranking

Draw a scatterplot to see whether the association is monotonic and whether a cluster of points drives it.

Watch: Rank correlation is less sensitive to a single extreme value than Pearson’s r, but a plateau or a reversal in the plot still needs describing in words, as one number cannot show it.

3

Run spearman With stats()

Type spearman with the variable pair and stats(rho obs p), so that the coefficient, the n and the p-value appear together.

Tip: With more than two variables the default matrix shows rho alone, so stats() is what puts the n and the p-value beside each coefficient. Up to three statistics can be listed.

4

Compare Casewise and Pairwise

Run the matrix once by default and once with pw, and compare the observation counts of each pair.

Check: Casewise deletion is the default, so a row missing a single variable drops out of every pair. Pairwise deletion keeps more data and gives pairs different n, which the table then shows.

5

Adjust or Mark Many Pairs

For a large matrix, add bonferroni or sidak to adjust the displayed p-values, or star() to mark those under a cutoff.

Tip: An adjusted p-value answers a different question from an unadjusted one. Bonferroni is slightly more conservative than sidak, and the text says which values appear.

6

Add an Interval and Save

Note that no interval is printed, compute one with a method suited to rank correlations, and save the commands in a do-file.

Watch: The Fisher z interval for Pearson’s r does not transfer exactly to rho. Adjusted approximations and resampling intervals exist, and the report names the method that was used.

Stata Commands
codebook x y
twoway scatter y x
spearman x y, stats(rho obs p)
spearman x y z w, stats(rho obs p)
spearman x y z w, stats(rho obs p) pw

READING THE OUTPUT

Reading a spearman Matrix With Its Options

A cell can stack up to three statistics, and the options change which cells are shown, so the layout is read before any value is copied.

Output element What it tells you What to check
Number of obs (two variables), or obs in a matrix cell Rows that entered the coefficient That it matches the sample intended after the deletion rule
Spearman’s rho Pearson correlation of the ranks, with average ranks for ties That sign and size are read with the scatterplot
Test of Ho: x and y are independent (wording varies by release) The null of no association between the pair That the null is worded as no monotonic association
p-value line under the test of independence, or p in a matrix cell Two-sided p-value for the null That it is quoted with the n behind it
Stacked rho, obs, p under stats() One coefficient, its n and its p-value per cell That the order of the stacked rows is read correctly
Asterisk from star() Flags coefficients whose p-value falls at or below the level set That the level, and any bonferroni or sidak adjustment, appears in the table note
Blank cells under print() Coefficients with larger p-values hidden That a table is not trimmed to hide the pairs examined
No interval column Nothing printed for the precision of rho That an interval is added and its method named

REPORTING

Reporting Spearman's Rho With Its Sample and Interval

Because the defaults are casewise and intervalless, a sentence has to supply what the matrix leaves out.

Report the coefficient as rs = ___ or rho = ___ with the n it rests on, the p-value and an interval computed separately, naming the method behind the interval. State whether casewise or pairwise deletion produced the sample, and give the n for each pair when pw was used. Describe the association as monotonic and give its direction in words, at the scale of the variables, adding the scatterplot when the shape matters. Mention the degree of ties when variables have few distinct values. Declare the size of the matrix and whether p-values were adjusted. A rank coefficient is not an effect estimate, so the result is worded as association only. Give the scale and the number of distinct values of any ordinal variable, so a reader can judge how many ties the ranks contain.

Sample Rule Statedn per Pair ShownInterval Method NamedTies AcknowledgedAdjustment Declared

COMMON MISTAKES

Misstatements Around a spearman Matrix

Most arise from the defaults, which are sensible but easy to forget once a table has been formatted for the manuscript.

Casewise Default Forgotten A matrix from spearman uses only rows complete on every listed variable. Reporting its n as if each pair had used all the data it holds understates the sample available to a pair.

Coefficient Switched After a Null Pearson Moving to Spearman because Pearson's r was not significant turns the choice of coefficient into a search for a p-value. The coefficient is chosen from the scale and the plot before either is computed.

Interval Presumed Present A table listing rho with its p-value invites readers to assume an interval exists. spearman prints none, so one is obtained by an approximation or by resampling, and its method is named.

Rho Called Linear A rank coefficient describes monotonic association. Calling it a linear relationship, or drawing a straight line through the points to illustrate it, describes something the coefficient did not measure.

Heavy Ties Overlooked Short ordinal scales give many ties, and rho then rests on few distinct ranks. A variable with three distinct values cannot support a fine reading of the coefficient's size.

Many Coefficients, One Cutoff Starring every pair under .05 in a large matrix leaves the number of tests unstated. Adjusted p-values, or a stated denominator, tell the reader how many chances there were.

Ordinal scores correlated, interval still missing? Independent Statistical Review establishes, for each rho, which rows it rests on and how its interval was obtained.

Request an Assessment

What's Next

Ordered outcomes with several predictors are modeled under Ordinal Regression.
Curved relationships that rise and then fall are explored with Non-Parametric Regression.
Agreement between two raters on the same items is covered under Inter-Rater Reliability (Cohen's Kappa & ICC).

FREQUENTLY ASKED QUESTIONS

Questions About spearman Options, Ties and Intervals

Nothing in the printed matrix says which deletion rule produced it or how an interval would be built, so those two gaps lead the list.

The stats() option: stats(rho obs p) displays the coefficient, the number of observations and the p-value for each pair. Up to three statistics can be listed, and the default is rho alone for a matrix. The star(), print(), bonferroni and sidak options then control how the matrix is marked and how its p-values are adjusted.

Tied values receive average ranks, and observations with a missing value on any listed variable are dropped for every pair unless pw is added. With pw, each pair uses all rows available to it. Either way, the obs statistic shows the n behind each coefficient, and the rule used is stated in the report.

No: spearman prints the coefficient, optionally the n and a p-value, and never an interval. One can be obtained from an approximation made for rank correlations, from a resampling method or from a command contributed by users. Name the method, because an interval built as for Pearson’s r is only roughly right for rho.

An in-house PhD-level statistician at OnlineSPSS runs the correlations on your file, chooses and states the deletion rule and adds the interval, or reviews a matrix you have already produced. The stage sits under Results Reporting & Interpretation, and the meaning of the associations in your field remains yours.

Your data and project details are handled confidentially, and project information is not published. Researcher names and institutions are not used publicly without permission. An NDA is available where required and can be arranged before sensitive materials are shared. Read more about confidentiality and data security.

You share your research question, design and relevant materials, such as the dataset or the output you have, and a statistically trained Research Coordinator reviews the request and responds the same day. The analysis, deliverables, timeline and one fixed project fee are then confirmed before any work begins, so the timeline follows from the agreed scope.

Still have a question? Find more answers in our full FAQ.

View All FAQs →

NEXT STEP

Is the Sample Rule
Stated Beside the Matrix?

A rho with no stated sample rule or interval leaves a reviewer guessing which rows it describes, and an assessment can work from the variables alone if no matrix exists yet.

No Commitment Required

Strictly Confidential

Fixed Project Fee

In-House PhD-Level Statisticians

Same-Day Response

Serving Researchers Since 2014