Opens in a new tab

Wilcoxon Signed-Rank Test in Stata
Wide Data, Zero Differences and Symmetry

For the Wilcoxon signed-rank test in Stata, signrank takes two variables in wide format and prints a table of positive, negative and zero differences. Reading its result as a shift in the median rests on the differences being roughly symmetric.

What You'll Need
Paired scores in two columns
A before-after or matched design
Differences that can be plotted

IN SHORT

How signrank Ranks the Differences Between Two Columns

The Wilcoxon signed-rank test compares two related measurements, such as scores on the same participants at two times, by ranking the absolute differences and summing the ranks of the positive and the negative ones. To run a Wilcoxon signed-rank test in Stata, type signrank followed by the two variables joined by an equals sign, with one row per participant. Stata prints the positive, negative and zero differences with their rank sums, then a z statistic and a p-value, and, in releases that offer it, the exact option adds an exact p-value. 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
Reshape to One Row per Pair
2
Compute and Plot the Differences
3
Run signrank on the Pair
4
Read the Counts of Differences
5
Check the Exact p-Value for Few Pairs
6
Compare With signtest

ANALYSIS SUPPORT

Analysis Support for This Method

A paired design also allows a comparison of means with an interval when the differences are roughly symmetric and free of extreme values. The rank test fits an ordinal scale or heavy-tailed differences.

Wilcoxon Signed-Rank Test

Paired scores compared through the ranks of their differences, with the symmetry judgment, an effect size suited to ranks and the sentence that reports them.

Explore Wilcoxon Signed-Rank Test
Paired Samples t-Test

Mean change within the same participants with its interval and a standardized effect, for differences that are roughly symmetric on an interval scale.

Explore Paired Samples t-Test

BEFORE YOU RUN IT

What signrank Needs in Rows and Differences

signrank pairs values only within a row, so a file in the wrong shape or a skewed set of differences alters the test before any number is printed.

Wide Layout, One Row per Pair The two measurements sit side by side in separate variables on the same row. Long data, with one score per row and a time variable, needs reshape wide first, or signrank cannot pair the values.

Pairs That Are Truly Related The design must link each value in one variable to one value in the other: the same person twice, or a matched partner. Two unrelated groups of equal size are not paired by lining them up.

A Symmetric Spread of Differences The test treats the differences as symmetric around their center. They are plotted, and a plan for clear skew is settled beforehand, since the claim in the text depends on it.

A Plan for Zeros and Ties Pairs with no change give zero differences, and rounded scores give ties among the absolute differences. Both are counted and reported, as they reduce how much the ranks tell.

IN STATA

How to Run a Wilcoxon Signed-Rank Test in Stata

signrank belongs to official Stata and reads two variables joined by an equals sign, so neither an add-on nor a stored difference variable is required.

1

Reshape to One Row per Pair

Put the two measurements in separate variables on one row per participant, using reshape wide when the data are long.

Check: After reshaping, count the rows that hold both variables. signrank uses only complete pairs, so a participant missing one occasion drops out of the test.

2

Compute and Plot the Differences

Create the difference variable and draw a histogram or box plot to judge its symmetry and its extreme values.

Watch: A long tail on one side means the differences are not symmetric. The result then supports only a statement that the two measurements tend to differ, and the text is adjusted to say so.

3

Run signrank on the Pair

Type signrank with var1 = var2 and read the direction from the sign column: positive means the first variable is larger.

Tip: Put the later or experimental measurement first, so positive counts mean an increase. Whichever order is chosen, state it in the sentence, as reversing it swaps the positive and negative rows.

4

Read the Counts of Differences

Read the positive, negative and zero rows, with their rank sums, before the z statistic and the p-value.

Check: The three counts add up to the number of complete pairs. A large zero row means many participants did not change, which is informative in itself and is reported, not set aside.

5

Check the Exact p-Value for Few Pairs

Rerun with the exact option, where your release offers it, when the number of pairs is small, and compare the result with the approximate p-value.

Tip: The two values usually agree when pairs are many. When they disagree in a small sample the exact value is preferred, and the text names which p-value it quotes.

6

Compare With signtest

Run signtest as a cross-check when symmetry is doubtful, since it uses only the signs of the differences.

Tip: signtest tests that the median difference is zero and assumes no symmetry, at the cost of ignoring how large the differences are. Report it as a labeled sensitivity check.

Stata Commands
generate diff = after - before
histogram diff
signrank after = before
signrank after = before, exact
signtest after = before

READING THE OUTPUT

Reading the Positive, Negative and Zero Rows

The table of signs comes before any statistic, and it carries the direction, the zeros and the rank sums that the later lines build on.

