How to create a simple crosstab (or CTABLE) loop

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

How to create a simple crosstab (or CTABLE) loop

Gareth Edwards-7

Seemingly simple question that I can’t solve

 

Let’s say I have two sets of 100 variables that are labeled from 1 to 100 (X1, X2, … X99, X100) and an associated set of variables (Y1, Y2, .. Y99, Y100)

 

I want to create a loop to run crosstabs between matching pairs.  So (X1 and Y1) and (X2 and Y2).  This would generate 100 crosstabs, (as opposed to 1000 if I crosstabbed each variable with every other one).

 

I’ve been looking into creating something with the LOOP command in syntax, but nothing seems to work.  I can’t use python to generate the syntax (at least yet) because I need a patch for SPSS 15.0.0 -> 15.0.1 (or alternatively a patch for 17.0.0 -> 17.0.1)

 

What’s the best way to do this?  Or is there anywhere to get these patches?  The SPSS website says no patches are available for anything under SPSS 18 due to the recent acquisition. 

 

Gareth Edwards
Research Associate | Member Research & Technology
1155 16th St., NW | Washington | DC 20036
T 202-872-4433 | F 202-872-6337
www.acs.org
––––––––––––––––––––
ACS Chemistry for Life

 

Reply | Threaded
Open this post in threaded view
|

Re: How to create a simple crosstab (or CTABLE) loop

Bruce Weaver
Administrator
You could use a macro.  E.g.,

* Define the macro.
define !mycross (first = !tokens(1) / last = !tokens(1))
!do !i = !first !to !last
!let !x = !concat("x",!i)
!let !y = !concat("y",!i)
crosstabs !x by !y .
!doend
!enddefine.

* Call the macro.
!mycross first=1 last=100.



Gareth Edwards-7 wrote
Seemingly simple question that I can't solve

 

Let's say I have two sets of 100 variables that are labeled from 1 to
100 (X1, X2, ... X99, X100) and an associated set of variables (Y1, Y2,
.. Y99, Y100)

 

I want to create a loop to run crosstabs between matching pairs.  So (X1
and Y1) and (X2 and Y2).  This would generate 100 crosstabs, (as opposed
to 1000 if I crosstabbed each variable with every other one).

 

I've been looking into creating something with the LOOP command in
syntax, but nothing seems to work.  I can't use python to generate the
syntax (at least yet) because I need a patch for SPSS 15.0.0 -> 15.0.1
(or alternatively a patch for 17.0.0 -> 17.0.1)

 

What's the best way to do this?  Or is there anywhere to get these
patches?  The SPSS website says no patches are available for anything
under SPSS 18 due to the recent acquisition.  

 

Gareth Edwards
Research Associate | Member Research & Technology
1155 16th St., NW | Washington | DC 20036
T 202-872-4433 | F 202-872-6337
www.acs.org <http://www.acs.org/
--------------------
ACS Chemistry for Life

 
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: How to create a simple crosstab (or CTABLE) loop

John F Hall
In reply to this post by Gareth Edwards-7
Not sure if you can do crosstabs like this in SPSS, but something like:
 
do repeat
     x = x1 to x100
     y = y1 to y100
cros x by y.
end repeat.
 
Bit late and off to bed, but full stops needed somewhere in there. 
Check the Syntax Guide for    
do repeat
----- Original Message -----
Sent: Tuesday, June 29, 2010 10:37 PM
Subject: How to create a simple crosstab (or CTABLE) loop

Seemingly simple question that I can’t solve

 

Let’s say I have two sets of 100 variables that are labeled from 1 to 100 (X1, X2, … X99, X100) and an associated set of variables (Y1, Y2, .. Y99, Y100)

 

I want to create a loop to run crosstabs between matching pairs.  So (X1 and Y1) and (X2 and Y2).  This would generate 100 crosstabs, (as opposed to 1000 if I crosstabbed each variable with every other one).

 

I’ve been looking into creating something with the LOOP command in syntax, but nothing seems to work.  I can’t use python to generate the syntax (at least yet) because I need a patch for SPSS 15.0.0 -> 15.0.1 (or alternatively a patch for 17.0.0 -> 17.0.1)

 

What’s the best way to do this?  Or is there anywhere to get these patches?  The SPSS website says no patches are available for anything under SPSS 18 due to the recent acquisition. 

 

Gareth Edwards
Research Associate | Member Research & Technology
1155 16th St., NW | Washington | DC 20036
T 202-872-4433 | F 202-872-6337
www.acs.org
––––––––––––––––––––
ACS Chemistry for Life

 

Reply | Threaded
Open this post in threaded view
|

Re: How to create a simple crosstab (or CTABLE) loop

Gareth Edwards-7
In reply to this post by Bruce Weaver
This worked great.  Do you have a good resource for reintroducing myself
to macros?  I can parse that code in my head, but I worry I'd like to
practice making more creative (read: complicated) versions in future.

I'm going to hash out a Python solution to this as well if I can.

Gareth Edwards
Research Associate | Member Research & Technology
1155 16th St., NW | Washington | DC 20036
T 202-872-4433 | F 202-872-6337
www.acs.org
--------------------
ACS Chemistry for Life

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Tuesday, June 29, 2010 4:53 PM
To: [hidden email]
Subject: Re: How to create a simple crosstab (or CTABLE) loop

You could use a macro.  E.g.,

