Statistical Modeling
Dr. Courtney Brown
Assignment #7
For this assignment, you will be learning how to interpret interaction terms using multiple regression and a plot. As with all assignments in this course, remember that this is an assignment of scientific writing, so explain your results clearly so that everyone can understand your findings. You are to use the SAS code below to get you started. Everything is already built into the code so that all you have to do is to change the variables that you are going to use for your interaction terms. First, you need to choose two variables that you think will have an interactive effect. Create the interaction term in your data step. Then include the interaction term as well as the two original variables upon which the interaction term is based in your regression equation. Be sure to include additional control variables as you feel are needed. You need to run the code below twice. The first time you will be obtaining the parameter values for the interaction term and the other two variables upon which it is based. Then you will be putting these values into the code below so that you can have SAS plot your predictive hypersurface, and then running the code a second time to get your plot. For this assignment, you are to write up an interpretation of the influence of interaction among these variables upon your dependent variable. Base your interpretation on the 3-D plot that SAS provides.
For the dependent variable (use only one), use either feelings for President Jimmy Carter or feelings for challenger Ronald Reagan using the variables carfeel3 or reafeel3. These variables are for feeling thermometers asked of the survey respondents in September of 1980. Try to find an interesting set of independent variables that explains one of these two dependent variables.
You will be working with multiple regression using the same SAS data set as you used in a previous assignment. If needed, you should first, download the survey data set for the Reagan vs. Carter election in 1980. (Right-mouse click this link and choose "Save Target As.") This data set is called a "panel study" because there were four waves of interviews that took place throughout 1980 to capture the sense of the campaign during (1) the entry into the primary season, (2) the post-primary season, (3) the main campaign in September, and (4) after the vote in November. After you download the data set, you will need to extract it since it is "zipped." Use Windows Explorer to do this by right-mouse clicking the zipped file and choosing "Extract." Put the extracted data set on your USB drive. Now you can run the SAS code below. Cut and paste everything below this line into your SAS editor. Then run the program. You will find that you can see the variable lables in the output for Proc Means.
Here is some help in interpreting the variable values.
Feeling thermometers: 0 to 100, with 50 being neutral.
Liberal/conservative scales: 1=extreme liberal, 7=extreme conservative.
Inter1-Inter3: respondent's interest in the campaign/low to high.
P1 through P4: This refers to the panel wave, January, July, Sept. & Nov.
Expectation to vote: 5 will vote, 1 no.
Education: years of education
Income: not in thousands of dollars, but a scale, low to high.
Frequency of church attendance: low to high
R : This refers to the respondent.
Generally all of the variables go from to low to high. Thus, if you see a variable
and you do not know the coding scheme, assume that a small number means less
and a larger number means more. The other codes are in the variable labels.
Most of the variables for this data set originated as a panel study supplied by the Interuniversity Consortium for Social and Political Research (ICPSR). Emory University is a member of the ICPSR. I have added some contextual variables to the survey data set by extracting these contextual data from a separate ICPSR data set.
libname windata 'e:\';
goptions reset=global gunit=pct border cback=white
colors=(black black black black) norotate
ftext=swiss ftitle=swissb htitle=6 htext=4
hsize=5 in vsize=5 in horigin=1.5 in vorigin=3 in;
**********************************************************;
* CLASS, NOTE THAT IF YOU BEGIN A LINE WITH AN ASTERISK *
* THEN YOU CAN PUT NOTES IN YOUR PROGRAM FILES. THIS IS
* LIKE A COMMENT CARD IN SPSS. HOWEVER, REMEMBER
* TO EVENTUALLY PUT A FINAL SEMICOLON AT THE END OF YOUR COMMENTS.;
***********************************************************;
* NOTE THAT I INDENT SOME STATEMENTS. THIS
* IS JUST FOR NEATNESS.;
***********************************************************;
* COPYRIGHT (c) Courtney Brown 2005, All Rights Reserved;
* Permission granted to use this file and computer code for any nonprofit and
* educational purposes, including classroom instruction.
* No further permission required.
* Please cite source as "From www.courtneybrown.com";
***********************************************************;
DATA panel80;SET windata.panel80;
if ((vote eq 1) or (vote eq 2));
if (age le 43) then generation = 'youth';
if (age gt 43) then generation = 'older';
if (partyid le 2) then party = 'Dem.';
if ((partyid ge 3) and (partyid le 5)) then party = 'Ind.';
if (partyid ge 6) then party = 'Rep.';
gender=sex;
if ((race eq 1) or (race eq 2)); * This gets rid of the "other" category
in race;
if (race eq 1) then white=1;else white=0; * This creates the intercept dummy
variable for whites;
if (race eq 2) then black=1;else black=0; * This creates the intercept dummy
variable for African Americans;
wpartyid=white*partyid; * This is one way of creating the whites only slope
dummy variable for partyid;
bpartyid=black*partyid; * This is one way of creating the blacks only slope
dummy variable for partyid;
int1=newv3213*dempart3;
* FYI, newv3213 = LIB/CON SCALE FOR R, P3 (1 t0 7 scale);
proc format;
value VoteFmt 1 ='Reagan' 2 ='Carter' 3 ='Clark' 4 ='Anderson';
value GenderFmt 1 ='Male' 2 ='Female';
proc print;var white black wpartyid bpartyid partyid;
proc means;
proc contents;
proc reg;
model carfeel3 = dempart3 newv3213 int1 gender / stb tol;
title 'Carter Feelings';
* create a data set using the parameter values that you obtained from the regression
above;
data CoolPlot;
intercept=22.5481;
do DemFeel=0 to 100 by 5;
do Ideology=1 to 7 by 1;
Carter=intercept + (.53584*DemFeel) + (-4.99643*Ideology) + (.06614*DemFeel*Ideology);
output;
end;
end;
run;
title 'Surface Plot of Feelings for Carter';
* footnote j=r 'Footnote If You Want It';
* here is one version of the plot using the default graphics options for SAS;
proc g3d data=CoolPlot;
plot DemFeel*Ideology=Carter;
run;
* here is another version of the plot, this time using some graphics options;
proc g3d data=CoolPlot;
plot DemFeel*Ideology=Carter / grid
rotate=45
ctop=black
cbottom=black
zmin=0
zmax=100;
run;
* summary of options (with thanks to Rafal Raciborski):
plot x*y = z / options
appearance options
------------------
cbottom = bottom surface color
ctop = top surface color
rotate = angle to rotate (default is 70) can also be rotate = 0 to 160 by 45,
etc.
tilt = angle to tilt (default is 0) can also be tilt = 0 to 160 by 45, etc.
axes options
------------
grid
xticknum = number of ticks on the x-axis
yticknum = number of ticks on the y-axis
zticknum = number of ticks on the z-axis
zmin = min value of the z-axis
zmax = max value of the z-axis
;
quit;