An SPSS Macro for run a series of simple linear regressions Often, before beginning to build a multi-variable regression model, the researcher may wish to examine a series of "univariate" models--univariate meaning only one predictor variable. One way to do this (in SPSS) is to generate the REGRESSION syntax for the first univariate model, then make several copies, and edit the name of the predictor variable in the copies. This is not difficult, but it can be rather time-consuming if you want to run a lot of models; and there is always potential for typos when one edits syntax in this fashion. This kind of scenario is ideal for using a MACRO. I am not yet very good at using the SPSS Macro Facility. But I did manage to cobble together the following macro to perform exactly this task. The main constraint to bear in mind is that it requires the series of predictor variables to be named X1, X2, X3, and so on. It also presupposes the existence of another macro called !dpath that returns the path to the folder in which you wish to save the regression coefficients from each of the univariate regressions. The macro definition is shown below, along with an example of syntax that calls it. * ------- Start of macro example ----------- . define !dpath ()'C:\bw\LU\CSIC\data\'!enddefine. * Define macro SLR (simple linear regression). * This macro will perform a series of simple linear * regressions with the same outcome variable (Y). * The macro has 4 arguments: * Y = the name of the outcome variable * NUMVARS = the number of predictor variables * PATH = the folder in which to save the files of coefficients * ROOT = the root file name to use when saving coefficients. * The macro needs predictor variables named X1, X2, X3, etc. * Therefore, before calling the macro, you must create these variables. * You can either RENAME existing variables, or compute new ones. DEFINE !SLR (Y = !tokens(1) / numvars = !tokens(1) / path = !tokens(1) / root = !tokens(1)). !DO !i = 1 !to !numvars. !LET !file = !quote(!concat(!unquote(!path),!unquote(!root),!i,'.sav')) !LET !x = !concat('x',!i) REGRESSION /STATISTICS = COEFF /DEPENDENT !Y /METHOD=ENTER !x /OUTFILE=COVB(!file) . !DOEND. !ENDDEFINE. * Create predictor variables suitable for * the SLR macro shown above, and label them . numeric x1 to x5 (f5.0). do repeat newvar = x1 to x5 / oldvar = crgender crage cggender cgage urbnrurl . - compute newvar = oldvar. end repeat. exe. var lab x1 'CR Gender' x2 'CR Age' x3 'CG Gender' x4 'CG Age' x5 'Urban v Rurual'. descrip x1 to x5. /* check for out of range values . * Call the SLR macro . !SLR Y = csi.t1 /* DV = CSI at baseline */ numvars = 5 /* run regressions with X1 to X5 */ path = !dpath /* save files to this folder */ root = 'SLR model'. /* root name for files . * ------ End of !SLR example ------- . Note that in the !SLR macro definition, I included the REGRESSION procedure's /OUTFILE subcommand in such a way that the regression coefficients were saved to a file for each univariate regression. Therefore, I can now read in the first of those files, and use ADD FILES to stack the files (i.e., combine them into one big file). Again, I could do this by creating ADD FILES syntax for the 2nd file in the list, then copy and edit for files 3 to N. But for a repetitive task like this, I could also use another macro. Here is one that does the job. * ---- Start of ADD FILES macro example ---------- . * Macro !ADDFILE replaces a series of ADD FILES commands. * I will use it to stack the files of coefficients from * the series of univariate regressions. DEFINE !addfile (nfiles = !tokens(1) / path = !tokens(1) / root = !tokens(1)). !DO !i = 2 !to !nfiles. !LET !file = !quote(!concat(!unquote(!path),!unquote(!root),!i,'.sav')) add files file = * /file = !file. exe. !DOEND. !ENDDEFINE. get file = !dpath + 'SLR model1.sav'. /* Read in the first file . * Call ADDFILE macro to stack the remaining files. !addfile nfiles = 5 /* total number of files . path = !dpath /* folder in which files are stored . root = 'SLR model'. /* root name for files . * ------ end of ADDFILE macro example ------ . -- Bruce Weaver bweaver@lakeheadu.ca www.angelfire.com/wv/bwhomedir 5-Oct-2004