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   "Abdalla, Ahmed" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: Pearson/Spearman Correlation Matrix
Date   Sun, 12 Jan 2014 16:08:04 +0000

Thanks Red and Daniel for the code, 
Red, I tried your code and it worked perfectly. However, when I try to add the option to report the p values , it gives me an error! I had to change corr to pwcorr to be able to use the print(0.05) or star(0.05) options, and I added the print option to Spearman, but it gives an error and doesn't report the matrix. When I added the option to pwcorr only, it did not give me an error however the output matrix at the end (for both spearman and pearson) doesn't give me the significance levels!
1) Do corr and pwcorr do the same job here (pearson correlations) ?
2) How can I report P values here?
3-Also, if I have 7 variables, I would add:
mata: mataRS[1,2] = mataS[2,1]
mata: mataRS[1,3] = mataS[3,1]
mata: mataRS[1,4] = mataS[4,1]
mata: mataRS[1,5] = mataS[5,1]
mata: mataRS[1,6] =mataS[6,1]
mata: mataRS[1,7] =mataS[7,1]

mata: mataRS[2,3] = mataS[3,2]
mata: mataRS[2,4] = mataS[4,2]
mata: mataRS[2,5] = mataS[5,2]
mata: mataRS[2,6] = mataS[6,2]
mata: mataRS[2,7] = mataS[7,2]

mata: mataRS[3,4] = mataS[4,3]
mata: mataRS[3,5] = mataS[5,3]
mata: mataRS[3,6] = mataS[6,3]
mata: mataRS[3,7] = mataS[7,3]

mata: mataRS[4,5] = mataS[5,4]
mata: mataRS[4,6] = mataS[6,4]
mata: mataRS[4,7] = mataS[7,4]

mata: mataRS[5,6] = mataS[6,5]
mata: mataRS[5,7] = mataS[7,5]

Is it right to add these commands? or do I mix things together?


Daniel, I was not sure how to edit your code to be used with my variables ! Let's say I have X1 X2 X3 X4 X5 X6 X7


Thanks in advance

________________________________________
From: [email protected] <[email protected]> on behalf of Red Owl <[email protected]>
Sent: 11 January 2014 05:09
To: [email protected]
Subject: RE: st: Pearson/Spearman Correlation Matrix

Ahmed,

I'm not sure why you would want to do this, but the following
provides some example code that does what you asked.  This builds
a correlation matrix with Pearson r's below the diagonal and
Spearman rho's above the diagonal.

***** BEGIN STATA CODE *****
sysuse auto, clear
local varlist mpg price weight length
* Get Pearson Matrix in Stata
corr `varlist'
matrix R = r(C)
* Get row and col names
local rnames : rownames R
local cnames : colnames R
* Get Spearman Matrix in Stata
spearman `varlist', matrix
matrix S = r(Rho)
* Convert Stata Pearson Matrix to Mata Matrix
mata: mataR = st_matrix("R")
* Convert Stata Spearman Matrix to Mata Matrix
mata: mataS = st_matrix("S")
* Clone Mata Pearson Matrix for Combined mataRS Mata Matrix
* Pearson and Spearman in Mata
mata: mataRS = mataR
* Replace Pearson r with Spearman rho
* in Top Half of Combined mataRS Mata Matrix
mata: mataRS[1,2] = mataS[2,1]
mata: mataRS[1,3] = mataS[3,1]
mata: mataRS[1,4] = mataS[4,1]
mata: mataRS[2,3] = mataS[3,2]
mata: mataRS[2,4] = mataS[4,2]
mata: mataRS[3,4] = mataS[4,3]
* Display Pearson, Spearman, and Combined Matrices in Mata
mata: mataR
mata: mataS
mata: mataRS
* Convert Combined mataRS Mata Matrix to Stata Matrix RS
mata: st_matrix("RS",mataRS)
matrix rownames RS = `rnames'
matrix colnames RS = `cnames'
* Display Combined Stata Matrix RS in Stata
matlist RS, format(%8.3f)
***** END STATA CODE *****

Red Owl
[email protected]
*
*   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/

*
*   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