turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- How do I create a random effects data set

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-25-2018 11:33 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-26-2018 01:36 AM

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;
```

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ChrisNZ

04-26-2018 05:26 PM

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?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-26-2018 05:42 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ChrisNZ

04-26-2018 05:52 PM

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;
```

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ChrisNZ

04-28-2018 09:40 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-26-2018 03:31 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

04-26-2018 05:24 PM

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?