* Question was: How can I find random pairs of cases for T-Test? * Note that the data file is NOT supplied with the code. * Current assumptions. * control variables (eg altgrp1) have integer values between 0 and 9. * sample variables (eg labfibg) have values of 1 or another integer. * maximum number of characters in name of the control variables is 7. * (the above condition is required because a 1 is added at the end of these names). * there are less than 100,000 cases being studied. * The above restrictions could be removed by making the macro more general. * Raynald Levesque Raynald@spsstools.net *Replace OFF by ON if you want to see more details in the Output.. SET MPRINT=OFF. *////////////////////////////////////////// Beginning of Macro ////////////////////////////. DEFINE !paired (sample =!CHAREND('/') /control =!CHAREND('/') /dv =!CHAREND('/') /fname =!DEFAULT("") !CMDEND) GET FILE='C:\\Program Files\\SPSS\\test\\riskfact.sav'. *Create the comparative criteria. COMPUTE criter=0. !DO !var !IN (!control) + COMPUTE criter=criter*10 + !var. !DOEND. EXECUTE. SELECT IF(~MISSING(criter)). COMPUTE draw=UNIFORM(1). SORT CASES BY !sample criter. RANK VARIABLES=draw (A) BY !sample criter /RANK /PRINT=YES /TIES=MEAN . SORT CASES BY criter rdraw. *compute the matching criteria. COMPUTE criter2=criter*100000+rdraw. SAVE OUTFILE='C:\\Program Files\\SPSS\\test\\all_data.sav'. SELECT IF (!sample=1). SAVE OUTFILE='C:\\Program Files\\SPSS\\test\\normal pop.sav'. GET FILE='C:\\Program Files\\SPSS\\test\\all_data.sav'. SELECT IF (!sample<>1). !DO !var !IN (!control) + RENAME VARIABLES (!var=!CONCAT(!var,1)). !DOEND. !LET !dv1=!NULL. !DO !var !IN (!dv) + RENAME VARIABLES (!var=!CONCAT(!var,1)). + !LET !dv1=!CONCAT(!dv1," ",!var,1) !DOEND. RENAME VARIABLES (lfnr=lfnr1) (rdraw=rdraw1). SAVE OUTFILE='C:\\Program Files\\SPSS\\test\\pathological pop.sav'. MATCH FILES /FILE=* /FILE='C:\\Program Files\\SPSS\\test\\normal pop.sav' /RENAME (!sample = d0) /BY criter2 /DROP=d0. * Next line is to keep only cases which have a match. SELECT IF (~MISSING(lfnr1) AND ~MISSING(lfnr)). EXECUTE. !IF (!LENGTH(!fname) !NE 0) !THEN SAVE OUTFILE=!QUOTE(!CONCAT('C:\\Program Files\\SPSS\\test\\',!fname,'.sav')). !IFEND T-TEST PAIRS= !dv WITH !dv1 (PAIRED) /CRITERIA=CIN(.95) /MISSING=ANALYSIS. !ENDDEFINE. *////////////////////////////////////////// End of Macro /////////////////////////////////////. **** Example no 1: call macro to study labfibg ****. !paired sample =labfibg /control =altgrp1 sex rr2grp diabet nikotin /dv = Іbag Іher /fname =labfibg controling for 5 var. *The macro variables are. *sample =the variable being studied. *control =the variables being controlled. *dv =the dependent variables. *fname =the name of the file containing the matched data. * leave the name blank if this is not needed. **** Example no 2: call macro to study l_cholgr ****. !paired sample = l_cholgr /control =altgrp1 sex rr2grp nikotin gewicht /dv = Іbag Іher /fname =. * Note that in example 2, fname is blank therefore the data file containing the matched data is not saved.