Back to Andrew’s homepage

Preacher, K. J., & Hayes, A. F. (2004).  SPSS and SAS procedures for estimating indirect effects

in simple mediation models.  Behavior Research Methods, Instruments, and Computers, 36, 717-731.

 

Click here to download the SPSS syntax file

Click here to get the SPSS data file from Preacher and Hayes paper

Get a PDF of Preacher and Hayes by clicking here

Can’t get the macro to work?  Check here.

NOTE: WE HAVE RECENTLY DEVELOPED A FAR SUPERIOR MACRO THAT ALLOWS FOR MULTIPLE MEDIATORS, STATISTICAL CONTROLS,  GENERATES BIAS-CORRECTED AND BIAS-CORRECTED AND ACCELERATED BOOTSTRAP CONFIDENCE INTERVALS, AND CONDUCTS CONTRASTS BETWEEN INDIRECT EFFECTS.  FOR DETAILS, CLICK HERE.

 

Interested in testing a moderated mediation hypothesis?  Click here.

 

Instructions for Use of SPSS Macro [PDF]

To activate the macro, execute the command set at the end of this appendix by typing it verbatim into an SPSS syntax file or downloading from the link above. Once the command set is executed, a new SPSS syntax command, SOBEL, will be available for use. This command is available until SPSS is closed. To run the mediation analysis on a data set, execute the following command in SPSS:

 

SOBEL y=yvar/x=xvar/m=mvar/boot=z.

 

where yvar is the name of the dependent variable in your data file, xvar is the name of the independent variable, mvar is the name of the proposed mediating variable, and z specifies the number of bootstrap resamples desired, in increments of 1000 up to a maximum of 1,000,000. For example, if z is set to 3000, then the bootstrap estimates will be based on 3000 resamples. If z is set to 0 (or any number less than 1000), the bootstrapping module is deactivated.

All four of these arguments must be provided. Any cases that are system missing on any of the three variables will be deleted from the mediation analysis (i.e., listwise deletion), but they will remain in the active SPSS data file. If the user desires any kind of imputation of missing values, imputation must be completed prior to running the SOBEL command. The SPSS matrix language does not recognize user-defined missing values, so any cases with user-defined missing values will be treated as valid data.

There are no error checking procedures in the macro, so the output should be examined carefully to make sure there are no errors printed. The most likely causes of errors include entering the command (or the original macro) incorrectly, using a variable that is actually a constant in the data file, or requesting a bootstrapped estimate when the original sample is very small. The latter error stems from the fact that bootstrap resampling is done with replacement, and it is possible for a variable resulting from a bootstrap sample to end up being a constant even though none of the variables are actually constants. The minimum sample size will depend on a number of factors, but in testing, the macro usually worked so long as n was at least 25 or so. Depending upon processor speed and the size of the sample, it may appear that SPSS has locked up or crashed once the SOBEL command is executed. Be patient.

            Because bootstrapping is based on random sampling from the data set, each run of the program will generate slightly different estimates of the indirect effect and its standard error, and the upper and lower bounds of confidence intervals will vary from run to run. The larger the number of bootstrap samples taken, the less variable these estimates will be over consecutive runs of the program. However, it is possible to replicate a set of bootstrap resamples by setting the random number seed prior to executing the SOBEL command. This is accomplished by preceding the SOBEL command with the command SET SEED seedval where seedval is a number between 1 and 2,000,000. If the same seed and number of bootstrap samples are requested over multiple runs on the same data, the output from those runs will be identical.


 

Instructions for Use of SAS Macro

Right-click here to download the SAS syntax file

Click here to download SAS data from Preacher and Hayes paper

The procedures for using the SAS version of the macro are largely the same as for the SPSS version. The user should first execute the command set at the end of this appendix (available online from http://www.jcomm.ohio-state.edu/ahayes/sobel.htm). This will activate a command called %sobel, with syntax:

 

%sobel(data=file, y=dv, x=iv, m=med, boot=z);

 

where file is the name of a SAS data file containing the data to be analyzed, dv is the name of the dependent variable in the data file, iv is the name of the independent variable, med is the name of the proposed mediating variable, and z specifies the number of bootstrap resamples desired. Except for command format, usage is the same as for the SPSS version of the macro.

The macro will exclude all cases from the analysis missing on any of the three variables, where missing is defined as the period character ("."). There is no error checking in the macro, so examine the log file carefully to look for errors. It will be obvious if an error occurs because a line marked "ERROR" will appear in the SAS log file. The same conditions described in Appendix A will produce errors in the SAS version of the macro.

To save the bootstrapped estimates of the indirect effect as a SAS data file for later examination, the following commands should be added just before the quiz command at the end of the macro:

create filename from res [colname='indirect'];

append from res;

where filename is any valid SAS file name.

            As currently configured, the random number generator will be seeded randomly. To set the seed, thus allowing you to replicate a set of bootstrap samples, change the "0" in the line that reads v = int(uniform(0)*n)+1 to any positive integer less than 232 – 1.