[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: saving output of -correlate, c- in two submatrixes for later use

From   "Nick Cox" <>
To   <>
Subject   st: RE: saving output of -correlate, c- in two submatrixes for later use
Date   Tue, 6 Nov 2007 17:32:16 -0000

-ereturn list- shows nothing after -correlate- because -correlate- is an
r-class command. This is documented, but think of it this way: in what
way is -correlate- fitting a model? 

You can get correlation matrices in various ways. -findit correlation
matrix- points to various, including

FAQ     . . . . . . . . . . . . . . . . . . . Obtaining the correlation
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W.
        12/99   How can I obtain the correlation matrix as a Stata

corrmat from
    corrmat.  Create and save correlation or covariance matrices.  /
    by Shannon Driver, StataCorp <>. / Creates a
    matrix, covariance matrix, or both and optionally / saves them in
    return list and/or matrix dir.

cpcorr from
    'CPCORR': module for correlations for each row vs each column
variable /
    cpcorr produces a matrix of correlations for rowvarlist versus /
    colvarlist. cpspear does the same for Spearman correlations. This /
    may thus be oblong, and need not be square. Both also / allow a

Also check out -makematrix- from SSC. 

You have two choices: get the whole matrix, and extract; or get separate
submatrices. -cpcorr- and -makematrix- support the latter approach. 

The sum of squared values I would get by squaring a variable and finding
its sum, using -summarize, meanonly- and picking up r(sum). 

Here is an example: 

. gen ysq = y^2
. su ysq, meanonly 
. scalar ysum = r(sum) 


I have a panel of some dozens of variables: ns x* z*. I would like to:
(1) save some of the output of -correlate x* z*, c- in two matrixes, X
(containing only that portion of the output about the (co)variances
between the x* variables and themselves) and Z (containing only that
portion of the output about the covariances between the x* variables and
the z* variables), e.g.
   x1 x2 ... xn z1 ... zn
z1 .......useless........
zn ..of...the...output...
Why can't I find the output with -ereturn list-, such as after -mean()-?
(2) and then to find the matrix A such that Z*A=X/sq where sq is the
scalar given by the sum of the squares of the values contained in
variable ns. (I know that A is -matrix A= inv(Z)*X/sq-, but has Stata 9
any simple command to calculate sq? And can I save the value of sq in
some variable for later use in a for i=1...sq statement?)

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index