Naming Matrices Sequentially

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

Naming Matrices Sequentially

bdates

Hi, all. I'm writing syntax to indicate for each item, which response option was chosen for each variable. Each resulting matrix is an n x option matrix. I'm looking for syntax to name each matrix as it's produced by the looping so I can perform more procedures. Any ideas? A sample of the syntax with three variables and 10 items for each is below. This would result in 3 matrices, one for each variable.


data list free / var1 var2 var3 .
begin data
1 1 2
2 2 2
1 2 1
3 3 3
2 4 4
4 3 3
4 4 3
3 3 2
4 4 4
3 4 1
end data.
dataset name test.
formats all (F1.0).
set seed=123456 .
preserve.
set printback=off mprint=off.
define corrtest (vars=!charend('/')/options=!charend('/')) .
set mxloops=100000000.
count ms__=!vars (missing).
select if ms__=0.
matrix.
get x /var=!vars.
compute n=nrow(x) .
compute numberv=ncol(x) .
compute opt=!options .
loop #count=1 to numberv .
compute #rm=x(:,#count) .
compute optitem=make(nrow(x),opt,0).
loop #i=1 to nrow(#rm).
loop #j=1 to ncol(#rm) .
loop #k=1 to opt.
do if #rm(#i,#j)=#k.
compute optitem(#i,#k)=optitem(#i,#k)+1.
end if.
end loop.
end loop.
end loop.
end loop .
end matrix .
!enddefine.
restore.
corrtest vars=var1 to var3/options=4 .


===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Naming Matrices Sequentially

Kirill Orlov
Please comment what you are doing and the results. It is difficult to understand currently how you three matrices (the senior loop) correspond to your data.


===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Naming Matrices Sequentially

bdates

Kiril,


Thanks for the reply. The syntax produces an item by response option matrix (in this case a 10 x 4). The ones in the matrix indicate which option was selected for an item for the particular variable. There will be three matrices, one for each variable. I need to name each matrix as it's produced to be separate from each other matrix. The third matrix that's produced by this syntax is:


.00 1.00 .00 .00
.00 1.00 .00 .00
1.00 .00 .00 .00
.00 .00 1.00 .00
.00 .00 .00 1.00
.00 .00 1.00 .00
.00 .00 1.00 .00
.00 1.00 .00 .00
.00 .00 .00 1.00
1.00 .00 .00 .00


Response options (1 - 4) are the columns. Items are the rows.


Brian



From: Kirill Orlov <[hidden email]>
Sent: Monday, April 9, 2018 1:30:17 PM
To: Dates, Brian; [hidden email]
Subject: Re: Naming Matrices Sequentially
 
Please comment what you are doing and the results. It is difficult to understand currently how you three matrices (the senior loop) correspond to your data.


===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Naming Matrices Sequentially

David Marso
Administrator
In reply to this post by bdates
Brian,
Perhaps the following will be of interest ;-)
Using DESIGN function on augmented vector will bring much joy.
Saving stripped result with added loop index yields desired result.
If you have other stuff to do inside MATRIX you can do a SPLIT FILE on
MatrixNum and use INCLUDE on the additional matrix commands.
HTH, David

data list free / var1 var2 var3 .
begin data
1 1 2
2 2 2
1 2 1
3 3 3
2 4 4
4 3 3
4 4 3
3 3 2
4 4 4
3 4 1
end data.
dataset name test.
formats all (F1.0).
set seed=123456 .
preserve.
set printback=off mprint=off.
define !corrtest (vars=!charend('/')/options=!charend('/')) .
SET MXLOOPS=100000000.
SELECT IF NMISS(!vars) EQ 0.
MATRIX.

GET x /VARIABLES=!vars.
LOOP #count=1 TO ncol(x) .

