Statalist The Stata Listserver


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

st: RE: RE: Drawing a (positive-definite) correlation matrix


From   "Feiveson, Alan H. (JSC-SK311)" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Drawing a (positive-definite) correlation matrix
Date   Mon, 15 May 2006 10:06:37 -0500

Daniel - This may be of some help - Here's a simple program to generate
a random sample covariance matrix for a specified sample size whose
population covariance is specified by the user. Even if the population
matrix is the identity and you make the sample size the same as the
dimension of the matrix, you will get a positive definite matrix with
plenty of high correlations. 

AL Feiveson

program define gencov
version 7.0
args C S N

/*
generates a sample covariance matrix S based on N observations where
true underlying covariance matrix is C
*/

local p=rowsof(`C')
tempname B
matrix `B'=cholesky(`C')
preserve
qui drop _all
qui set obs `N'
forv i=1(1)`p' {
tempvar x`i'
qui zor `x`i''
}
qui matrix accum `S'=`x'*,noconstant
qui matrix `S'=(1/(`N'-1))*`B'*`S'*`B''
restore
end




-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: Monday, May 15, 2006 9:17 AM
To: [email protected]
Subject: st: RE: Drawing a (positive-definite) correlation matrix

If all you care about is the average
correlation, then given that all the
correlations along the principal
diagonal must be 1, all the others
could be just that average multiplied
by whatever constant yields the right
answer. 

If not, you need a more precise specification. 

Nick
[email protected] 

Daniel Hoechle
 
> I would like to perform a Monte Carlo simulation with correlated, 
> normally distributed data. It seems to be tempting to use Stata's
> -drawnorm- command. However, this is not possible because I do not yet

> have a correlation matrix. Does anyone know how to generate a positive
> (semi-) definite random correlation matrix with average correlation 
> avg_corr=x in Stata?
> 
> Or are there other ways to produce multivariate normal random numbers 
> with average correlation between the subjects/variables equal to x 
> (x!=0)?

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

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