Dear all, I have a repetitive task, which requires computing several weighted means for each case in a data base. More exactly, for each case there are 9 variables (zR011HF to zr019HF), that I need to sum up weighted with different weights, depending on the values (ranging from 1 to 6) of another variable (idd6bis). The operation repeats with several other sets of variable and I expect that I will need to change several times the weights, when simulating the final model. My idea was to build a series of commands like this one: vector prim=zR011HF to zr019HF. vector weights= 65 5 5 10 6 5 4 0 0 40 15 5 15 11 9 5 0 0 50 7 5 15 10 8 5 0 0 30 10 10 20 15 10 5 0 0 10 20 10 20 30 5 5 0 0 5 5 5 15 10 5 5 25 25. loop #i=1 to 6. loop #j=1 to 9. compute k=#j+(#i-1)*#j. if idd6bis=#i zR01HF=sum(zR01HF, weights(k)*prim(#j)). end loop. end loop. exe. del var k. The above solution does not work. I cannot use the vector command for the weights. My question is which command should I use to declare the weights as a matrix/vector, using the syntax file. Thank you in advance! Bogdan Bogdan Voicu Principal research fellow, Romanian Academy of Science, Research Institute for Quality of Life Associate professor, Department of Sociology, Lucian Blaga University of Sibiu [hidden email]; http://www.bogdanvoicu.ro |
Administrator
|
See the MATRIX language documentation in the manual.
You can very easily implement this.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
In reply to this post by Bogdan Voicu
Hi Bogdan, first create the variables weights (e.g. paste the values from Excel and name them w1 to w9) and then you can define vector weights = w1 to w9
and use it in a loop.
Jan
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bogdan Voicu Sent: Wednesday, May 25, 2011 3:37 PM To: [hidden email] Subject: using vectors and matrixes Dear all, I have a repetitive task, which requires computing several weighted means for each case in a data base. More exactly, for each case there are 9 variables (zR011HF to zr019HF), that I need to sum up weighted with different weights, depending on the values (ranging from 1 to 6) of another variable (idd6bis). The operation repeats with several other sets of variable and I expect that I will need to change several times the weights, when simulating the final model. My idea was to build a series of commands like this one: vector prim=zR011HF to zr019HF. vector weights= 65 5 5 10 6 5 4 0 0 40 15 5 15 11 9 5 0 0 50 7 5 15 10 8 5 0 0 30 10 10 20 15 10 5 0 0 10 20 10 20 30 5 5 0 0 5 5 5 15 10 5 5 25 25. loop #i=1 to 6. loop #j=1 to 9. compute k=#j+(#i-1)*#j. if idd6bis=#i zR01HF=sum(zR01HF, weights(k)*prim(#j)). end loop. end loop. exe. del var k. The above solution does not work. I cannot use the vector command for the weights. My question is which command should I use to declare the weights as a matrix/vector, using the syntax file. Thank you in advance! Bogdan Bogdan Voicu Principal research fellow, Romanian Academy of Science, Research Institute for Quality of Life
Associate professor, Department of Sociology, Lucian Blaga University of Sibiu [hidden email];
http://www.bogdanvoicu.ro _____________ Tato zpráva a všechny připojené soubory
jsou důvěrné a určené výlučně adresátovi(-ům). Jestliže nejste oprávněným adresátem, je zakázáno jakékoliv zveřejňování, zprostředkování nebo jiné použití těchto informací. Jestliže jste tento mail dostali neoprávněně, prosím, uvědomte odesilatele a smažte
zprávu i přiložené soubory. Odesilatel nezodpovídá za jakékoliv chyby nebo opomenutí způsobené tímto přenosem.
P
Are you sure that you really need a print version of this message and/or its attachments? Think about nature.
|
Administrator
|
MATRIX is a much more concise and general way to do such a task.
Obviously not tested, but general idea as follows. Computational goal is REALLY a simple matrix multiplication. MATRIX. GET RAW /VARIABLES= zR011HF to zr019HF / FILE=*. COMPUTE WTS={65, 5, 5, 10, 6, 5,4, 0, 0; 40, 15 , 5............; ............ 10 , 5, 5, 25 ,25}. COMPUTE TW=T(WTS). COMPUTE WTSCALE=RAW*TW. SAVE .... RTFM for exact syntax. END MATRIX. THE WTS matrix can also be read from a system file. -----
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me. --- "Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis." Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?" |
Free forum by Nabble | Edit this page |