Statalist The Stata Listserver


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

Re: st: computing covariance


From   Joseph Coveney <jcoveney@bigplanet.com>
To   Statalist <statalist@hsphsun2.harvard.edu>
Subject   Re: st: computing covariance
Date   Sat, 03 Jun 2006 21:55:10 +0900

Rida Zaidi wrote:

This may be a v. basic question - but how does one compute and store
covariances in stata ?

For the standard deviations I only do egen x_sd=sd(varx)
How do I obtain the covariance between two of my variables ?

--------------------------------------------------------------------------------

Stata's command -correlate- will compute covariance.  You can store it (in
the same sense as you store something with -egen-) by generating a variable
to contain the returned scalar.  This is illustrated below, along with
something basic that I learned on the List today.  Does R's output report
that the variable has been transformed?

Joseph Coveney

sysuse auto
correlate headroom gear_ratio, covariance
generate float xy_cov = r(cov_12)
expr: correlate sqrt(headroom) log10(gear_ratio)


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index