Dear all, I have a repetitive task, which requires to compute 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 |
Maybe the Matrix solution can work, though I don't see how it takes into account the test in the example on idd6bis. I could be uninformed, but I don't know a compact way to initialize the values of Vector in SPSS except to a single value ("0", usually), where Recode works. I think it takes separate Computes. So here are some comments, first, on how to get around that limitation. For your problem, where you also want to have a program that you can read, I think I would have a Compute which sets up a text-array with the weights, using 54F3 for the systematic spacing. Then, I would use the internal, formatted Read (Decode?) to create 54 variables which are read into the vector of #Weight. -- If you start the name with "#", then the values are preserved from record to record, so you can use a "#-name", and make the program more efficient by using DO IF $CASE=1 so that the reading only gets done once. That is how I would import the values. There are a couple of other weaknesses with the proposed code. - The outer loop on #i is not needed - Instead of using the Loop/ IF combination, you will get *exactly* the same result by using +COMPUTE #i = idd6bis ; to set the value of #i. - You can use the SUM( ) function as you do, but I would initialize to make *sure* that zR01HF is zero. And that the code shows it. What you want, after vector prim=zR011HF to zr019HF. is -- Rich Ulrich Date: Wed, 25 May 2011 16:36:03 +0300 From: [hidden email] Subject: using vectors and matrixes To: [hidden email] Dear all,
I have a repetitive task, which requires to compute 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.
|
Administrator
|
"I could be uninformed, but I don't know a compact way to initialize the values of Vector
in SPSS except to a single value ("0", usually), where Recode works." Something like the following untested... VECTOR #V(54). DO IF $CASENUM=1. DO REPEAT Index=1 TO 54 / WTS=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. COMPUTE #V(Index)=WTS . END REPEAT . END IF. ..........
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 |