* Define the macro.
define !mycross (first = !tokens(1) / last = !tokens(1))
!do !i = !first !to !last
!let !x = !concat("x",!i)
!let !y = !concat("y",!i)
crosstabs !x by !y .
!doend
!enddefine.

* Call the macro.
!mycross first=1 last=100.




Gareth Edwards-7 wrote:
>
> Seemingly simple question that I can't solve
>
>
>
> Let's say I have two sets of 100 variables that are labeled from 1 to
> 100 (X1, X2, ... X99, X100) and an associated set of variables (Y1,
Y2,
> .. Y99, Y100)
>
>
>
> I want to create a loop to run crosstabs between matching pairs.  So
(X1
> and Y1) and (X2 and Y2).  This would generate 100 crosstabs, (as
opposed

> to 1000 if I crosstabbed each variable with every other one).
>
>
>
> I've been looking into creating something with the LOOP command in
> syntax, but nothing seems to work.  I can't use python to generate the
> syntax (at least yet) because I need a patch for SPSS 15.0.0 -> 15.0.1
> (or alternatively a patch for 17.0.0 -> 17.0.1)
>
>
>
> What's the best way to do this?  Or is there anywhere to get these
> patches?  The SPSS website says no patches are available for anything
> under SPSS 18 due to the recent acquisition.
>
>
>
> Gareth Edwards
> Research Associate | Member Research & Technology
> 1155 16th St., NW | Washington | DC 20036
> T 202-872-4433 | F 202-872-6337
> www.acs.org <http://www.acs.org/>
> --------------------
> ACS Chemistry for Life
>
>
>
>
>


-----
--
Bruce Weaver
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."

NOTE:  My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
--
View this message in context:
http://old.nabble.com/How-to-create-a-simple-crosstab-%28or-CTABLE%29-lo
op-tp29028075p29028218.html
Sent from the SPSSX Discussion mailing list archive at 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: How to create a simple crosstab (or CTABLE) loop

Bruce Weaver
Administrator
I would suggest looking at examples in the archives for this list, for the SPSS usenet group (http://groups.google.com/group/comp.soft-sys.stat.spss/topics), and from Raynald's website (http://www.spsstools.net/).  There's also the book by Eric Einspruch, "Next Steps with SPSS".  You can preview on Google Books (mind the line-wrap):

http://books.google.ca/books?id=xj03clTXInwC&printsec=frontcover&dq=SPSS+Eric+Einspruch&source=bl&ots=ybiGHnjTTX&sig=vm4fIzB_KVsoqPzImOxpZ1FMooQ&hl=en&ei=_3kqTMvoDIyhnQfll_DWDg&sa=X&oi=book_result&ct=result&resnum=5&ved=0CCQQ6AEwBA#v=onepage&q&f=false



Gareth Edwards-7 wrote
This worked great.  Do you have a good resource for reintroducing myself
to macros?  I can parse that code in my head, but I worry I'd like to
practice making more creative (read: complicated) versions in future.

I'm going to hash out a Python solution to this as well if I can.

Gareth Edwards
Research Associate | Member Research & Technology
1155 16th St., NW | Washington | DC 20036
T 202-872-4433 | F 202-872-6337
www.acs.org
--------------------
ACS Chemistry for Life

-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@listserv.uga.edu] On Behalf Of
Bruce Weaver
Sent: Tuesday, June 29, 2010 4:53 PM
To: SPSSX-L@listserv.uga.edu
Subject: Re: How to create a simple crosstab (or CTABLE) loop

You could use a macro.  E.g.,

* Define the macro.
define !mycross (first = !tokens(1) / last = !tokens(1))
!do !i = !first !to !last
!let !x = !concat("x",!i)
!let !y = !concat("y",!i)
crosstabs !x by !y .
!doend
!enddefine.

* Call the macro.
!mycross first=1 last=100.




Gareth Edwards-7 wrote:
>
> Seemingly simple question that I can't solve
>
>
>
> Let's say I have two sets of 100 variables that are labeled from 1 to
> 100 (X1, X2, ... X99, X100) and an associated set of variables (Y1,
Y2,
> .. Y99, Y100)
>
>
>
> I want to create a loop to run crosstabs between matching pairs.  So
(X1
> and Y1) and (X2 and Y2).  This would generate 100 crosstabs, (as
opposed
> to 1000 if I crosstabbed each variable with every other one).
>
>
>
> I've been looking into creating something with the LOOP command in
> syntax, but nothing seems to work.  I can't use python to generate the
> syntax (at least yet) because I need a patch for SPSS 15.0.0 -> 15.0.1
> (or alternatively a patch for 17.0.0 -> 17.0.1)
>
>
>
> What's the best way to do this?  Or is there anywhere to get these
> patches?  The SPSS website says no patches are available for anything
> under SPSS 18 due to the recent acquisition.
>
>
>
> Gareth Edwards
> Research Associate | Member Research & Technology
> 1155 16th St., NW | Washington | DC 20036
> T 202-872-4433 | F 202-872-6337
> www.acs.org <http://www.acs.org/>
> --------------------
> ACS Chemistry for Life
>
>
>
>
>


-----
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/
"When all else fails, RTFM."

NOTE:  My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
--
View this message in context:
http://old.nabble.com/How-to-create-a-simple-crosstab-%28or-CTABLE%29-lo
op-tp29028075p29028218.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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@LISTSERV.UGA.EDU (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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).