- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have generated dummy variables for every year as below
Data work;
set work;
array yrdummy(*) d_&startyr - d_&endyr;
do i=1 to dim(yrdummy);
if fyear = i+&startyr then yrdummy{i} = 1;
else yrdummy{i} = 0;
end;
drop i;
run;
Now I want to interact every d_'year' with a variable. For example, I have a dummy called 'd_group'. I want to interact d_group with d_1988 through d_2018 so that I am left with variables called d_group*d_1988 through d_group*d_2018. Is there a loop to make this happen?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Modeling procedures in SAS (such as PROC GLM and many others) create the interactions for you. So all you have to do is specify the desired model (with main effects and interactions) and you don't have to create dummy variables.
This code fits a model with all two-way interactions of X1 X2 X3 X4 X5, no dummy variables needed
proc glm data=have;
class x1-x5;
model y=x1|x2|x3|x4|x5@2;
run;
quit;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes there can be a loop to do this, but why do you need these dummy variables? Many SAS procedures create dummy variables internally, so you don't have to create them yourself.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I want to compare two coefficients of the same model with two different sample. To do so, I need to interact all variables in the model with the dummy variable that divides total observations into the two different samples.
I want to display tables that have the coefficients on all variables with one sample and the same with the other sample, and the third column would show the difference between the two samples. Because the fixed effects are going to change the coefficients if I run the two samples separately, I need to have all variables interacted with the indicator variable and include in the model.
Can you tell me how to create the loop, please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Modeling procedures in SAS (such as PROC GLM and many others) create the interactions for you. So all you have to do is specify the desired model (with main effects and interactions) and you don't have to create dummy variables.
This code fits a model with all two-way interactions of X1 X2 X3 X4 X5, no dummy variables needed
proc glm data=have;
class x1-x5;
model y=x1|x2|x3|x4|x5@2;
run;
quit;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You might be trying to do what is described in this note.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content