/*Adding original response categories so as to preserve order */.
COMPUTE optitem=DESIGN({T({1:!options});x(:,#count)}).

/* Saving Design/Indicator Matrix, Raw Vector and Column Counter */.
SAVE ({optitem(!options+1:nrow(x),:),x(:,#count),MAKE(nrow(x),1,#count)})
  /OUTFILE * /VARIABLES=X1 TO !CONCAT(X,!options) rawdata MatrixNum.

END LOOP .
END MATRIX .
!enddefine.
restore.
!corrtest vars=var1 to var3/options=4 .
FORMATS ALL (F1.0).
LIST.
 
 
X1 X2 X3 X4 rawdata MatrixNum
 
 1  0  0  0    1        1
 0  1  0  0    2        1
 1  0  0  0    1        1
 0  0  1  0    3        1
 0  1  0  0    2        1
 0  0  0  1    4        1
 0  0  0  1    4        1
 0  0  1  0    3        1
 0  0  0  1    4        1
 0  0  1  0    3        1
 1  0  0  0    1        2
 0  1  0  0    2        2
 0  1  0  0    2        2
 0  0  1  0    3        2
 0  0  0  1    4        2
 0  0  1  0    3        2
 0  0  0  1    4        2
 0  0  1  0    3        2
 0  0  0  1    4        2
 0  0  0  1    4        2
 0  1  0  0    2        3
 0  1  0  0    2        3
 1  0  0  0    1        3
 0  0  1  0    3        3
 0  0  0  1    4        3
 0  0  1  0    3        3
 0  0  1  0    3        3
 0  1  0  0    2        3
 0  0  0  1    4        3
 1  0  0  0    1        3


bdates wrote

> Hi, all. I'm writing syntax to indicate for each item, which response
> option was chosen for each variable. Each resulting matrix is an n x
> option matrix. I'm looking for syntax to name each matrix as it's produced
> by the looping so I can perform more procedures. Any ideas? A sample of
> the syntax with three variables and 10 items for each is below. This would
> result in 3 matrices, one for each variable.
>
>
> data list free / var1 var2 var3 .
> begin data
> 1 1 2
> 2 2 2
> 1 2 1
> 3 3 3
> 2 4 4
> 4 3 3
> 4 4 3
> 3 3 2
> 4 4 4
> 3 4 1
> end data.
> dataset name test.
> formats all (F1.0).
> set seed=123456 .
> preserve.
> set printback=off mprint=off.
> define corrtest (vars=!charend('/')/options=!charend('/')) .
> set mxloops=100000000.
> count ms__=!vars (missing).
> select if ms__=0.
> matrix.
> get x /var=!vars.
> compute n=nrow(x) .
> compute numberv=ncol(x) .
> compute opt=!options .
> loop #count=1 to numberv .
> compute #rm=x(:,#count) .
> compute optitem=make(nrow(x),opt,0).
> loop #i=1 to nrow(#rm).
> loop #j=1 to ncol(#rm) .
> loop #k=1 to opt.
> do if #rm(#i,#j)=#k.
> compute optitem(#i,#k)=optitem(#i,#k)+1.
> end if.
> end loop.
> end loop.
> end loop.
> end loop .
> end matrix .
> !enddefine.
> restore.
> corrtest vars=var1 to var3/options=4 .
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
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?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
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: Naming Matrices Sequentially

David Marso
Administrator
You could even lose the LOOP by doing a RESHAPE.
Bookkeeping courtesy of Ms KRONEKER ;-)

DEFINE !corrtest2 (vars=!charend('/')/options=!charend('/')) .
PRESERVE.
SET MXLOOPS=100000000.
SELECT IF NMISS(!vars) EQ 0.
MATRIX.
GET data /FILE */VARIABLES !vars.
COMPUTE N_P_NP={NROW(data),NCOL(data),NROW(data)*NCOL(data)}.
COMPUTE res=DESIGN({T({1:!options});RESHAPE(T(data),N_P_NP(3),1)}).
SAVE ({res(!options+1:N_P_NP(3),:),
      KRONEKER(T({1:N_P_NP(2)}),MAKE(N_P_NP(1),1,1)),
      RESHAPE(T(data),N_P_NP(3),1)})
 /OUTFILE * /VARIABLES X1 TO !CONCAT(X,!options) MatrixNum Rawdata.
END MATRIX.
FORMATS ALL (F1.0).
RESTORE.
!ENDDEFINE.
!corrtest2 vars=var1 to var3/options=4 .


David Marso wrote

> Brian,
> Perhaps the following will be of interest ;-)
> Using DESIGN function on augmented vector will bring much joy.
> Saving stripped result with added loop index yields desired result.
> If you have other stuff to do inside MATRIX you can do a SPLIT FILE on
> MatrixNum and use INCLUDE on the additional matrix commands.
> HTH, David
>
> data list free / var1 var2 var3 .
> begin data
> 1 1 2
> 2 2 2
> 1 2 1
> 3 3 3
> 2 4 4
> 4 3 3
> 4 4 3
> 3 3 2
> 4 4 4
> 3 4 1
> end data.
> dataset name test.
> formats all (F1.0).
> set seed=123456 .
> preserve.
> set printback=off mprint=off.
> define !corrtest (vars=!charend('/')/options=!charend('/')) .
> SET MXLOOPS=100000000.
> SELECT IF NMISS(!vars) EQ 0.
> MATRIX.
>
> GET x /VARIABLES=!vars.
> LOOP #count=1 TO ncol(x) .
>
> /*Adding original response categories so as to preserve order */.
> COMPUTE optitem=DESIGN({T({1:!options});x(:,#count)}).
>
> /* Saving Design/Indicator Matrix, Raw Vector and Column Counter */.
> SAVE ({optitem(!options+1:nrow(x),:),x(:,#count),MAKE(nrow(x),1,#count)})
>   /OUTFILE * /VARIABLES=X1 TO !CONCAT(X,!options) rawdata MatrixNum.
>
> END LOOP .
> END MATRIX .
> !enddefine.
> restore.
> !corrtest vars=var1 to var3/options=4 .
> FORMATS ALL (F1.0).
> LIST.
>  
>  
> X1 X2 X3 X4 rawdata MatrixNum
>  
>  1  0  0  0    1        1
>  0  1  0  0    2        1
>  1  0  0  0    1        1
>  0  0  1  0    3        1
>  0  1  0  0    2        1
>  0  0  0  1    4        1
>  0  0  0  1    4        1
>  0  0  1  0    3        1
>  0  0  0  1    4        1
>  0  0  1  0    3        1
>  1  0  0  0    1        2
>  0  1  0  0    2        2
>  0  1  0  0    2        2
>  0  0  1  0    3        2
>  0  0  0  1    4        2
>  0  0  1  0    3        2
>  0  0  0  1    4        2
>  0  0  1  0    3        2
>  0  0  0  1    4        2
>  0  0  0  1    4        2
>  0  1  0  0    2        3
>  0  1  0  0    2        3
>  1  0  0  0    1        3
>  0  0  1  0    3        3
>  0  0  0  1    4        3
>  0  0  1  0    3        3
>  0  0  1  0    3        3
>  0  1  0  0    2        3
>  0  0  0  1    4        3
>  1  0  0  0    1        3
>
>
> bdates wrote
>> Hi, all. I'm writing syntax to indicate for each item, which response
>> option was chosen for each variable. Each resulting matrix is an n x
>> option matrix. I'm looking for syntax to name each matrix as it's
>> produced
>> by the looping so I can perform more procedures. Any ideas? A sample of
>> the syntax with three variables and 10 items for each is below. This
>> would
>> result in 3 matrices, one for each variable.
>>
>>
>> data list free / var1 var2 var3 .
>> begin data
>> 1 1 2
>> 2 2 2
>> 1 2 1
>> 3 3 3
>> 2 4 4
>> 4 3 3
>> 4 4 3
>> 3 3 2
>> 4 4 4
>> 3 4 1
>> end data.
>> dataset name test.
>> formats all (F1.0).
>> set seed=123456 .
>> preserve.
>> set printback=off mprint=off.
>> define corrtest (vars=!charend('/')/options=!charend('/')) .
>> set mxloops=100000000.
>> count ms__=!vars (missing).
>> select if ms__=0.
>> matrix.
>> get x /var=!vars.
>> compute n=nrow(x) .
>> compute numberv=ncol(x) .
>> compute opt=!options .
>> loop #count=1 to numberv .
>> compute #rm=x(:,#count) .
>> compute optitem=make(nrow(x),opt,0).
>> loop #i=1 to nrow(#rm).
>> loop #j=1 to ncol(#rm) .
>> loop #k=1 to opt.
>> do if #rm(#i,#j)=#k.
>> compute optitem(#i,#k)=optitem(#i,#k)+1.
>> end if.
>> end loop.
>> end loop.
>> end loop.
>> end loop .
>> end matrix .
>> !enddefine.
>> restore.
>> corrtest vars=var1 to var3/options=4 .
>>
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (not to SPSSX-L), with no body text except the
>> command. To leave the list, send the command
>> SIGNOFF SPSSX-L
>> For a list of commands to manage subscriptions, send the command
>> INFO REFCARD
>
>
>
>
>
> -----
> 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?"
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
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?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
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: Naming Matrices Sequentially

bdates

Thank-you very much, David! Perfect! I have to spend more time with Ms. Kroneker. I need to learn of her many charms. Take care!


Brian


From: SPSSX(r) Discussion <[hidden email]> on behalf of David Marso <[hidden email]>
Sent: Monday, April 9, 2018 4:02:17 PM
To: [hidden email]
Subject: Re: Naming Matrices Sequentially
 
You could even lose the LOOP by doing a RESHAPE.
Bookkeeping courtesy of Ms KRONEKER ;-)

DEFINE !corrtest2 (vars=!charend('/')/options=!charend('/')) .
PRESERVE.
SET MXLOOPS=100000000.
SELECT IF NMISS(!vars) EQ 0.
MATRIX.
GET data /FILE */VARIABLES !vars.
COMPUTE N_P_NP={NROW(data),NCOL(data),NROW(data)*NCOL(data)}.
COMPUTE res=DESIGN({T({1:!options});RESHAPE(T(data),N_P_NP(3),1)}).
SAVE ({res(!options+1:N_P_NP(3),:),
      KRONEKER(T({1:N_P_NP(2)}),MAKE(N_P_NP(1),1,1)),
      RESHAPE(T(data),N_P_NP(3),1)})
 /OUTFILE * /VARIABLES X1 TO !CONCAT(X,!options) MatrixNum Rawdata.
END MATRIX.
FORMATS ALL (F1.0).
RESTORE.
!ENDDEFINE.
!corrtest2 vars=var1 to var3/options=4 .


David Marso wrote
> Brian,
> Perhaps the following will be of interest ;-)
> Using DESIGN function on augmented vector will bring much joy.
> Saving stripped result with added loop index yields desired result.
> If you have other stuff to do inside MATRIX you can do a SPLIT FILE on
> MatrixNum and use INCLUDE on the additional matrix commands.
> HTH, David
>
> data list free / var1 var2 var3 .
> begin data
> 1 1 2
> 2 2 2
> 1 2 1
> 3 3 3
> 2 4 4
> 4 3 3
> 4 4 3
> 3 3 2
> 4 4 4
> 3 4 1
> end data.
> dataset name test.
> formats all (F1.0).
> set seed=123456 .
> preserve.
> set printback=off mprint=off.
> define !corrtest (vars=!charend('/')/options=!charend('/')) .
> SET MXLOOPS=100000000.
> SELECT IF NMISS(!vars) EQ 0.
> MATRIX.
>
> GET x /VARIABLES=!vars.
> LOOP #count=1 TO ncol(x) .
>
> /*Adding original response categories so as to preserve order */.
> COMPUTE optitem=DESIGN({T({1:!options});x(:,#count)}).
>
> /* Saving Design/Indicator Matrix, Raw Vector and Column Counter */.
> SAVE ({optitem(!options+1:nrow(x),:),x(:,#count),MAKE(nrow(x),1,#count)})
>   /OUTFILE * /VARIABLES=X1 TO !CONCAT(X,!options) rawdata MatrixNum.
>
> END LOOP .
> END MATRIX .
> !enddefine.
> restore.
> !corrtest vars=var1 to var3/options=4 .
> FORMATS ALL (F1.0).
> LIST.


> X1 X2 X3 X4 rawdata MatrixNum

>  1  0  0  0    1        1
>  0  1  0  0    2        1
>  1  0  0  0    1        1
>  0  0  1  0    3        1
>  0  1  0  0    2        1
>  0  0  0  1    4        1
>  0  0  0  1    4        1
>  0  0  1  0    3        1
>  0  0  0  1    4        1
>  0  0  1  0    3        1
>  1  0  0  0    1        2
>  0  1  0  0    2        2
>  0  1  0  0    2        2
>  0  0  1  0    3        2
>  0  0  0  1    4        2
>  0  0  1  0    3        2
>  0  0  0  1    4        2
>  0  0  1  0    3        2
>  0  0  0  1    4        2
>  0  0  0  1    4        2
>  0  1  0  0    2        3
>  0  1  0  0    2        3
>  1  0  0  0    1        3
>  0  0  1  0    3        3
>  0  0  0  1    4        3
>  0  0  1  0    3        3
>  0  0  1  0    3        3
>  0  1  0  0    2        3
>  0  0  0  1    4        3
>  1  0  0  0    1        3
>
>
> bdates wrote
>> Hi, all. I'm writing syntax to indicate for each item, which response
>> option was chosen for each variable. Each resulting matrix is an n x
>> option matrix. I'm looking for syntax to name each matrix as it's
>> produced
>> by the looping so I can perform more procedures. Any ideas? A sample of
>> the syntax with three variables and 10 items for each is below. This
>> would
>> result in 3 matrices, one for each variable.
>>
>>
>> data list free / var1 var2 var3 .
>> begin data
>> 1 1 2
>> 2 2 2
>> 1 2 1
>> 3 3 3
>> 2 4 4
>> 4 3 3
>> 4 4 3
>> 3 3 2
>> 4 4 4
>> 3 4 1
>> end data.
>> dataset name test.
>> formats all (F1.0).
>> set seed=123456 .
>> preserve.
>> set printback=off mprint=off.
>> define corrtest (vars=!charend('/')/options=!charend('/')) .
>> set mxloops=100000000.
>> count ms__=!vars (missing).
>> select if ms__=0.
>> matrix.
>> get x /var=!vars.
>> compute n=nrow(x) .
>> compute numberv=ncol(x) .
>> compute opt=!options .
>> loop #count=1 to numberv .
>> compute #rm=x(:,#count) .
>> compute optitem=make(nrow(x),opt,0).
>> loop #i=1 to nrow(#rm).
>> loop #j=1 to ncol(#rm) .
>> loop #k=1 to opt.
>> do if #rm(#i,#j)=#k.
>> compute optitem(#i,#k)=optitem(#i,#k)+1.
>> end if.
>> end loop.
>> end loop.
>> end loop.
>> end loop .
>> end matrix .
>> !enddefine.
>> restore.
>> corrtest vars=var1 to var3/options=4 .
>>
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (not to SPSSX-L), with no body text except the
>> command. To leave the list, send the command
>> SIGNOFF SPSSX-L
>> For a list of commands to manage subscriptions, send the command
>> INFO REFCARD
>
>
>
>
>
> -----
> 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?"
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
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?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Naming Matrices Sequentially

David Marso
Administrator
KRONEKER(A,B) simply creates a new matrix which is the multiplication of A
with each element of B.

MATRIX.
COMPUTE A={1;2;3}.
COMPUTE B={1;1;1;1}.
COMPUTE AKB=KRONEKER(A,B).
PRINT A.
PRINT B.
PRINT AKB.
END MATRIX.

A
  1
  2
  3
 
B
  1
  1
  1
  1
 
AKB
  1
  1
  1
  1
  2
  2
  2
  2
  3
  3
  3
  3


BUT of course you can go batshit crazy with it and do things like this.

DEFINE !RecursiveCartesianProduct ( !POS !CHAREND ("|" ) /!POS !CMDEND )
!IF (!TAIL(!1) !NE !NULL ) !THEN
!LET !I1 = !HEAD(!1) !LET !I2 = !HEAD(!TAIL (!1))
COMPUTE
!HEAD(!2)={KRONEKER(!I1,MAKE(NROW(!I2),1,1)),KRONEKER(MAKE(NROW(!I1),1,1),!I2)}.      
!RecursiveCartesianProduct !HEAD(!2)  !TAIL(!TAIL(!1)) | !TAIL(!2).
!ELSE
SAVE !HEAD(!2) /OUTFILE =* .
!IFEND
!ENDDEFINE.
SET MPRINT ON PRINTBACK ON.
OUTPUT CLOSE ALL.
MATRIX.
COMPUTE A={1;2;3;4;5;6}.
COMPUTE B={7;8;9}.
COMPUTE C={10;20;30;40}.
COMPUTE D={-1;-2;-3;-4}.
COMPUTE E={1;2;3;4;5;6}.
!RecursiveCartesianProduct A B C D E  | W X Y Z Z.
PRINT NROW(Z).
PRINT Z.
END MATRIX.



bdates wrote
> Thank-you very much, David! Perfect! I have to spend more time with Ms.
> Kroneker. I need to learn of her many charms. Take care!
>
>
> Brian
>
> ________________________________
> From: SPSSX(r) Discussion &lt;

> SPSSX-L@.UGA

> &gt; on behalf of David Marso &lt;

> david.marso@

> &gt;
> Sent: Monday, April 9, 2018 4:02:17 PM
> To:

> SPSSX-L@.UGA

> Subject: Re: Naming Matrices Sequentially
>
> You could even lose the LOOP by doing a RESHAPE.
> Bookkeeping courtesy of Ms KRONEKER ;-)
>
> DEFINE !corrtest2 (vars=!charend('/')/options=!charend('/')) .
> PRESERVE.
> SET MXLOOPS=100000000.
> SELECT IF NMISS(!vars) EQ 0.
> MATRIX.
> GET data /FILE */VARIABLES !vars.
> COMPUTE N_P_NP={NROW(data),NCOL(data),NROW(data)*NCOL(data)}.
> COMPUTE res=DESIGN({T({1:!options});RESHAPE(T(data),N_P_NP(3),1)}).
> SAVE ({res(!options+1:N_P_NP(3),:),
>       KRONEKER(T({1:N_P_NP(2)}),MAKE(N_P_NP(1),1,1)),
>       RESHAPE(T(data),N_P_NP(3),1)})
>  /OUTFILE * /VARIABLES X1 TO !CONCAT(X,!options) MatrixNum Rawdata.
> END MATRIX.
> FORMATS ALL (F1.0).
> RESTORE.
> !ENDDEFINE.
> !corrtest2 vars=var1 to var3/options=4 .
>
>
> David Marso wrote
>> Brian,
>> Perhaps the following will be of interest ;-)
>> Using DESIGN function on augmented vector will bring much joy.
>> Saving stripped result with added loop index yields desired result.
>> If you have other stuff to do inside MATRIX you can do a SPLIT FILE on
>> MatrixNum and use INCLUDE on the additional matrix commands.
>> HTH, David
>>
>> data list free / var1 var2 var3 .
>> begin data
>> 1 1 2
>> 2 2 2
>> 1 2 1
>> 3 3 3
>> 2 4 4
>> 4 3 3
>> 4 4 3
>> 3 3 2
>> 4 4 4
>> 3 4 1
>> end data.
>> dataset name test.
>> formats all (F1.0).
>> set seed=123456 .
>> preserve.
>> set printback=off mprint=off.
>> define !corrtest (vars=!charend('/')/options=!charend('/')) .
>> SET MXLOOPS=100000000.
>> SELECT IF NMISS(!vars) EQ 0.
>> MATRIX.
>>
>> GET x /VARIABLES=!vars.
>> LOOP #count=1 TO ncol(x) .
>>
>> /*Adding original response categories so as to preserve order */.
>> COMPUTE optitem=DESIGN({T({1:!options});x(:,#count)}).
>>
>> /* Saving Design/Indicator Matrix, Raw Vector and Column Counter */.
>> SAVE ({optitem(!options+1:nrow(x),:),x(:,#count),MAKE(nrow(x),1,#count)})
>>   /OUTFILE * /VARIABLES=X1 TO !CONCAT(X,!options) rawdata MatrixNum.
>>
>> END LOOP .
>> END MATRIX .
>> !enddefine.
>> restore.
>> !corrtest vars=var1 to var3/options=4 .
>> FORMATS ALL (F1.0).
>> LIST.
>>
>>
>> X1 X2 X3 X4 rawdata MatrixNum
>>
>>  1  0  0  0    1        1
>>  0  1  0  0    2        1
>>  1  0  0  0    1        1
>>  0  0  1  0    3        1
>>  0  1  0  0    2        1
>>  0  0  0  1    4        1
>>  0  0  0  1    4        1
>>  0  0  1  0    3        1
>>  0  0  0  1    4        1
>>  0  0  1  0    3        1
>>  1  0  0  0    1        2
>>  0  1  0  0    2        2
>>  0  1  0  0    2        2
>>  0  0  1  0    3        2
>>  0  0  0  1    4        2
>>  0  0  1  0    3        2
>>  0  0  0  1    4        2
>>  0  0  1  0    3        2
>>  0  0  0  1    4        2
>>  0  0  0  1    4        2
>>  0  1  0  0    2        3
>>  0  1  0  0    2        3
>>  1  0  0  0    1        3
>>  0  0  1  0    3        3
>>  0  0  0  1    4        3
>>  0  0  1  0    3        3
>>  0  0  1  0    3        3
>>  0  1  0  0    2        3
>>  0  0  0  1    4        3
>>  1  0  0  0    1        3
>>
>>
>> bdates wrote
>>> Hi, all. I'm writing syntax to indicate for each item, which response
>>> option was chosen for each variable. Each resulting matrix is an n x
>>> option matrix. I'm looking for syntax to name each matrix as it's
>>> produced
>>> by the looping so I can perform more procedures. Any ideas? A sample of
>>> the syntax with three variables and 10 items for each is below. This
>>> would
>>> result in 3 matrices, one for each variable.
>>>
>>>
>>> data list free / var1 var2 var3 .
>>> begin data
>>> 1 1 2
>>> 2 2 2
>>> 1 2 1
>>> 3 3 3
>>> 2 4 4
>>> 4 3 3
>>> 4 4 3
>>> 3 3 2
>>> 4 4 4
>>> 3 4 1
>>> end data.
>>> dataset name test.
>>> formats all (F1.0).
>>> set seed=123456 .
>>> preserve.
>>> set printback=off mprint=off.
>>> define corrtest (vars=!charend('/')/options=!charend('/')) .
>>> set mxloops=100000000.
>>> count ms__=!vars (missing).
>>> select if ms__=0.
>>> matrix.
>>> get x /var=!vars.
>>> compute n=nrow(x) .
>>> compute numberv=ncol(x) .
>>> compute opt=!options .
>>> loop #count=1 to numberv .
>>> compute #rm=x(:,#count) .
>>> compute optitem=make(nrow(x),opt,0).
>>> loop #i=1 to nrow(#rm).
>>> loop #j=1 to ncol(#rm) .
>>> loop #k=1 to opt.
>>> do if #rm(#i,#j)=#k.
>>> compute optitem(#i,#k)=optitem(#i,#k)+1.
>>> end if.
>>> end loop.
>>> end loop.
>>> end loop.
>>> end loop .
>>> end matrix .
>>> !enddefine.
>>> restore.
>>> corrtest vars=var1 to var3/options=4 .
>>>
>>>
>>> =====================
>>> To manage your subscription to SPSSX-L, send a message to
>>
>>> LISTSERV@.UGA
>>
>>>  (not to SPSSX-L), with no body text except the
>>> command. To leave the list, send the command
>>> SIGNOFF SPSSX-L
>>> For a list of commands to manage subscriptions, send the command
>>> INFO REFCARD
>>
>>
>>
>>
>>
>> -----
>> 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?"
>> --
>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (not to SPSSX-L), with no body text except the
>> command. To leave the list, send the command
>> SIGNOFF SPSSX-L
>> For a list of commands to manage subscriptions, send the command
>> INFO REFCARD
>
>
>
>
>
> -----
> 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?"
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD





-----
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?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
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: Naming Matrices Sequentially

PRogman
IIRC Ms Kroneker's first name was Leopold...  

David Marso wrote
> KRONEKER(A,B) simply creates a new matrix which is the multiplication of A
> with each element of B.
> ...
>> Thank-you very much, David! Perfect! I have to spend more time with Ms.
>> Kroneker. I need to learn of her many charms. Take care!
>>
> ...





--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD