Statalist The Stata Listserver

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

Re: st: How to store correlate result using stata 9

From   Maarten buis <>
Subject   Re: st: How to store correlate result using stata 9
Date   Wed, 23 May 2007 07:34:36 +0100 (BST)

--- hai guo <> wrote:
> I want to store the correlation coefficient into a
> variable. After I run corr var1 var2 var3
> i see the correlation coefficient output table. I
> searched online and it is said the correlate result
> should be stored in matrix rho(r), but when I tried in
> stata 9. I can't find it. 

You can get a list of what is stored and how it is named after a
command by typing -return list- (and -ereturn list- after estimation
commands). That shows you that -correlate- doesn't store the
correlation matrix but only the correlation between the first two
variables. (If you want the matrix you can look at )
Typically storing a constant as a variable is a bad idea, but the
example below shows you how to do that. A better way is to use a local,
see: -help local-. Again the example below illustrates how that is

*----------- begin example ---------
sysuse auto, clear
corr price mpg weight
return list
di r(rho)
gen rho = r(rho)   /*create the variable*/
local rho = r(rho) /*create the local*/
di `rho'
*----------- end example ------------
(For more on how to use examples I sent to the Statalist, see )

Hope this helps,

Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

Inbox full of unwanted email? Get leading protection and 1GB storage with All New Yahoo! Mail.
*   For searches and help try:

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