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   Sun, 12 Jan 2014 21:08:08 +0100

Here is an "upgraded" version of -corsp- reporting p-values. The syntax is

corsp <varlist> [if] [in] [ , pvalues ]

*! version 1.1.0 12jan2014 Daniel Klein

pr corsp ,rclass
vers 9.2
syntax varlist(min = 2 num) [if] [in] ///
[, PValues FORmat(str) ]
if ("`format'" != "") conf numeric for `format'
else loc format %7.4f
marksample touse
qui cou if (`touse')
if !(r(N)) err 2000
loc n = r(N) - 2
loc nvars : word count `varlist'
tempname R rho P
qui cor `varlist' if (`touse')
mat `R' = r(C)
qui spearman `varlist' if (`touse') ,stats(rho p)
mat `rho' = r(Rho)
mat `P' = r(P)
forv i = 1/`nvars' {
forv j = `= `i' + 1'/`nvars' {
mat `R'[`i', `j'] = `rho'[`i', `j']
mat `P'[`j', `i'] =  2 * ttail(`n', ///
abs(`R'[`j', `i'])*(sqrt(`n')/sqrt(1 - `R'[`j', `i']^2)))
}
}
di as txt _n "Pearson/Spearman correlation matrix" _n
if ("`pvalues'" == "") matlist `R' ,for(`format')
else {
tempname X
loc i = 0
forv j = 1(`nvars')`= `nvars' * 3' {
loc ++i
if (`j' <= 1) mat `X' = `R'[`i', 1...]
else mat `X' = `X'\ `R'[`i', 1...]
mat `X' = `X'\ `P'[`i', 1...]
mat `X' = `X'\ J(1, `nvars', .z)
loc rown `rown' `: word `i' of `varlist'' p `= char(160)'
}
mat rown `X' = `rown'
matlist `X' ,nodotz for(`format')
ret mat RP = `X'
}
ret mat P = `P'
ret mat R = `R'
end


As far as I can see from a quick glance, the program you found does
the same thing. Would have been quite a good idea to search the web a
little more extensive before asking for such a thing in the first
place (as is suggested in the FAQs).

Best
Daniel

-- 
Thanks Red Owl
But even if I use Daniel - corsp- program, I can't get the p values in
the same time with the table, and the matrix get mixed when I import
it to spreadsheet or word.
*
*   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