Output element What it tells you What to check
Header: Wilcoxon signed-rank test (wording varies by release) The test that ran That the manuscript names the test once and consistently
positive row (sign, obs, sum ranks, expected) Pairs where the first variable is larger, with their rank sum That the direction is named from the typed order
negative row Pairs where the first variable is smaller, with their rank sum That obs here and in the positive row sum to the changers
zero row Pairs with no difference That their number is reported with the pairs analyzed
all row Total pairs, with the total rank sum and its expected value That the total matches the complete pairs in the file
unadjusted variance, adjustment for ties, adjustment for zeros, adjusted variance Variance of the rank sum with its corrections That correction lines appear when ties or zeros exist
Null line (Ho: or H0: by release), first variable = second variable, with z The null of equal distributions and the standardized statistic That the sign of z agrees with the direction in the text
p-value line after z, and Exact prob when printed (wording varies by release) Approximate and, with exact, exact two-sided p-values That the quoted value is the one named

REPORTING

Reporting a Paired Rank Test From signrank

The direction, the zeros and the symmetry judgment are what a reader checks first, since the statistic alone cannot supply them.

Report the test as the Wilcoxon signed-rank test run with signrank, giving the number of pairs, the counts of positive, negative and zero differences, z = ___ and p = ___, and state whether the approximate or the exact p-value is quoted. Describe the change with the median of the differences and its interquartile range, labeled as descriptive, and add an effect size for ranks, such as the matched-pairs rank-biserial correlation = ___, computed from the rank sums and named. State the direction in words using the order in which the variables were typed. Report how many pairs were lost to missing values and how the differences were judged for symmetry. Avoid wording that implies a difference in medians when the differences were skewed.

Pairs CountedZero DifferencesDirection StatedSymmetry JudgedExact or Approx. p

COMMON MISTAKES

Misreadings of the signrank Table

The output is short, which makes it easy to quote one line and miss the others that change its meaning.

Zero Differences Dropped Silently Participants with no change are not noise. Their number is in the zero row, and a report giving only the n of changers misstates how many pairs were studied.

Direction Reversed Typing the variables in the other order swaps the positive and negative rows. A sentence saying scores rose, built from the wrong row, reverses the finding.

Median Change Claimed Without Symmetry The test supports a statement about the median difference only if the differences are symmetric. A skewed plot calls for narrower wording or the sign test as a check.

Two Tests, the Smaller p Reported Running signrank and signtest and quoting whichever p-value is lower inflates the false-positive rate. The primary test is chosen from the symmetry judgment before either is run, and the other is reported as secondary.

r From z With an Unnamed n An effect size computed as z divided by the square root of n changes with whether zero differences are counted in n. The formula and the n used are stated beside the value.

Effect Size Missing A z and a p-value do not show how large the change is. A rank-based effect size, with the median change and its quartiles, is reported beside them, and the pairs are counted.

Positive row larger, but unsure what it says about change? Independent Statistical Review lines up your paired design, the signrank output and the change you report.

Request an Assessment

What's Next

Three or more related measurements on the same people lead to the Friedman Test.
A binary outcome measured twice on the same participants is covered by McNemar's Test.
Two independent groups compared through ranks are covered under Mann-Whitney U Test.

FREQUENTLY ASKED QUESTIONS

Questions About Direction, Zeros and Symmetry

A signrank result can be right in every digit and still be described backwards, which is why direction is answered before zeros and symmetry.

The first variable in var1 = var2: a pair counts as positive when the first variable is larger than the second. Typing signrank after = before therefore reads positive as an increase. Reverse the order and the positive and negative rows swap, while z changes sign and the two-sided p-value stays the same.

Zero differences get their own row in the table, and the variance carries separate adjustments for ties and for zeros. Programs differ in how they treat pairs with no change, so the count of zeros is reported and the program named. Rounded scores create ties among the absolute differences, which lowers the information the ranks carry.

The test reads as a statement about the median difference only if the distribution of differences is symmetric around its center. With skewed differences, a significant result shows that the two measurements tend to differ, not that the median moved. A histogram of the differences is checked, and signtest serves as a check with no symmetry assumption.

An in-house PhD-level statistician at OnlineSPSS looks at the difference plot, runs the signed-rank and sign tests on your file and checks the direction and wording in your manuscript text, as part of Results Reporting & Interpretation. The decision about what the change means 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

Which Way Does Your
Positive Row Point?

Swap the two variable names and every sign in the table flips, so the typed order is settled before any sentence about change is checked.

No Commitment Required

Strictly Confidential

Fixed Project Fee

In-House PhD-Level Statisticians

Same-Day Response

Serving Researchers Since 2014