1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
*Author:David Marso.

/***********************************************************/
/* SPSS Macro: */
/* Bootstrapped Confidence Interval for Cronbach's Alpha */
/* Requires three arguments: */
/* NSAMP: the number of boootstrap samples */
/* VARLIST:The set of variables comprising the scale */
/* INTWID : The confidence interval (95 = 95% CI ) */
/* Example : !CA_BOOT NSAMP 2000 */
/* / VARLIST V1 TO V10 */
/* / INTWID 95 */
/* */
/* NOTE: This macro creates and deletes two files in the */
/* current working directory: 'NMACRO.INC' and */
/* 'BOOTSAMP.SAV'. The working data file is saved */
/* as 'RAWDATA.SAV' and then retrieved so it becomes */
/* the active file after the macro has completed. */ 
/***********************************************************/.


DEFINE !CA_BOOT (NSAMP !CHAREND('/')
/VARLIST !CHAREND('/')
/ INTWID !CMDEND ).

*0 Save original data after tagging ID *.
COMPUTE BOOTID=$CASENUM.
SAVE OUTFILE 'RAWDATA.SAV'.

*1 Find the sample size and create a MACRO for it *.
COMPUTE NOBREAK=1.
AGGREGATE OUTFILE * / PRESORTED / BREAK=NOBREAK / N=N.
WRITE OUTFILE 'NMACRO.INC' 
/ 'DEFINE !NCASE ( ) ',N,' !ENDDEFINE '.
EXECUTE.
SET ERRORS OFF.
INCLUDE 'NMACRO.INC'.
SET ERRORS ON.

*2 Build bootstrap samples * .
VECTOR #SUBJ( !NCASE).
LOOP SAMPLE=1 TO !NSAMP.
* Initialize a vector of case indicators * .
+ LOOP #I=1 TO !NCASE.
+ COMPUTE #SUBJ(#I)=0.
+ END LOOP.

*3 Mark each case the number of times it must be sampled *.
+ LOOP #ITER=1 TO !NCASE.
+ COMPUTE INDEX=TRUNC(UNIFORM(!NCASE))+1.
+ COMPUTE #SUBJ(INDEX)=#SUBJ(INDEX)+1.
+ END LOOP.

*4 Write out the cases for each bootstrap sample and a weight *. 
+ LOOP BOOTID=1 TO !NCASE.
+ DO IF #SUBJ(BOOTID) > 0.
+ COMPUTE BOOTWGT=#SUBJ(BOOTID) .
+ XSAVE OUTFILE 'BOOTSAMP.SAV' / KEEP SAMPLE BOOTID BOOTWGT. 
+ END IF.
+ END LOOP.
END LOOP.
EXECUTE.

*5 Attach the original data using a TABLE lookup *.
GET FILE 'BOOTSAMP.SAV' .
SORT CASES BY BOOTID.
MATCH FILES FILE * / TABLE 'RAWDATA.SAV' / BY BOOTID.

*6 Weight by the number of times cases is in each sample *.
WEIGHT BY BOOTWGT.

*7 Compute Coefficient Alpha for each sample * .
COMPUTE SCALE = SUM(!VARLIST).
AGGREGATE OUTFILE *
/ BREAK SAMPLE
/ !VARLIST SCALE=SD(!VARLIST SCALE).
DO REPEAT V=!VARLIST SCALE.
COMPUTE V=V**2.
END REPEAT.
COMPUTE NV=NVALID(!VARLIST).
COMPUTE C_ALPHA =(NV/(NV-1))*(1-(SUM(!VARLIST)/SCALE)).

* 8 Extract the lower and upper confidence limits for Alpha * .
SORT CASES BY C_ALPHA.
COMPUTE #=#+1.
COMPUTE CPCT=#/!NSAMP.
COMPUTE #IW=!INTWID/100.
SELECT IF (CPCT <=(1-#IW)/2) OR (CPCT >= 1-(1-#IW)/2 ).
COMPUTE TAG=CPCT > (1-#IW)/2.
MATCH FILES FILE * 
/ FIRST=TOP / LAST=BOT
/ BY TAG 
/ KEEP C_ALPHA CPCT TAG.
SELECT IF (NOT (TAG) AND BOT) OR (TAG AND TOP).
DO IF TAG.
COMPUTE LCL=LAG(C_ALPHA).
COMPUTE UCL=C_ALPHA.
PRINT /!QUOTE(!CONCAT(!INTWID,"% CI for Cronbach's Alpha")) /!QUOTE(!CONCAT("Based on ",!NSAMP," Samples")) /"LCL=",LCL,' UCL=',UCL .
END IF.
EXECUTE.
SELECT IF TOP.
EXECUTE.
ERASE FILE 'BOOTSAMP.SAV'.
ERASE FILE 'NMACRO.INC'.
GET FILE 'RAWDATA.SAV'.
!ENDDEFINE.

* Get a data file and Run the macro * .
* Some sample data simulated here *.

INPUT PROGRAM.
LOOP #CASE=1 to 33.
COMPUTE #SEED=NORMAL(1).
DO REPEAT V=V1 TO V10.
COMPUTE V=.7 * #SEED + NORMAL(1).
END REPEAT.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
* END OF DATA SIMULATION *.

* Invoke the macro with the following command.
* Change 2000 to the number of bootstrap samples you desire.
* Change V1 TO V10 to your variable list .
* Change 95 to the confidence interval you wish.

!CA_BOOT NSAMP=2000 / VARLIST V1 TO V10 / INTWID 95 .