Sampling with Replacement and Regression Macro

The most complicated part of the OMS bootstrapping example has nothing to do with the OMS command. A macro routine is used to generate the samples and run the REGRESSION commands. Only the basic functionality of the macro is discussed here. For detailed information on macros, see DEFINE-!ENDDEFINE.

DEFINE regression_bootstrap (samples=!TOKENS(1)
                             /depvar=!TOKENS(1)
                             /indvars=!CMDEND)
                                          
COMPUTE dummyvar=1.
AGGREGATE
  /OUTFILE=* MODE=ADDVARIABLES
  /BREAK=dummyvar
  /filesize=N.
!DO !other=1 !TO !samples
SET SEED RANDOM.
WEIGHT OFF.
FILTER OFF.
DO IF $casenum=1.
- COMPUTE #samplesize=filesize.
- COMPUTE #filesize=filesize.
END IF.
DO IF (#samplesize>0 and #filesize>0).
- COMPUTE sampleWeight=rv.binom(#samplesize, 1/#filesize).
- COMPUTE #samplesize=#samplesize-sampleWeight.
- COMPUTE #filesize=#filesize-1.
ELSE.
- COMPUTE sampleWeight=0.
END IF.
WEIGHT BY sampleWeight.
FILTER BY sampleWeight.
REGRESSION
  /STATISTICS COEFF
  /DEPENDENT !depvar
  /METHOD=ENTER !indvars.
!DOEND
!ENDDEFINE.

GET FILE='/examples/data/Employee data.sav'.

regression_bootstrap 
   samples=100
   depvar=salary 
   indvars=salbegin jobtime.
  • A macro named regression_bootstrap is defined. It is designed to work with arguments similar to IBM® SPSS® Statistics subcommands and keywords.
  • Based on the user-specified number of samples, dependent variable, and independent variable, the macro will draw repeated random samples with replacement and run the REGRESSION command on each sample.
  • The samples are generated by randomly selecting cases with replacement and assigning weight values based on how many times each case is selected. If a case has a value of 1 for sampleWeight, it will be treated like one case. If it has a value of 2, it will be treated like two cases, and so on. If a case has a value of 0 for sampleWeight, it will not be included in the analysis.
  • The REGRESSION command is then run on each weighted sample.
  • The macro is invoked by using the macro name like a command. In this example, we generate 100 samples from the employee data.sav file. You can substitute any file, number of samples, and/or analysis variables.

Next