BookmarkSubscribeRSS Feed
katiexyz
Calcite | Level 5


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

2 REPLIES 2
ballardw
Super User

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

Ksharp
Super User

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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