How do I create a random effects data set

Reply
New Contributor bdp
New Contributor
Posts: 4

How do I create a random effects data set

Hello,

 

I am trying to generate a data set for a two factor random-effects model. The closest I have been able to get is:


data part1;
do i=1 to 3;
do j=1 to 9;
do k=1 to 2;
a=rannor(1);
b=rannor(1);
c=rannor(1);
e=rannor(1);
x=a+b+c+e;
output;

end;

end;
end;
run;

 

However, this doesn't work because, for example, a will equal something different every time that i=1. I believe that I need to have the same random a for every i, b for every j, and c for every k. How do I do this?

 

Thank you everyone



PROC Star
Posts: 2,363

Re: How do I create a random effects data set

Something like this?


data part1;
 array A [*] A1-A3;
 array B [*] B1-B9;
 array C [*] C1-C2;
 do I=1 to dim(A);
   A[I]=rannor(1);
 end;
 do I=1 to dim(B);
   B[I]=rannor(1);
 end;
 do I=1 to dim(C);
   C[I]=rannor(1);
 end;
 do I=1 to dim(A);
  do J=1 to dim(B);
   do K=1 to dim(C);
    E=rannor(1);
    X=A[I]+B[J]+C[K]+E;
    output;
   end;
  end;
 end;
run;

 

 

New Contributor bdp
New Contributor
Posts: 4

Re: How do I create a random effects data set

This seems to be almost exactly what I was looking for. I had meant to specify that c is actually the a*b interaction term though-there is no actual term c. So this would lead me to believe that I would need to do c=1 to 27 to get every combination of a*b. But when I do that I get 729 entries. Do you have any suggestions on how to accomplish this?

PROC Star
Posts: 2,363

Re: How do I create a random effects data set

Then this: 

 

data part1;
 array B [*] B1-B9;
 do I=1 to dim(B);
   B[I]=rannor(1);
 end;
 do I=1 to dim(A);
  A=rannor(1); 
do J=1 to dim(B); C=rannor(1); E=rannor(1); X=A+B[J]+C+E; output; end; end; run;

C is unique and constant for each A and B combination, but that's probably not what you meant as there is now no logical difference between C and E.

PROC Star
Posts: 2,363

Re: How do I create a random effects data set

Or this, but the comment about C and E being equivalent still stands

I hope you can modify one of these to do what you want (assuming you know what you want).

 

data part1;
 array A [*] A1-A3;
 array B [*] B1-B9;
 array C [3,9,2] ;
 do I=1 to dim(A);
   A[I]=rannor(1);
 end;
 do I=1 to dim(B);
   B[I]=rannor(1);
 end;
 do I=1 to dim(A);
  do J=1 to dim(B);
   do K=1 to 2;
    C[I,J,K]=rannor(1);
    E=rannor(1);
    X=A[I]+B[J]+C[I,J,K]+E;
    output;
   end;
  end;
 end;
run;

 

New Contributor bdp
New Contributor
Posts: 4

Re: How do I create a random effects data set

I see what you are saying about c and e being equivalent. Thanks for the help!

SAS Super FREQ
Posts: 4,241

Re: How do I create a random effects data set

Which variables are fixed effects and which are random effects?

 

The general rule is that the random effects change for each level of district/school/classroom/student. 

 

 

New Contributor bdp
New Contributor
Posts: 4

Re: How do I create a random effects data set

A and b are both random, and c is actually the interaction term. This is actually more of a theoretical exercise. It would make sense though that for each level of a, the random effect will be the same for all y's corresponding to that level of a?

Ask a Question
Discussion stats
  • 7 replies
  • 165 views
  • 0 likes
  • 3 in conversation