preserve. set printback=on. * SIMPLE AND COMPLEX RANDOM ASSIGNMENT IN EXPERIMENTAL DESIGN (Version 2.0) Valentim R. Alferes, University of Coimbra (Portugal), 2014. * WITHIN-SUBJECTS DESIGNS. * Program: PC-Ls6proc2.sps Method 15: Positional Counterbalancing - Design 6M6: Repeated Measures Latin Square Design (t=6, n=6, p=6). * NOTE: This program has no user's specifications. Just select RUN/ALL. set printback=off. set ovars labels onumbers values tvars labels tnumbers labels. set olang=English small=0 errors=none decimal=dot. new file. data list free/c1(f8.0) c2(f8.0) c3(f8.0) c4(f8.0) c5(f8.0) c6(f8.0). begin data 1 2 3 4 5 6 2 6 4 3 1 5 3 4 5 6 2 1 4 1 6 5 3 2 5 3 1 2 6 4 6 5 2 1 4 3 end data. value labels all 1'A' 2'B' 3'C' 4'D' 5'E' 6'F'. variable labels c1'Column_1' c2'Column_2' c3'Column_3' c4'Column_4' c5'Column_5' c6'Column_6'. compute Order=6. compute Row=$casenum. execute. formats all(f8.0). oms/select tables/if commands=["summarize"] subtypes=["case processing summary"]/destination viewer=no. summarize/tables=order row c1 to c6/format=list nocasenum nototal /title='Square 1: Selected Standard Square'/footnote 'Source: Cochran & '+ 'Cox, 1957, pp. 145-146.'/cells=none. save outfile='%temp%\fout0'. new file. input program. loop x=1 to 6. end case. end loop. end file. end input program. execute. set rng=mt mtindex=random. compute rn=rv.uniform(0,1). execute. rank variables=rn(a)/rank/print=no/ties=condense. compute Permutation=rrn. compute y=permutation. execute. value labels x y 1'A' 2'B' 3'C' 4'D' 5'E' 6'F'. variable labels x"Symbols in Square 1" y"Symbols in Square 2". formats all(f8.0). summarize/tables=x permutation y/format=validlist nocasenum nototal /title='Random Permutation for the Symbols of the Standard Square'/cells=none. save outfile='%temp%\fout1'/keep permutation. get file='%temp%\fout0'. sort cases by c1(a). match files/file=*/file='%temp%\fout1'. execute. compute Column_1=permutation. execute. delete variables permutation. sort cases by c2(a). match files/file=*/file='%temp%\fout1'. execute. compute Column_2=permutation. execute. delete variables permutation. sort cases by c3(a). match files/file=*/file='%temp%\fout1'. execute. compute Column_3=permutation. execute. delete variables permutation. sort cases by c4(a). match files/file=*/file='%temp%\fout1'. execute. compute Column_4=permutation. execute. delete variables permutation. sort cases by c5(a). match files/file=*/file='%temp%\fout1'. execute. compute Column_5=permutation. execute. delete variables permutation. sort cases by c6(a). match files/file=*/file='%temp%\fout1'. execute. compute Column_6=permutation. execute. delete variables permutation. value labels column_1 to column_6 1'A' 2'B' 3'C' 4'D' 5'E' 6'F'. sort cases by row(a). formats all(f8.0). summarize/tables=row column_1 to column_6/format=list nocasenum nototal /title='Square 2: Random Permutation of Square 1 Symbols'/cells=none. delete variables order row c1 to c6. set results=no. flip variables=all. set results=yes. set rng=mt mtindex=random. compute rn=rv.uniform(0,1). execute. compute permcols=$casenum. execute. sort cases by rn(a). variable labels permcols'Permutation'. formats permcols(f8.0). summarize/tables=permcols/format=list nocasenum nototal /title='Random Permutation for the Columns of Square 2'/cells=none. delete variables rn permcols. set results=no. flip variables=all/newname=case_lbl. set results=yes. delete variables case_lbl. value labels all 1'A' 2'B' 3'C' 4'D' 5'E' 6'F'. compute Row=$casenum. execute. formats all(f8.0). summarize/tables=row all/format=list nocasenum nototal /title='Square 3: Random Permutation of Square 2 Columns'/cells=none. set rng=mt mtindex=random. compute rn=rv.uniform(0,1). execute. sort cases by rn(a). compute permrows=row. execute. variable labels permrows'Permutation'. formats all(f8.0). summarize/tables=permrows/format=list nocasenum nototal /title='Random Permutation for the Rows of Square 3'/cells=none. delete variables rn permrows. formats all(f8.0). summarize/tables=row all/format=list nocasenum nototal /title='Square 4: Random Permutation of Square 3 Rows'/cells=none. delete variables row. set results=no. flip variables=all. set results=yes. compute myname=$casenum. execute. string yourname(a8). compute yourname='P_'. execute. string finalname(A8). compute finalname=concat(rtrim(yourname),ltrim(string(myname,f5))). execute. delete variables case_lbl myname yourname. set results=no. flip all/newname=finalname. set results=yes. delete variables case_lbl. value labels all 1'A' 2'B' 3'C' 4'D' 5'E' 6'F'. compute Unit=$casenum. execute. formats all(f8.0). summarize/tables=unit all/format=list nocasenum nototal /title='Final Randomization (Square 4)' /footnote 'P = Period. \n'+ 'If necessary, repeat the syntax for each new set of 6 units.'/cells=none. save outfile='%userprofile%\desktop\FinalRandomization.sav'/keep unit all. get file='%userprofile%\desktop\FinalRandomization.sav'. erase file='%temp%\fout0'. erase file='%temp%\fout1'. restore.