SET PRINTBACK ON MPRINT ON . * Bootstrap the mean and the median. * Author: David Marso. * Raynald's note: 474 is the number of cases in the file. It is possible to let the syntax automatically determine this number (see bcnon.sps for instance). GET FILE='C:\\Program Files\\SPSS\\Employee data.sav'. BOOTMED NSAMP=1000 NSIZE = 474 BOOTVAR=SALARY OUTFILE=BOOTME . **GET THE BOOT STRAP FILE AND SMILE *. get file "BOOTME" . DEFINE BOOTMED ( NSAMP !TOKENS(1) / NSIZE !TOKENS(1) / BOOTVAR !TOKENS(1) / OUTFILE !TOKENS(1) ) . * STUFF IT ALL ***SORTED*** INTO ONE CASE * . sort cases by !BOOTVAR . vector data (!NSIZE). compute data($casenum)=!BOOTVAR . compute nobreak=1. aggregate outfile * / break nobreak / data1 to !CONCAT(data,!NSIZE) = max(data1 to !CONCAT(data,!NSIZE)). * DO ON THE FLY RANDOMIZATION AND STAT CALCULATION * . vector data=data1 to !CONCAT(data,!NSIZE) . vector tmp (!NSIZE). loop #P=1 to !NSAMP. * INITIALIZE A STORAGE ARRAY FOR EACH ITERATION * . loop #=1 to !NSIZE . compute tmp(#)=0. end loop. * INCREMENT STORAGE EACH TIME A CASE IS SAMPLED * . loop #I=1 to !NSIZE . compute ID=trunc(uni(!NSIZE )+1). compute tmp(ID)=TMP(ID)+1. end loop. **** IN THIS EXAMPLE I CREATE THE MEDIAN AND MEAN**** . **** YOU MAY WISH TO USE A DIFFERENT FUNCTION ****. **** IN WHICH CASE PLUG AWAY!!! **** * CALCULATE THE CASE COUNT CONTAINING THE MEDIAN * . compute tot=0. compute crit=!NSIZE / 2. * LOOP UNTIL YOU FIND THE CRITICAL CASE * . loop #=1 to !NSIZE . compute tot=tot + tmp(#). end loop if tot >=crit . * CALCULATE THE MEDIAN * . do if mod(!NSIZE,2)=0 . compute median=(data(#) + data(#-1))/2. else. compute median=data(#). end if . *** COMPUTE MEAN USING SAME SAMPLE *** . compute MEAN=0 . loop # = 1 to !NSIZE . compute MEAN=MEAN + data(#) * tmp(#) . end loop. COMPUTE MEAN=MEAN / !NSIZE . * DUMP THE MEAN and MEDIAN TO The OUTFILE * . xsave outfile !QUOTE(!OUTFILE) / keep median MEAN . * DO IT AGAIN AND AGAIN AND AGAIN .... * . end loop . execute . !ENDDEFINE .