This small program extends the
egen command in Stata. It calculates the Spearman's rank correlation coefficient between two variables using the
egen command and stores it in a new variable. This is most useful when combined with the
##To Install Place the _gscorr.ado file in your user ado directory (e.g, ~/Library/Application Support/Stata/plus/ado/_).
To generate a new variable called
varname that stores the Spearman's Rank correlation coefficient between two variables use:
egen newvar = scorr(existingvar1 existingvar2)
You can optionally—and perhaps most usefully—combine this command with the
by A: B = scorr(existingvar1 existingvar2) bysort A: B = scorr(existingvar1 existingvar2)
Last modified: July 2015.