# st: RE: is a "rectangular" correlation matrix possible?

 From "Nick Cox" To Subject st: RE: is a "rectangular" correlation matrix possible? Date Mon, 15 Nov 2004 18:19:37 -0000

```Yes. As a point of terminology, square matrices
are all rectangular too; your request includes
oblong matrices in which the number of variables
differs as between rows and columns. A good Stata
friend tells me that no American he knows has been
taught the word "oblong".

Enough fooling.

You can do this in various ways. Two
canned methods are to use -makematrix- from SSC
or the more specific -cpcorr- from SSC.

Doing it directly is instructive:

(1) set up your matrix and fill with nonsense:

mat r = J(50,3,0)

(2) cycle over your two varlists:

local i = 0
qui foreach x of var var1-var50 {
local ++i
local j = 0
foreach y of var dv1-dv3 {
local ++j
corr `x' `y'
mat r[`i',`j'] = r(rho)
}
}

unab x: var1-var50
unab y: dv1-dv3
matrix rownames r = `x'
matrix colnames r = `y'

Nick
n.j.cox@durham.ac.uk

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of
> Garrard, Wendy
> M.
> Sent: 15 November 2004 17:56
> To: statalist@hsphsun2.harvard.edu
> Subject: st: is a "rectangular" correlation matrix possible?
>
>
> Hello,
> Is it possible to produce a "rectangular correlation matrix" in Stata?
> I need a fairly long table of correlations, but do not need
> the results
> of the default "square" correlation matrix (i.e., corr for every
> variable with all other variables).
>
> Specifically, I need to produce a long, rectangular table showing
> correlations for 2 or 3 dependent variables (e.g., 3 columns)
> correlated
> with a long list (e.g., 50 rows) of potential covariates.
>
> 	DV1	DV2	DV3
> VAR1	r1,1	r1,2	r1,3
> VAR2	r2,1	r2,2	r2,3
> ..
> VAR50	r50,1 r50,2 r50,3
>
> I am a fairly new Stata user, so may be overlooking a simple solution.
> But, I have searched the ref manuals and Statlist archives to
> no avail.
> The rectangular correlation matrix is possible in SPSS [e.g.,
> CORRELATE
> DV1 DV2 DV3 WITH IV1 IV2 IV3 IV4 IV5] so I assume it not an unusual
> command.
>
> Thanks very much,
> wg
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Wendy M. Garrard
> Vanderbilt University
> Nashville, TN 37212
>
> *
> *   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/
>

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