Skip to Main Content

Reading Matrix Data into SPSS | SPSS Code Fragments

Sometimes you want to be able to read matrix data (e.g., correlations)
directly into SPSS for analysis.  For example, perhaps you have ordinal
data and used the Stata polychoric command to get polychoric correlations
and then want to do a factor analysis (see
our FAQ on using polychoric
  for more info on that command.). First, in
Stata we get the polychoric correlation matrix.

use https://stats.idre.ucla.edu/stat/stata/notes/hsb2
(highschool and beyond (200 cases))

search polychoric 
(download the program)

polychoric female race ses schtyp

Polychoric correlation matrix

            female        race         ses      schtyp
female           1
  race  -.02425329           1
   ses  -.17389495   .30832494           1
schtyp   .02920402   .24444337   .23757881           1

Now, we can use this as input into SPSS like this.

MATRIX DATA VARIABLES=ROWTYPE_ female race ses schtyp.
BEGIN DATA
N 200 200 200 200
CORR           1
CORR  -.02425329           1
CORR  -.17389495   .30832494           1
CORR   .02920402   .24444337   .23757881           1
END DATA.

Now we can analyze this file using a procedure that understands matrix input,
for example we can do a factor analysis on it like this.

factor /matrix=in(cor=*).