UCLA Academic Technology Services HomeServicesClassesContactJobs
Help the Stat Consulting Group by giving a gift             
Loading

SPSS Code Fragment
Reading Matrix Data into SPSS

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 http://www.ats.ucla.edu/stat/stata/notes/hsb2
(highschool and beyond (200 cases))

findit 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=*).

How to cite this page

Report an error on this page or leave a comment

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California