Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How to estimate var-cov matrix from data

From   Richard Williams <>
Subject   Re: st: How to estimate var-cov matrix from data
Date   Sun, 15 Feb 2004 23:20:17 -0500

At 07:57 PM 2/15/2004 -0800, wei liu wrote:

I have a very easy question to ask. I have two random
variables with 1000 observations each. How can I
generate the variance-covariance matrix for them? I
wanna save this matrix as a matrix variable for
further use. Is there a simple way to do so? Can I
further generalize this method for higher dimension?

Thanks a lot!

Try -help mataccum-

The commands would be something like

. mat accum cov = x y, noconstant deviations

. mat cov = cov/(_N-1)

. mat list cov

symmetric cov[2,2]
x y
x 9.0365155
y 3.0502898 3.982194

To confirm that you did it right,

. corr x y, cov

| x y
x | 9.03652
y | 3.05029 3.98219

You can do it with more than 2 variables; and you can make things more complicated by using if, in and weights parameters.

Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: Richard.A.Williams.5@ND.Edu
WWW (personal):
WWW (department):

* For searches and help try:

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