* ======================================================================= * File: macro_with_nested_loop.SPS . * Date: 25-May-2005 . * Author: Bruce Weaver, bweaver@lakeheadu.ca . * Notes: Example of nested loop in macro, where arithmetic is used to compute the starting point for the internal loop . * ======================================================================= . * Read in some data to illustrate. * Data are binary ratings of 24 objects by 4 raters. data list list / item r1 to r4 (5f2.0). begin data. 1 1 1 0 1 2 0 1 1 1 3 0 1 0 1 4 0 1 0 1 5 1 1 0 1 6 0 0 0 1 7 1 1 1 1 8 1 1 1 1 9 1 0 0 0 10 1 0 0 1 11 0 0 0 1 12 1 1 1 1 13 0 1 0 1 14 1 1 1 1 15 0 1 0 1 16 1 1 1 1 17 0 0 0 0 18 1 1 1 1 19 0 1 0 1 20 1 1 1 1 21 1 1 1 1 22 1 1 1 1 23 1 0 0 1 24 1 1 0 1 end data. var lab r1 'Rater 1' r2 'Rater 2' r3 'Rater 3' r4 'Rater 4' . * Run all pairwise kappas . * Method 1 . crosstabs var = r1 to r4 (0,1) /table = r1 by r2 /table = r1 by r3 /table = r1 by r4 /table = r2 by r3 /table = r2 by r4 /table = r3 by r4 /stat = kappa. * This method is not great for a large number of raters. * A macro with a nested loop would be better. * One problem to overcome is that macros cannot do arithmetic. * Therefore, the "nogood" macro shown below will not work. /* ------- NOGOOD macro that will not work ---- . define !nogood (start = !tokens (1) / finish = !tokens (1) ) . !do !i = !start !to (!finish - 1) !let !r1 = !concat('r',!i) !do !j = (!i + 1) !to !finish !let !r2 = !concat('r',!j) crosstabs /table = !r1 by !r2 /stat = kappa. !doend !doend !enddefine. * ------------------------------------------------------------- . * Raynald's SPSS Tools website has some macro arithmetic * examples in this file: * http://www.spsstools.net/Macros/ArithmeticWithMacroVariables.txt . * I should be able to make use if these to get the job done. * ------------------------------------------------------------- . /* ----- Definition of PAIRS macro -------- . define !pairs (start = !tokens (1) / finish = !tokens (1) ) . !let !one = 1 /* set !fminus1 = !finish - !one */ !let !fminus1 = !length(!substr(!blanks(!finish), !length(!concat(!blanks(!one), !blanks(1))))) !do !i = !start !to !fminus1 !let !r1 = !concat('r',!i) /* set !iplus1 = !i + !one */ !let !iplus1 = !length(!concat(!blanks(!i), !blanks(!one))) !do !j = !iplus1 !to !finish !let !r2 = !concat('r',!j) crosstabs /table = !r1 by !r2 /stat = kappa. !doend !doend !enddefine. /* -------------------------------------- . set mprint on. !pairs start = 1 finish = 4 . set mprint off. * NOTE that in a case like this it would also be convenient * to use the Output Management System (OMS) to direct the * output for each pair of raters to a file. * OMS became available in SPSS 12, IIRC. OMS /SELECT TABLES /IF COMMANDS = ["Crosstabs"] SUBTYPES = ["Case Processing Summary"] /DESTINATION FORMAT = SAV NUMBERED = TableNumber_ viewer = no OUTFILE = "case processing summary.sav". OMS /SELECT TABLES /IF COMMANDS = ["Crosstabs"] SUBTYPES = ["Crosstabulation"] /DESTINATION FORMAT = SAV NUMBERED = TableNumber_ viewer = no OUTFILE = "crosstabulation.sav". OMS /SELECT TABLES /IF COMMANDS = ["Crosstabs"] SUBTYPES = ["Symmetric Measures"] /DESTINATION FORMAT = SAV NUMBERED = pair viewer = no OUTFILE = "pairwise kappas.sav". !pairs start = 1 finish = 4 . OMSEND. * Open file with pairwise kappas, and get descriptives. get file = "pairwise kappas.sav". select if (var2="Kappa"). exe. rename var (value = kappa). descriptives kappa. GRAPH /HISTOGRAM=kappa /TITLE= 'All pairwise kappas'. * Erase files when finished. new file. erase file = "case processing summary.sav". erase file = "crosstabulation.sav". erase file = "pairwise kappas.sav". * ======================================================================= .