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

 From Philip Ryan <[email protected]> To [email protected] Subject Re: st: How to estimate var-cov matrix from data Date Mon, 16 Feb 2004 15:27:07 +1030

As an alternative to Richard's suggestion, Shannon Driver from StataCorp wrote a useful ado program called -corrmat- (type -findit corrmat-) which does just what you want.

Phil

At 11:20 PM 15/02/2004 -0500, you wrote:

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

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!

Wei
```
Try -help mataccum-

The commands would be something like

. mat accum cov = x y, noconstant deviations
(obs=1000)

. 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
(obs=1000)

| 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: [email protected]
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc

*
* 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/
```Philip Ryan
Associate Professor,
Department of Public Health
Associate Dean (Information Technology)
Faculty of Health Sciences
South Australia
tel 61 8 8303 3570
fax 61 8 8223 4075
CRICOS Provider Number 00123M
-----------------------------------------------------------
This email message is intended only for the addressee(s)
and contains information that may be confidential and/or
notify the sender by reply email and immediately delete
this email. Use, disclosure or reproduction of this email
by anyone other than the intended recipient(s) is strictly
prohibited. No representation is made that this email or
any attachments are free of viruses. Virus scanning is
recommended and is the responsibility of the recipient.

*
*   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/
```