Statalist


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

Re: st: Question about -drawnorm- for two normally distributed variables


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Question about -drawnorm- for two normally distributed variables
Date   Tue, 18 Mar 2008 12:40:55 -0400

Sampling variation is normal; if you want to match .7 exactly use -corr2data-

Your code doesn't match your stated desiderata:
* variable 1 = 125+-50 mg/dl
* variable 2 = 120+-25 mg/dl
* covariance = 0.7
 clear
 matrix C = (50, 0.7\ 0.7, 25)
 matrix m = (125,120)
 drawnorm cholesterol1 cholesterol2, n(1000) means(m) cov(C)
 su ch*
 corr ch*, cov


On Tue, Mar 18, 2008 at 12:23 PM,  <tiago.pereira@incor.usp.br> wrote:
> Dear all,
>
> I just want to generate two means which are modelled as being bivariate
> normally distributed. However, I am not 100% sure regarding doing that in
> Stata.
>
>
> I have to simulate two variables (mean+-standard deviation, respectively:
>
> variable 1 = 125+-50 mg/dl
> variable 2 = 120+-25 mg/dl
>
> covariance = 0.7
>
> In this respect, I am using the following code:
>
> clear
> matrix C = (25, 0.7\ 0.7, 50)
> matrix m = (125,120)
> drawnorm cholesterol1 cholesterol2, n(100) means (m) cov(C)
>
> My question is: is that correct? when I type
>
> corr cholesterol1 cholesterol2, covar
>
> the estimated covariance (for 10^6 simulated values) is far away from the
> inputed 0.7 value.
>
> For instance:
>
>             | choles~1 choles~2
> -------------+------------------
> cholesterol1 |  24.9746
> cholesterol2 |  .655911  49.9338
>
> (for 1000000 simulated values)
>
> Is that normal or am I doing something wrong?
>
> Thanks again for your time.
>
> Tiago
*
*   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