Back to Andrew’s homepage

Web page to support

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.

If you will be using this macro in published work, please cite the paper rather than this web page.

 

 

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 (2004) by clicking here

Can’t get the macro to work or have questions?  Check here for some macro rules and answers to frequently asked questions.

Join the new Statistical Mediation and Moderation Analysis group on Facebook.

If you are interested in moderation (a.k.a. “interaction”) rather than mediation, click here.

Can an effect that doesn’t exist be “mediated”?  Click here.

 

NOTE: WE HAVE 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.

 

 

NOTE: Some users of SPSS 18 have reported problems with macros and scripts.  Click here for more information and a possible solution.

 

 

 

Interested in testing a moderated mediation hypothesis?  Click here.

 

NEW: As of January 3, 2009, the SOBEL macro for SPSS (but not SAS) works with dichotomous outcome variables (Y only).  See the SOBEL syntax reference for details. 

 

A script has also been produced for SPSS that uses a Windows-style dialog box for setting up the model  (see below). Download the script file here.  You should open this file within SPSS as a script file.  It will not run as a syntax file.  Here is a document on opening and running scripts in SPSS for Windows.

 

 SPSS SOBEL script dialog box

 

Instructions for Use of SPSS Macro [PDF]

To activate the macro, execute the SOBEL macro command set that you downloading from the link above.   Run it exactly as is.  Do not modify it one bit.  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 SOBEL command set for SAS.  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.

 

DISCLAIMER:  As with all statistical software, all attempts are made to make sure that the computations programmed into this macro are being performed correctly.  When bugs are found and reported, I attempt to eliminate them as quickly as possible.  I offer these macros to the research community “as is” and accept no responsibility for any negative consequences that might result from their use.  In other words, use at your own risk. 

 

 

 

free hit counter