DEFINE CovMat ( Vars !CharEnd ('/') /OutFile !CMDEnd). /* -------------------------------------------------------------- */ /* --- MACRO to export covariance matrix of variables 1..p --- */ /* -------------------------------------------------------------- */ /* To use this macro the list of variables must be specified */ /* together with the (path and) name of the covariance matrix to */ /* be written. */ /* A lower triangular matrix of variances and covariances of the */ /* variables will be written to the text-file specified, based on */ /* listwise deletion of missing cases. */ /* Example: */ /* You want to write out the covariance matrix of the variables */ /* x1, x2, x25, x49 into file C:/STATIST/TEST.COV. The respective */ /* macro-procedure CovMat is called by: */ /* */ /* CovMat Vars = x1,x2,x25,x49 */ /* /OutFile = 'c:\statist\test.cov'. */ matrix. get X /file = * /variables = !vars /missing = omit. compute D = X-(Make(NRow(X),1,1)*(CSum(X)/NRow(X))). compute COV = SSCP(D)/(NRow(X)-1). compute s_2_mean = (msum(diag(cov)))/ncol(cov). print NRow(X) /title"N(Cases):" /FORMAT = "F10.0". print NCol(X) /title"P(Variables):" /FORMAT = "F10.0". print t(diag(cov)) /title"Variances:" /FORMAT = "F7.3". print CMin(diag(cov)) /Title"Min variance:" /Format= "F9.5". print CMax(diag(cov)) /Title"Max variance:" /FORMAT = "F9.5". print s_2_mean /title"Mean variance:" /FORMAT = "F9.5". print det(cov) /title"Determinant(cov):" /Format = "F14.10". WRITE cov /OUTFILE = !outfile /FIELD = 1 TO 80 /MODE = TRIANGULAR. END MATRIX. !EndDefine. /* --------------------------------------------------------- */. /* The macro is called by: */. /* */. /* CovMat VARS = variables */. /* /OUTFILE = 'filename'. */. /* --------------------------------------------------------- */.