Dear List,
I'm trying to get the lower rectangular of a correlation matrix - just the plain correlations, without probability, sample size etc. I need it for another statistics package. It should look like this: v1 v2 v3 v4 v5 .34 . . . . .35 .56 . . . .55 .23 .44 . . .12 .84 .33 .85 . .33 .45 .65 .56 .30 Thank you! Philippe |
In an off-list message, I asked Kevin for clarification. He replied
>> I have a .txt file that has no delimiters, so I have to code variable names for specific spaces. ie, claim number 1-10 client name 11-25 (a) etc... >> The file I want to match to has the same variable name and format ie. Client number. So, I want to identify specific Client numbers and extract the entire row of data to a separate file. >> The remaining data is to be exported as a .txt file without my variable names or back to the original state. OK, there are some easy parts and some hard parts to doing this. Your data list statement will look something like. Datalist file='<file name string>'/records=?? / claimnumber 1-10 .... You'll need to fill in the details as to file name, number of records, and variable names and locations. Then, Match files file=*/file='<file name string of other file>'/by clientnumber. I'll assume that both files are sorted by clientnumber. If not, they will have to be for the Match files to work. Now, I'm unsure about the next part. You say: So, I want to identify specific Client numbers and extract the entire row of data to a separate file. Since client numbers is plural, I guessing that you have multiple clientnumbers to pick out rather than just one as I originally thought. I don't know whether you want a) to save each clientnumber record to its own file or b) to save all of the picked out cases to their own file. Multiple files or a single file, this determines things. If a single file, I'd recode the client numbers to be picked out to a new variable and select on that variable and then save the resulting file, which, I guessing is a spss data file rather than a text file. Like this. Recode clinetnumber(123 145 456 345=1)(else=0) into pick. Do if (pick eq 1). + xsave outfile='<output file name string>'. End if. If multiple files. It would be (far) more efficient to use a macro for this. However, I never use macros and can't offer help. Others on the list can. Here is the clunky setup. Do if (clinetnumber eq 123). + xsave outfile='<output file name1 string>'. else if (clinetnumber eq 256). + xsave outfile='<output file name2 string>'. .... etc End if. However, you are limited to a maximum of 10 files in the do if block. If more than 10 files, insert an execute statement following the end if and make additional do if blocks. Then you say: The remaining data is to be exported as a .txt file without my variable names or back to the original state. I don't know whether you want to delete the picked out records or not. If not, then no export is needed. The input data file will unchanged at the completion of the job. If you do want to delete the picked out records, then the easiest way is to select out those records en masse and then write out the remaining records to a new text file. Like this. If the variable 'pick' is defined as above. If not, define it as above. Select if (pick eq 0). Having used pick to select records, you now need to get rid of it for the upcoming write command to give you the same variable list as came in. I have seen this used; I have not used it. If I have this wrong, would somebody correct me please. Match files file=*/drop=pick. Write outfile='<new text file name string>' / all. This writes a text output data file with one record per case using the existing formats, which are most likely the ones defined in your datalist statement. The formats can be changed using a Format statement or defined in the Write statements. See the documentation. If you have 14, there may be shortcuts offered by the new features, notably the Dataset related commands. However, I just got 14 and have not used them. Others can comment. Gene Maguin |
In reply to this post by Philippe Rast
Phillipe,
I find it surprising that whatever program the correlation matrix is going into can not read a rectangular matrix. I would expect a program to have that level of flexibility. Anyway. The syntax needed to get the rectangle matrix out to a file is this. Correlation x1 to x30/matrix=out(*). Select if (rowtype_ eq 'CORR'). Write outfile='file name string'. Based on things Marta has posted, I think that you could use the read matrix command set to read the output correlation matrix that exists in the program workspace following the select statement and using the loop commmand you could mark elements in the upper triangle to sysmis. However, I have not done this and can not offer specific help. Gene Maguin |
Hi Phillipe
GM> Based on things Marta has posted, I think that you could use the read matrix GM> command set to read the output correlation matrix that exists in the program GM> workspace following the select statement and using the loop commmand you GM> could mark elements in the upper triangle to sysmis. However, I have not GM> done this and can not offer specific help. Something like this might be a starting point: INPUT PROGRAM. - VECTOR x(20). - LOOP #I = 1 TO 100. - LOOP #J = 1 TO 20. - COMPUTE x(#J) = NORMAL(1). - END LOOP. - END CASE. - END LOOP. - END FILE. END INPUT PROGRAM. CORRELATIONS /VARIABLES=x1 TO x20 /PRINT=TWOTAIL SIG /MATRIX=OUT('C:\Temp\CorrelationMatrix.sav') /MISSING=LISTWISE . MATRIX. MGET /FILE='C:\Temp\CorrelationMatrix.sav'. RELEASE MN,SD,NC. WRITE CR /OUTFILE='C:\Temp\LowerTriangularMatrix.txt' /FIELD=1 TO 160 /MODE=TRIANGULAR /FORMAT='F8.3'. END MATRIX. Comments (some details are obscure, even for me, I had to do a lot of T&E - Trial and Error - until it worked): - This method will export the correlation matrix to a text file. I hope your "another statistical package" can read it. - As I understand it, the /FIELD subcommand indicates the actual width of the file text. Since this example uses 20 variables with a 'F8' FORMAT, the number of columns needed is 20*8= 160 (I'm not really sure if the logic is correct, but selecting a smaller figure for the /FIELD caused a narrow text file with carriage returns in the middle of a row, I started fiddling with the figure until the output text file looked OK, I'd be very glad if someone explained to me the real function of that subcommand...). HTH -- Regards, Dr. Marta García-Granero,PhD mailto:[hidden email] Statistician --- "It is unwise to use a statistical procedure whose use one does not understand. SPSS syntax guide cannot supply this knowledge, and it is certainly no substitute for the basic understanding of statistics and statistical thinking that is essential for the wise choice of methods and the correct interpretation of their results". (Adapted from WinPepi manual - I'm sure Joe Abrahmson will not mind) |
Free forum by Nabble | Edit this page |