Statalist


[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" <[email protected]>
To   <[email protected]>
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
matrix
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W.
Gould
        12/99   How can I obtain the correlation matrix as a Stata
                matrix?
                http://www.stata.com/support/faqs/stat/rho.html

corrmat from http://www.stata.com/users/sdriver
    corrmat.  Create and save correlation or covariance matrices.  /
Program
    by Shannon Driver, StataCorp <[email protected]>. / Creates a
correlation
    matrix, covariance matrix, or both and optionally / saves them in
the
    return list and/or matrix dir.

cpcorr from http://fmwww.bc.edu/RePEc/bocode/c
    '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 /
matrix
    may thus be oblong, and need not be square. Both also / allow a
single


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) 

Nick 
[email protected] 

[email protected]

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
x1 XXXXXXXXXXXX ZZZZZZZZZ  
x2 XXXXXXXXXXXX ZZZZZZZZZ
...XXXXXXXXXXXX ZZZZZZZZZ
xn XXXXXXXXXXXX ZZZZZZZZZ
z1 .......useless........
..........portion........
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:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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