```Date: Wed, 25 May 2011 22:57:47 -0400 Reply-To: Rich Ulrich Sender: "SPSSX(r) Discussion" From: Rich Ulrich Subject: Re: using vectors and matrixes Comments: To: bogdanicus@gmail.com In-Reply-To: <007701cc1ae0\$b25408f0\$16fc1ad0\$@com> Content-Type: multipart/alternative; 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 RECODE zR011HF to zr019HF(else=0); to initialize. -- Rich Ulrich Date: Wed, 25 May 2011 16:36:03 +0300 From: bogdanicus@GMAIL.COM Subject: using vectors and matrixes To: SPSSX-L@LISTSERV.UGA.EDU 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 040 15 5 15 11 9 5 0 050 7 5 15 10 8 5 0 030 10 10 20 15 10 5 0 010 20 10 20 30 5 5 0 05 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. [text/html] ```

Back to: Top of message | Previous page | Main SPSSX-L page