Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using a loop to do a series of crosstabs

873 views
Skip to first unread message

Betsey Stevenson

unread,
Mar 27, 2002, 10:08:41 PM3/27/02
to
I want to do something relatively simple -- run several crosstabs of
variables that are in a row. I tried to use the following loop but it
didn't work
***********
loop #i=1 to 28.
CROSSTABS
/TABLES=aq71d@(#i) BY aq71c@(#i)
/FORMAT= AVALUE TABLES
/CELLS= COUNT .
end loop.
execute.
***********

The variables are names aq71d@1 to aq71d@28 and aq71c@1 to aq71c@28
(where the last number changes from 1 to 28 for new variables).

Any ideas why my loop didn't work?

Thanks,
Betsey

Michael Lacy

unread,
Mar 27, 2002, 10:53:45 PM3/27/02
to
Betsey Stevenson <bstev...@forrester.com> wrote:
> I want to do something relatively simple -- run several crosstabs of
> variables that are in a row. I tried to use the following loop but it
> didn't work
> ***********
> loop #i=1 to 28.
> CROSSTABS
> /TABLES=aq71d@(#i) BY aq71c@(#i)
> /FORMAT= AVALUE TABLES
> /CELLS= COUNT .
> end loop.
> execute.
> ***********


Your loop didn't work because SPSS only allows transformation commands,
such as COMPUTE, within loops. Procedures such as CROSSTABS
are not permitted. However, it appears that you should be able
to accomomplish what you want by using a list of variables
on your crosstabs command:

crosstabs aq71d@1 to aq71d@28 by aq71c@1 to aq71c@1 .

This will generate all pairs of tables across the two variable
lists. See the documentation on crosstabs, which will indicate
that a 'varlist' may appear on one or both sides of the BY.

Regards,

=-=-=-=-=-=-=-=-=-==-=-=-=
Mike Lacy, Ft Collins CO 80523
voice (970) 491-6721

Rich Ulrich

unread,
Mar 28, 2002, 10:39:32 AM3/28/02
to
To Mike Lacy and SPSS users,

On 27 Mar 2002 20:53:45 -0700, Michael Lacy
<mgl...@lamar.ColoState.EDU> wrote:

[ del problem]


>
> Your loop didn't work because SPSS only allows transformation commands,
> such as COMPUTE, within loops. Procedures such as CROSSTABS
> are not permitted. However, it appears that you should be able
> to accomomplish what you want by using a list of variables
> on your crosstabs command:
>
> crosstabs aq71d@1 to aq71d@28 by aq71c@1 to aq71c@1 .

[ typographical error? - intended, aq71c@1 to aq71c@28 ? ]


>
> This will generate all pairs of tables across the two variable
> lists. See the documentation on crosstabs, which will indicate
> that a 'varlist' may appear on one or both sides of the BY.
>
> Regards,

But 'all pairs' is going to be 28x28 tables, and not the
obvious 28 on the diagonal. Which I believe was intended.

Occasionally I have wanted to have this choice like the one
that does exactly that, for paired t-tests, "(paired)"; but I don't
know of any shortcut like that in Crosstabs.

--
Rich Ulrich, wpi...@pitt.edu
http://www.pitt.edu/~wpilib/index.html

Michael Lacy

unread,
Mar 28, 2002, 11:16:26 AM3/28/02
to
In reference to my response to a question about trying to use LOOP
to control the generation of a list of crosstabs tables,
Rich Ulrich <wpi...@pitt.edu> wrote:

>>
>>
> But 'all pairs' is going to be 28x28 tables, and not the
> obvious 28 on the diagonal. Which I believe was intended.


Rich, of course, is absolutely right; my apologies for my offhand
incorrect suggestion. At the risk of getting in deeper, I would
venture a guess that this problem could be solved with a macro,
but I'm not enough of a macro user to know.

Regards,

--

Neila Nessa

unread,
Mar 28, 2002, 4:56:00 PM3/28/02
to
Betsey,
You will need to investigate the SPSS Macro facility.
DEFINE ...!DO.. !CONCAT ...!BLAHBLAHBLAH... !DOEND...!ENDDEFINE
Why??? Loop... End Loop only supports data transformations. XTABS is a procedure.
HTH, Neila
BTW, Hope you never need to go beyond 99.

bstev...@forrester.com (Betsey Stevenson) wrote in message news:<8091e8b2.02032...@posting.google.com>...


> I want to do something relatively simple -- run several crosstabs of
> variables that are in a row. I tried to use the following loop but it
> didn't work

Call the below aircode as MYXTAB 28 .

**AIRCODE ALERT**!!

DEFINE MYXTAB (N !TOKENS (1) )

*loop #i=1 to 28.
!DO !INDEX=1 !TO !N
> CROSSTABS
> /TABLES= !CONCAT("aq71d@",!INDEX) BY !CONCAT("aq71c@",!INDEX)


> /FORMAT= AVALUE TABLES
> /CELLS= COUNT .
> end loop.

!DOEND
!ENDDEFINE
** DONT NEED EXECUTE!;-)

0 new messages