BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
buckeyebmr
Calcite | Level 5

I am trying to solve this issue and I am very new to sas.  Can someone please help me?

 

Simulate 200 observations from the following linear model: Y = alpha + beta1 * X1 + beta2 * X2 + noise

where

• alpha=1, beta1=2, beta2=-1.5

• X1 ~ N(1, 4), X2 ~ N(3,1), noise ~ N(0,1)

 

I have this so far but do not think its right.

 

DATA ONE;
alpha = 1;
beta1 = 2;
beta2 = -1.5;
RUN;

DATA CALC;
SET ONE;
DO i = 1 to 200;
Y=alpha+beta1*X1+beta2*X2+Noise;
X1=Rannor(1);
X2=rannor(3);
Noise=ranuni(0);
OUTPUT;
END;

RUN;

PROC PRINT DATA=CALC;
RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
It is X~N(mu,sigma^2) ,right ?







DATA CALC;
alpha = 1;
beta1 = 2;
beta2 = -1.5;
call streaminit(1234);


DO i = 1 to 200;
X1=rand('normal',1,2);
X2=rand('normal',3,1);
Noise=rand('normal');
Y=alpha+beta1*X1+beta2*X2+Noise;

OUTPUT;
END;
RUN;

PROC PRINT DATA=CALC;
RUN;

View solution in original post

2 REPLIES 2
Reeza
Super User

Yeah, I don't think so either. Hopefully this helps provide you with some more direction:

 

X1 ~ N(1, 4) -> X is Normally distributed with a mean of 1 and standard deviation of 4. 

 

RANNOR (Seed)

The RANNOR function returns a variate that is generated from a normal distribution with mean 0 and variance 1. The Box-Muller transformation of RANUNI uniform variates is used.

 

Reading further into the documentation:

 

A normal variate X with mean MU and variance S2 can be generated with this code:
x=MU+sqrt(S2)*rannor(seed);

 

Your order is also incorrect. You need to create the random variables X1/X2/Noise before you apply the formula.

Ksharp
Super User
It is X~N(mu,sigma^2) ,right ?







DATA CALC;
alpha = 1;
beta1 = 2;
beta2 = -1.5;
call streaminit(1234);


DO i = 1 to 200;
X1=rand('normal',1,2);
X2=rand('normal',3,1);
Noise=rand('normal');
Y=alpha+beta1*X1+beta2*X2+Noise;

OUTPUT;
END;
RUN;

PROC PRINT DATA=CALC;
RUN;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1129 views
  • 2 likes
  • 3 in conversation