SPSS Macro to calculate Krippendorff's alpha for nominal level, 3 category variables with 2 coders
*----------------------------------------------------------------.
* 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 *three* valid coding .
* categories (0, 1 and 2). In the process it prints the details .
* of the calculations (another version with 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 K2C3CTP (!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).
COUNT N_3 = !1 !2 (2).
*---------------------------------------------------------------------.
* COMPUTE NUMERATOR VALUE: FIRST FOR EACH UNIT SEPARATELY.
*---------------------------------------------------------------------.
COMPUTE NUM =
(N_1 * N_2) +
(N_1 * N_3) +
(N_2 * N_3).
*---------------------------------------------------------------------.
* 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.
* NA_3 is the sum across all values of N_3 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)
/NA_3=SUM(N_3)
/UNITS=N.
GET FILE ' K2_TMP2.SAV'.
COMPUTE DENOM =
(NA_1 * NA_2) +
(NA_1 * NA_3) +
(NA_2 * NA_3).
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.
SET PRINTBACK=LISTING.
K2C2CTP var1c1 var1c2.
SET PRINTBACK=OFF.