It doesn't make your posting more attractive
if you flag that your questions are "simple"!
The simpler they are, the more likely it is
that you should be able to answer them, and the
less likely is that anyone might would want
to answer for you.
Setting that aside, your first question is
often asked, as a search of the archives
using -pwcorr- as keyword would have shown.
For example,
=============================================
Subject st: RE: Storing a correlation matrix
Date Tue, 18 Apr 2006 16:50:50 +0100
-makematrix- can do this with the -listwise- option.
-makematrix- is downloadable from SSC.
Here is a dopey example.
. sysuse auto, clear
(1978 Automobile Data)
. makematrix , from(r(rho)) listwise : corr price-rep78
price mpg rep78
price 1
mpg -.46859669 1
rep78 .00655327 .40234039 1
Making a matrix from the sample sizes shows the
underlying mess:
. makematrix , from(r(N)) listwise : corr price-rep78
price mpg rep78
price 74
mpg 74 74
rep78 69 69 69
There are, naturally, options for saving the matrix,
and so forth.
-makematrix- was discussed in the Stata Journal:
SJ-3-4 pr0011 . . . . . . . . Speaking Stata: Problems with tables, Part II
Q4/03 SJ 3(4):420--439 (no commands)
reviews three user-written commands (tabcount, makematrix,
and groups) as different approaches to tabulation problems
===========================================
I'm going to lobby the author of -makematrix- to withdraw that option,
as it probably leads to all kinds of unreliable result.
Your second question: In Mata, just use -abs()-.
In Stata, one way to do it is evidently to loop over rows and
columns and apply -abs()- to each element. A short cut
way to do that is using -matewmf- from STB-56.
. matrix foo = J(3,3,-1)
. matewmf foo foo, f(abs)
. mat li foo
symmetric foo[3,3]
c1 c2 c3
r1 1
r2 1 1
r3 1 1 1
But you should be using Mata.
Nick
n.j.cox@durham.ac.uk
Timothy.Mak@iop.kcl.ac.uk
> I searched the help for how to convert a correlation of a set
> of variables
> to a Matrix. It tells me to use the command -matrix accum-. I
> tried it but
> it drops all my observations with missing data. eg if var1 contains 1
> missing data point, I should still be able to collect the
> pwcorr for var2
> and var3 using that record, but that's ignored in the matrix
> approach. Any
> fix to that?
>
> Second question is probably easier - how do you convert all
> the elements
> of a matrix to non-negative, ie taking the absolute?
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/