Statalist


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

Re: st: re: combined Correlationmatrix Pearson and Spearman + LaTeX output


From   René Geppert <geppert.rene@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: re: combined Correlationmatrix Pearson and Spearman + LaTeX output
Date   Wed, 17 Dec 2008 11:30:54 +0100

Sorry for the late answer Mr. Baum,

but could you (or someone else) give me an example of thie code using a dataset such as: .sysuse auto ?
I cannot get it working for some reason.

regards, R. Geppert

Kit Baum schrieb:
< >
René said

Is there a way to do pairwise Pearson AND Spearman Correlations in a
single matrix, such as Pearson in the lower left and Spearman in the
upper right traingle of the matrix?
Provided, that is even possible. Is there a nice way to ouput such a
correlation matrix to LaTeX?


The following requires -outtable- from SSC (ssc install outtable)

-------------------
capt prog drop corrmat
*! corrmat CFB 2008dec09
prog corrmat
version 10.1
syntax varlist(numeric) using/
qui spearman `varlist', pw
tempname c
mat `c' = r(Rho)
local k: word count `varlist'
forv i = 2/`k' {
    local f: word `i' of `varlist'
    forv j = 1/`=`i'-1' {
        local s: word `j' of `varlist'
        qui corr `f' `s'
        mat `c'[`i', `j'] = r(rho)
    }
}
outtable using `using', mat(`c') replace format(%9.4f)
di _n "Spearman/Pearson correlations written to `using'.tex" _n
end
--------------------

Stupidly, -pwcorr- returns nothing useful in its return list---merely the correlation of the last variable with itself, which is predictably unity. Thus regular -corr- is used here, invoked pairwise to avoid listwise deletion due to missing values.

To test,

sysuse auto
corrmat price mpg rep78 using testcorrmat
type testcorrmat.tex


Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/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/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