******************************************************************************************************************** *** *** *** BEGIN MACRO FILE *** *** INTERACTION AND SIMPLE SLOPES TESTS WITH TWO CONTINUOUS VARIABLES *** *** *** *** Programmed by Jason T. Newsom *** *** Institute on Aging, Portland State University *** *** *** *** (c) 2002-2003 Jason T. Newsom. All rights reserved. *** *** *** ********************************************************************************************************************. ******************************************************************************************************************** *** This program tests the two-way interaction between two continuous variables (a separate *** macro will be available at a later date for the interaction between a continuous and dichotomous *** variable), calculates the correct standardized coefficient for the interaction variable, calculates *** standardized and unstandardized simple slopes, tests them for significance, and plots *** them. Naturally, if the interaction is nonsignificant, you should ignore the simple slopes and plot. *** *** The data set must contain three variables named x, y, and z. x is the predictor, *** z is the moderator, and y is the dependent variable. The program centers x and z *** and forms a product variable for the interaction, named xz. For example, three *** simple compute statements can be used to produce these variables (omit /* and */ ): *** *** /* COMPUTE X=indvar. */ *** /* COMPUTE Z=modvar. */ *** /* COMPUTE Y=depvar. */ *** *** Add the following two lines to any syntax file to call the macro: *** *** /* INCLUDE 'filename'. */ *** /* SIMPLE1 VARS=covariate list. */ *** *** Important: The list of variables should not include x y z--only the covariates. If no *** covariates are desired, include the VARS statement but leave the covariate *** list blank (i.e., VARS= .) *** *******************************************************************************************************************. define simple1(vars=!charend('/')). compute x=x. compute y=y. compute z=z. count miss=!vars x y z (missing). select if miss eq 0. save outfile='c:\datatemp.sav' /keep=!vars x y z. matrix. get m /variables=x y z /names=varnames /missing=omit. compute n=nrow(m). compute sums=csum(m). compute means=sums/n. compute j=make(n,1,1). compute devs=m-j*means. compute sqdevs=csum(devs&*devs). compute ss=csum(devs&*devs). compute var=ss/(n-1). compute sd=sqrt(var). compute z=devs/(j*sd). release m. * print {z} /title "z" /format=f10.3. save {devs,z} /outfile='c:\mtrxtemp.sav' /variables=devx,devy,devz,zx,zy,zz. end matrix. get file='c:\datatemp.sav'. match files /file='c:\mtrxtemp.sav' /file=*. compute x=devx. compute z=devz. compute xz=devx*devz. compute stanxz=zx*zz. save outfile='c:/regdata.sav' /keep=!vars x y z xz stanxz. get file='c:/regdata.sav'. regression /matrix out ('c:\regout.sav') /vars= !vars x y z xz stanxz /descriptives=mean stdev /statistics= r coeff ses anova bcov /dependent=y /method=enter !vars x z xz /outfile=covb ('c:/covb.sav'). get file='c:/regout.sav'. select if rowtype_='MEAN'. rename variables (x=meanx) (z=meanz). save outfile='c:/means.sav' /keep=meanx meanz. execute. get file='c:/regout.sav'. select if rowtype_='N'. rename variables (y=n). save outfile='c:/n.sav' /keep=n. execute. get file='c:/regout.sav'. select if rowtype_='STDDEV'. rename variables (x=sdx) (z=sdz) (y=sdy) (xz=sdxz) (stanxz=sdstanxz). save outfile='c:/stddevs.sav' /keep=sdx sdz sdy sdxz sdstanxz. execute. get file='c:/covb.sav'. select if rowtype_='DFE'. rename variables (xz=df). save outfile='c:/df.sav' /keep=df. execute. get file='c:/covb.sav'. select if rowtype_='EST'. rename variables (const_=constant) (x=bx) (z=bz) (xz=bxz). save outfile='c:/coeffs.sav' /keep=constant bx bz bxz. execute. get file='c:/covb.sav'. select if varname_='x'. rename variables (x=varxx) (xz=covxxz). save outfile='c:/bcovs1.sav' /keep=varxx covxxz. execute. get file='c:/covb.sav'. select if varname_='xz'. rename variables (xz=covxzxz). save outfile='c:/bcovs2.sav' /keep=covxzxz. execute. get file='c:/means.sav'. match files /file='c:/n.sav' /file='c:/stddevs.sav' /file='c:/df.sav' /file='c:/coeffs.sav' /file='c:/bcovs1.sav' /file='c:/bcovs2.sav' /file=*. execute. compute stanbxz=(bxz*(sdxz/sdy))/sdstanxz. print / ' '. print / 'Correct Standardized Slope for XZ'. print / ' ' stanbxz (f7.3). print space. execute. COMPUTE LOWZLOWX=(bx+(bxZ*-SDZ))*(-SDX)+((bz*-SDZ)+CONSTANT). COMPUTE LOWZMEDX=(bx+(bxZ*-SDZ))*(MEANX)+((bz*-SDZ)+CONSTANT). COMPUTE LOWZHIX=(bx+(bxZ*-SDZ))*(SDX)+((bz*-SDZ)+CONSTANT). COMPUTE MEDZLOWX=(bx+(bxZ*MEANZ))*(-SDX)+((bz*MEANZ)+CONSTANT). COMPUTE MEDZMEDX=(bx+(bxZ*MEANZ))*(MEANX)+((bz*MEANZ)+CONSTANT). COMPUTE MEDZHIX=(bx+(bxZ*MEANZ))*(SDX)+((bz*MEANZ)+CONSTANT). COMPUTE HIZLOWX=(bx+(bxZ*SDZ))*(-SDX)+((bz*SDZ)+CONSTANT). COMPUTE HIZMEDX=(bx+(bxZ*SDZ))*(MEANX)+((bz*SDZ)+CONSTANT). COMPUTE HIZHIX=(bx+(bxZ*SDZ))*(SDX)+((bz*SDZ)+CONSTANT). COMPUTE LOWZSLOP=bx+(bxZ*-SDZ). COMPUTE MEDZSLOP=bx+(bxZ*MEANZ). COMPUTE HIZSLOP=bx+(bxZ*SDZ). COMPUTE ERRSLP1=SQRT(VARXX+(2*(-SDZ)*(COVXXZ))+(-SDZ*-SDZ)*COVXZXZ). COMPUTE ERRSLP2=SQRT(VARXX+(2*(MEANZ)*(COVXXZ))+(MEANZ*MEANZ)*COVXZXZ). COMPUTE ERRSLP3=SQRT(VARXX+(2*(SDZ)*(COVXXZ))+(SDZ*SDZ)*COVXZXZ). compute stanslp1=lowzslop*(sdx/sdy). compute stanslp2=medzslop*(sdx/sdy). compute stanslp3=hizslop*(sdx/sdy). COMPUTE TSLOPE1=LOWZSLOP/ERRSLP1. COMPUTE TSLOPE2=MEDZSLOP/ERRSLP2. COMPUTE TSLOPE3=HIZSLOP/ERRSLP3. compute abs_t1=abs(tslope1). compute cump1=cdf.t (abs_t1,df). compute p1=(1-cump1)*2. compute abs_t2=abs(tslope2). compute cump2=cdf.t (abs_t2,df). compute p2=(1-cump2)*2. compute abs_t3=abs(tslope3). compute cump3=cdf.t (abs_t3,df). compute p3=(1-cump3)*2. print / ' '. print / 'Unstandardized Simple Slopes for X' . print / ' b'. print / ' at low Z: ' lowzslop (f6.2). print / ' at mean Z: ' medzslop (f6.2). print / ' at high Z: ' hizslop (f6.2). print / ' '. print / 'Standardized Simple Slopes for X' . print / ' beta'. print / ' at low Z: ' stanslp1 (f6.2). print / ' at mean Z: ' stanslp2 (f6.2). print / ' at high Z: ' stanslp3 (f6.2). print / ' '. print / 'Significance'. print / ' SE t-value p-value'. print / ' at low Z: ' errslp1 (f6.2) ' ' tslope1 (f6.2) ' ' p1 (f4.3). print / ' at mean Z: ' errslp2 (f6.2) ' ' tslope2 (f6.2)' ' p2 (f4.3). print / ' at high Z: ' errslp3 (f6.2) ' ' tslope3 (f6.2)' ' p3 (f4.3). execute. formats lowzlowx lowzmedx lowzhix medzlowx medzmedx medzhix hizlowx hizmedx hizhix (f10.3). write outfile='c:/plotdata.dat' /lowzlowx medzlowx hizlowx '1' /lowzmedx medzmedx hizmedx '2' /lowzhix medzhix hizhix '3' . execute. data list file='c:/plotdata.dat' notable /lowz 1-10 medz 11-20 highz 21-30 x 31. graph title = 'Simple Slopes for Y on X at Values of Z' /footnote = 'LOWZ = -1SD below mean, MEDZ=at mean, HIGHZ=+1SD above mean' / line = value(lowz medz highz) by x . !enddefine. *************************************************************************************************************. *** *** *** END OF MACRO FILE *** *** *** *************************************************************************************************************.