**Date:** Tue, 20 Sep 2005 09:52:34 +0200
**Reply-To:** Marta García-Granero
<biostatistics@terra.es>
**Sender:** "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
**From:** Marta García-Granero
<biostatistics@terra.es>
**Organization:** Asesoría Bioestadística
**Subject:** Re: Transforming vector data into matrix format
**In-Reply-To:** <1582395875.20050920094540@terra.es>
**Content-Type:** text/plain; charset=ISO-8859-15
Hi Paul,

Is this what you need?

DATA LIST LIST/ID v1 TO v10 (11 F8.0).
BEGIN DATA
1 2 3 7 8 10 1 4 5 6 9
2 10 2 1 3 4 5 6 7 9 8
3 9 6 4 2 1 3 5 7 10 8
1000 2 4 8 10 9 3 5 7 1 6
END DATA.

MATRIX.
GET data /VAR=v1 TO v10 /NAMES=vnames.
COMPUTE nvars=NCOL(data).
COMPUTE ndata=NROW(data).
* Set diagonal values at n/2 *.
COMPUTE diagmat=MAKE(nvars,nvars,0).
CALL SETDIAG(diagmat,ndata/2).
* Upper diagonal *.
LOOP i=1 TO ndata.
- LOOP j=1 TO nvars-1.
- LOOP k=j TO nvars.
- DO IF data(i,j) GT data(i,k).
- COMPUTE diagmat(j,k)=diagmat(j,k)+1.
- END IF.
- END LOOP.
- END LOOP.
END LOOP.
* Lower diagonal *.
LOOP i=1 TO ndata.
- LOOP j=1 TO nvars-1.
- LOOP k=j TO nvars.
- DO IF data(i,j) LT data(i,k).
- COMPUTE diagmat(k,j)=diagmat(k,j)+1.
- END IF.
- END LOOP.
- END LOOP.
END LOOP.
* Report *.
PRINT diagmat
/CNAMES=vnames
/RNAMES=vnames.
END MATRIX.

You can also export this matrix to an external SPSS file, if you ant
(tell me if you need that and I'll add the code).

PE>> I have a fairly complex (at least I think it is complex anyway) data
PE>> transformation procedure I am trying to run in SPSS. I have a data set of
PE>> 10 variables where each vector represents the ranking of those concepts by
PE>> one individual. To be specific the data looks like this:

PE>> ID v1 v2 v3 v4 v5 v6
PE>> v7 v8 v9 v10
PE>> 1 2 3 7 8 10
PE>> 4 5 6 9
PE>> 2 10 2 1 3 4
PE>> 6 7 9 8
PE>> 3 9 6 4 2 1
PE>> 5 7 10 8
PE>> .
PE>> .
PE>> .
PE>> 1000 2 4 8 10 9 3 5
PE>> 7 1 6

PE>> What I would like to do is to create some syntax or a macro that will
PE>> change this data into a matrix where everything in columns above the
PE>> diagonal is the number of times each concept was ranked higher than the
PE>> corresponding row concept and everything in columns below the diagonal is
PE>> the number of times each concept was ranked lower than the row concept. The
PE>> diagonals themselves will be equal to N/2 but right now I am more concerned
PE>> with the off diagonals.

PE>> I believe this can be done with the matrix language but in all my years of
PE>> dealing with SPSS I haven't had the "pleasure" of working with any matrix
PE>> commands and the help text is a misnomer in this regard. I'm sure there are
PE>> macros that could do this as well but I haven't found anything on Raynard's
PE>> page or other links that have been very useful as references.

HTH,
Marta mailto:biostatistics@terra.es

--
Saludos,
Marta mailto:biostatistics@terra.es