using vectors and matrixes

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

using vectors and matrixes

Bogdan Voicu

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

 

 

 

Reply | Threaded
Open this post in threaded view
|

Re: using vectors and matrixes

David Marso
Administrator
See the MATRIX language documentation in the manual.
You can very easily implement this.
Bogdan Voicu wrote
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

 <mailto:[hidden email]> [hidden email];  <http://www.bogdanvoicu.ro/>
http://www.bogdanvoicu.ro
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?"
Reply | Threaded
Open this post in threaded view
|

Re: using vectors and matrixes

Spousta Jan
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 Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu.

 


This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

 

P Are you sure that you really need a print version of this message and/or its attachments? Think about nature.

-.- --
Reply | Threaded
Open this post in threaded view
|

Re: using vectors and matrixes

David Marso
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.
-----
Spousta Jan wrote
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]<mailto:[hidden email]>; http://www.bogdanvoicu.ro<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 Jste si jisti, že opravdu potřebujete vytisknout tuto zprávu a/nebo její přílohy? Myslete na přírodu.


This message and any attached files are confidential and intended solely for the addressee(s). Any publication, transmission or other use of the information by a person or entity other than the intended addressee is prohibited. If you receive this in error please contact the sender and delete the message as well as all attached documents. The sender does not accept liability for any errors or omissions as a result of the transmission.

P Are you sure that you really need a print version of this message and/or its attachments? Think about nature.
-.- --
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?"