BookmarkSubscribeRSS Feed
khalillx
Fluorite | Level 6

So I'm doing a simulation exercise where I had to make the error time be correlated with the independent variable X and see what happens to the empirical distribution. So I changed my code from this :

data samples;

do samp = 1 to 1000;

do t = 1 to 100;

      u = rannor(1996)*5;

      x = 100 + 3*rannor(6991);

      y = 10 + 0.5*x + u;

    output;

  end;

end;

run;

 

to this:

 

data samples;

do samp = 1 to 1000;

do t = 1 to 100;

      u = rannor(1996)*5;

      x = 100 + 3*rannor(6991) + 0.3*u;

      y = 10 + 0.5*x + u;

    output;

  end;

end;

run;

 

Then I'm supposed to figure out of the model satisfies the assumption that E(U|X) = 0. To do this I have to run a single regression using only the first sample by putting WHERE SAMP=1 after the proc reg statement. Then I have to pull out the residuals and the predicted values of Y. Then I need t do a proc contents on the staset and have X,Y, Yhat, u and uhat in it. Then I need to calculate the correlation between X and uhat. I'm so confused how to go about this. Here is all my code if you guys can please help, thanks.

 

data samples;
do samp = 1 to 1000;
do t = 1 to 100;
u = rannor(1996)*5;
x = 100 + 3*rannor(6991) + 0.3*u;
y = 10 + 0.5*x + u;
output;
end;
end;
run;

proc corr;
where samp=1;
var x y u;
run;

proc reg data=samples outest=bvalues outseb noprint;
by samp;
model y = x;
run;


data one two;
set bvalues;
if _type_ ='PARMS' then output one;
else if _type_ ='SEB' then output two;
run;

proc sql;
create table mystuff
as select one.intercept as b0hat, one.x as b1hat,
two.intercept as seb0, two.x as seb1
from one, two
where one.samp = two.samp;
quit;

proc means data=mystuff;
var b0hat b1hat;
run;

proc univariate data=mystuff noprint;
var b0hat b1hat;
histogram / normal;
run;

proc reg data=samples WHERE SAMP=1 noprint;
by samp;
model y = x;
run;

 

3 REPLIES 3
Reeza
Super User
You can probably help us and yourself, i you indicate in your code (via comments) what you think each step is doing. You seem to understand what you want to do, but there's no link to your code as to which step is doing what.
khalillx
Fluorite | Level 6

I copied and pasted all my code into the question.

Reeza
Super User
Your code has no comments. When you're coding commenting really does help you ensure your code is correct and it's a good habit to get into.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 741 views
  • 0 likes
  • 2 in conversation