SPSS Macro to calculate Krippendorff's alpha for nominal level, 2 category variables with 2 coders, with detailed printing
*----------------------------------------------------------------.
* This macro for SPSS for Windows calculates Krippendorff's .
* alpha for one or more nominal level variables that cannot be .
* skipped by coders and for which there are *two* valid coding .
* categories (0 and 1). In the process it prints the details .
* of the calculations (another version without the detailed .
* printout is available as well).
* If you have questions please contact Matthew Lombard at .
* lombard@temple.edu.
*----------------------------------------------------------------.
*----------------------------------------------------------------.
* To invoke this macro, start the SPSS program, use the File .
* menu to open a new syntax window. Paste the macro into the .
* new syntax file. Search for the text "FOR UNIT NO.:" .
* and following it type in the name of the variable in .
* your dataset that indicates the case or unit number.
* At the bottom of the file add the command to invoke the
* macro. Use this format: .
* .
* macroname vara varb.
* .
* where macroname is the name of the macro (which follows .
* the define command), vara is the dataset variable that .
* contains the values from the first coder, and varb is .
* the dataset variable that contains the values from the .
* second coder (an example has been included in this file).
* Multiple variables can be evaluated in a single use of the macro.
* .
* Use the "Run" menu option to have SPSS implement the macro.
*----------------------------------------------------------------.
*----------------------------------------------------------------.
*----------------------------------------------------------------.
* Define the macro and the variables to be used in the .
* macro, which are to be specified when the macro is invoked.
*----------------------------------------------------------------.
DEFINE K2C2CTP (!POSITIONAL !TOKENS(1)/
!POSITIONAL !TOKENS(1) )
*----------------------------------------------------------------.
* Save current SPSS environment settings, save a copy of the .
* current data-set file, and set default values for calculations .
* that follow.
*----------------------------------------------------------------.
SAVE OUTFILE= 'K2_TMP1.SAV'.
EXECUTE.
COMPUTE BRKGRP = 1.
*---------------------------------------------------------------------.
* COUNT NUMBER OF TIMES EACH CATEGORY WAS CODED .
* FOR EACH RECORDING UNIT: .
*---------------------------------------------------------------------.
COUNT N_1 = !1 !2 (0).
COUNT N_2 = !1 !2 (1).
PRINT /
/"FOR UNIT NO.: " CASENO " - N_1: " N_1
/"FOR UNIT NO.: " CASENO " - N_2: " N_2
/.
EXECUTE.
*---------------------------------------------------------------------.
* COMPUTE NUMERATOR VALUE: FIRST FOR EACH UNIT SEPARATELY.
*---------------------------------------------------------------------.
COMPUTE NUM =
(N_1 * N_2).
PRINT /
/"FOR UNIT NO.: " CASENO " - NUM: " NUM
/.
EXECUTE.
*---------------------------------------------------------------------.
* COMPUTE and save in a new temporary file the numerator value .
* across recording units.
* .
* NUMER is the sum across values of num all cases.
* NA_1 is the sum across all values of N_1 for the denominator.
* NA_2 is the sum across all values of N_2 for the denominator.
* UNITS is the number of cases.
*---------------------------------------------------------------------.
AGGREGATE
/OUTFILE=' K2_TMP2.SAV'
/PRESORTED
/BREAK=BRKGRP
/NUMER=SUM(NUM)
/NA_1=SUM(N_1)
/NA_2=SUM(N_2)
/UNITS=N.
GET FILE ' K2_TMP2.SAV'.
PRINT /
/"NUMER: " NUMER
/"NA_1: " NA_1
/"NA_2: " NA_2
/"UNITS: " UNITS
/.
EXECUTE.
COMPUTE DENOM =
(NA_1 * NA_2).
PRINT /
/"DEMON: " DENOM.
EXECUTE.
DO IF DENOM = 0.
COMPUTE RELIAB = 1.00 .
ELSE.
COMPUTE RELIAB =
(1) - ( ( (UNITS * 2-1)/(2-1) ) * (NUMER/DENOM) ).
END IF.
PRINT /'***************************************************'
/'KRIPPENDORFFS ALPHA FOR THIS VARIABLE IS: ' RELIAB
/'***************************************************'
/.
EXECUTE.
GET FILE 'K2_TMP1.SAV'.
EXECUTE.
ERASE FILE 'K2_TMP2.SAV'.
EXECUTE.
!ENDDEFINE.
K2C2CTP var1c1 var1c2.