Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Joint -pwcorr- and -spearman-

From   "Nick Cox" <>
To   <>
Subject   RE: st: Joint -pwcorr- and -spearman-
Date   Wed, 23 Aug 2006 22:15:59 +0100

Your location for -spearman.ado- is dependent on where it 
was installed on your machine and indeed on your OS. In 
Stata 9 a more general way to find the code is 

. viewsource spearman.ado 

as discussed in 

SJ-6-1  pr0022  . . . . . . . . . . . Stata tip 30: May the source be with you
        Q1/06   SJ 6(1):149--150   
        tip for using viewsource to locate and view source
        code or text files

Also, this as said is Stata 8 code. In Stata 9 -spearman- will
take a more general varlist, although it doesn't leave a matrix in memory. 

Hervé indicated privately that -makematrix- from SSC was appropriate
for his problem. This shows that people should close threads publicly, 
as Rodrigo was naturally not aware of that email. 

The code below is fine so long as you accept the rule 
that correlations are calculated only for observations
non-missing across all variables specified, as I 
indicated earlier. 


Rodrigo A. Alfaro
> Typing: -type C:\Stata8\ado\updates\s\spearman.ado-
> will show you the code for spearman. It is simple and
> full of comments.
> This line "syntax varlist(min=2 max=2) [if] [in]" tells
> you that the command was created for 2 variables only.
> The following lines:
> "
>                 egen `r1' = rank(`1') if `touse'
>                 egen `r2' = rank(`2') if `touse'
>                 corr `r1' `r2'
> "
> tell you that spearman is a simple correlation of the
> "ranks" of the variables. Therefore, generate the
> variables and use the same code that you already have.
> Example:
> sysuse auto, clear
> egen price_r=rank(price)
> egen mpg_r=rank(mpg)
> matrix accum S= price_r mpg_r, nocons dev
> matrix S=corr(S)
> matrix list S

*   For searches and help try:

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