## Generating bivariate lognormal data

Occasional Contributor
Posts: 18

# Generating bivariate lognormal data

Hi,

I have to generate 30 lines of data from the bivariate lognormal distribution.

I have this information

"The log10 transformed responses follow the normal distribution as follows: X~N(-0.4, 0.3**2) and Y~N(-1.4, 0.3**2). Their correlation rho=0.5"

I have been generating the data with this code so far, which I believe is incorrect.

data simulate;
keep logy1 logy2;
do i=1 to 30;
mu1=-0.4 ;mu2=-1.4;sd1=0.3;sd2=0.3;rho=0.5;
r1 = rannor(1245);
r2 = rannor(2923);
logy1=10**(mu1 + sd1*r1);
logy2= 10**(mu2 + rho*sd2*r1+sqrt(sd2**2-sd2**2*rho**2)*r2);
output;
end;

proc corr data=simulate;
var logy1 logy2;
run;

Proc corr gives me estimates that i do not expect. I suppose I expected to see the mean, sd and rho values that I wrote in the datastep: I don't know how they'd change by being logtransformed.

Please can anyone help me? I am very stuck.

Katie

XX

Super User
Posts: 13,517

## Re: Generating bivariate lognormal data

The Rand function with 'LOGNORMAL' might generate the type of number you need better than the attempted transforms.

Super User
Posts: 10,770

## Re: Generating bivariate lognormal data

Not sure if it what you need. You should run code several times to get almost 0.5 correlation rho.

```data simulate;
do i=1 to 300;
r1 = rand('NORMAL',-0.4,0.3);
r2 = rand('NORMAL',-1.4,0.3);
r3 = rand('NORMAL',-1.4,0.3);
r1=0.5*r2+sqrt(1-0.5**2)*r3;
output;
end;

proc corr data=simulate;
var r1 r2;
run;

```

Ksharp

Discussion stats
• 2 replies
• 371 views
• 0 likes
• 3 in conversation