/* This SPSS macro estimates a population mean and generates a 95%*/. /* confidence interval via bootstrapping. The syntax is BOOTMEAN x /* where x is a variable in the open data file. Output provides the */. /* sample mean ("Sample"), the bootstrap estimate of the population mean */. /* based on 1000 resamples with replacement ("Bootstrp"), and the lower */. /* ("Lo95%CI") and upper ("Hi95%CI) limits of a 95% confidence interval */. /* for the population mean based on the bootstrapped sampling distribution */. /* The 1000 bootstrap estimates are saved as an SPSS data file on the C */. /* drive with file name bootmean.sav. */. /* */. /* First execute the program below. This will create a new command */. /* called BOOTMEAN that you can then execute, as described above */. /* The macro will remain active only until you quit SPSS */. DEFINE bootmean (!POSITIONAL !TOKEN (1)). set mxloops = 10000. preserve. set length = none. set seed = random. matrix. get dd/variables = !1/MISSING = OMIT. compute reps = 1000. compute n = nrow(dd). compute mnb = make(reps,1,0). compute dat=dd. compute mni=dd. compute mn=csum(dat)/n. loop #n = 1 to reps. compute v=trunc(uniform(n,1)*n)+1. compute dat(:,1)=dd(v,1). compute mnb(#n,1)=csum(dat)/n. end loop. compute bmn = csum(mnb)/reps. compute mnb = {-999;mnb}. loop #i = 2 to reps+1. compute ix = mnb(#i,1). loop #k= #i to 2 by -1. compute k = #k. do if (mnb(#k-1,1) > ix). compute mnb(#k,1)=mnb(#k-1,1). else if (mnb(#k-1,1) <= ix). BREAK. end if. end loop. compute mnb(k,1)=ix. end loop. compute mnb = mnb(1:reps+1,1). compute loci = mnb(25,1). compute hici = mnb(976,1). compute bw={mn, bmn, loci, hici, n}. print/title = "BOOTSTRAP MEAN ESTIMATES, 1000 RESAMPLES". print bw/title = " "/clabels = "Sample" "Bootstrp" "Lo95%CI " "Hi95%CI" "n"/format f9.4. save mnb/outfile = 'c:\bootmean.sav'. end matrix. restore. !END DEFINE.