* Macro call bootmed nsamp = 1000 (Number of bootstrap samples) Percnt = .25 (Percent/100 - .5 = median) nsize = 16 (sample of sample) BOOTVAR = sample (variable name) outfile = BOOTME (name of output file). 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:\test.sav'. SET SEED 1. BOOTMED NSAMP= 1000 Percnt = .5 NSIZE = 16 BOOTVAR= x OUTFILE=BOOTME . **GET THE BOOT STRAP FILE AND SMILE *. get file "BOOTME" . DEFINE BOOTMED ( NSAMP !TOKENS(1) / NSIZE !TOKENS(1) / percnt !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). compute id11 = 0. 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 less than percent * . compute tot=0. compute crit=!NSIZE * !percnt. * 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 perctle =median. *** COMPUTE MEAN USING SAME SAMPLE *** . compute MEAN=0 . loop # = 1 to !NSIZE . compute MEAN=MEAN + data(#) * tmp(#) . end loop. COMPUTE MEAN=MEAN / !NSIZE . **** Compute min. loop #=2 to !NSIZE . do if tmp(#-1) > 0. compute min= data(# -1). else. compute min = data(#). end if. end loop if tmp(#-1) > 0 . *** compute max. compute nn = !nsize -1. loop #=1 to nn . compute #i = !Nsize - #. do if tmp(#i +1) > 0. compute max= data(#i+1). else. compute mAX = data(#i). end if. end loop if tmp(#i +1) > 0. * DUMP THE MEAN and MEDIAN TO The OUTFILE * . xsave outfile !QUOTE(!OUTFILE) / keep perctle MEAN min max. * DO IT AGAIN AND AGAIN AND AGAIN .... * . end loop . execute . !ENDDEFINE .