Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Spearman correlations in Stata 8


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Spearman correlations in Stata 8
Date   Wed, 9 Nov 2005 21:35:18 -0000

There are many ways to do this in Stata 8. 

One is to generate ranks for all your 
variables, and then run -correlate- on 
the ranks. 

foreach v of var frog toad newt gingrich { 
	egen rank_`v' = rank(`v') 
}
corr rank_* 

That, however, requires some care if there
are missings in some or all of the variables. 
Safer is this: 

egen nmiss = rmiss(frog toad newt gingrich) 
foreach v of var frog toad newt gingrich { 
	egen rank_`v' = rank(`v') if nmiss == 0 
}
corr rank_* 

Another is to create a matrix full of 
missings, and then populate it with 
individual correlations. There are
various canned ways of doing that. 
One is to use -makematrix- from
SSC. Another is to use -cpspear-
from SSC. 

Another method is to use -pwcorrs- 
from the STB. 

Note that typing 

. findit spearman 

in Stata would have pointed you to -cpspear-
and -pwcorrs-. This is part of the standard
advice for finding stuff in the Statalist FAQ. 

Nick 
n.j.cox@durham.ac.uk 

Vasilis.Sarafidis
 
> I need to calculate Spearman correlation coefficients for a 
> large number of 
> variables and get them in a single matrix . In Stata 9 this 
> is implemented 
> easily, typing the command spearman varlist. In Stata 8 the command 
> spearman handles two variables only, if I am not wrong. Is 
> there any way to 
> do this in Stata 8?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index