Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Pearson/Spearman Correlation Matrix,


From   daniel klein <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Pearson/Spearman Correlation Matrix,
Date   Sat, 11 Jan 2014 11:40:29 +0100

Red Owl already showed the basic idea. I have heard the same question
just some moths ago, did not really understand why one would want this
either, but suggested some code anyway here
(http://www.stata-forum.de/post1967.html). There is no need to shift
things to Mata and the cobination of the matrices can be done in a
loop, so the approach is a little more general.

Here is the outline of a basic program to do this.


*! version 1.0.0 09oct2013

pr corsp ,rclass
    vers 9.2

    syntax varlist(min = 2 num) [if] [in]

    marksample touse
    qui cou if (`touse')
    if !(r(N)) err 2000

    loc nvars : word count `varlist'

    tempname R rho

    qui cor `varlist'
    mat `R' = r(C)

    qui spearman `varlist'
    mat `rho' = r(Rho)

    forv c = 1/`nvars' {
        forv r = `= `c' + 1'/`nvars' {
            mat `R'[`r', `c'] = `rho'[`r', `c']
        }
    }

    matlist `R'
    ret mat R = `R'
end

Best
Daniel

-- 
Dear Statalist,
Is there any code to produce a Pearson/Spearman correlation matrix
such that Pearson correlations are above diagonal and Spearman
correlations are below diagonal ?

Thanks
Ahmed
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index