Help with Loop - a bit more info

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

Help with Loop - a bit more info

Michael Kruger
Below is my earlier question to the list. After playing around with the
data I see that I need to increment two values in my command syntax to
run the procedure.
I have frequency data in two rows ('select if row_no EQ 1 OR row_no EQ
477 to start with). The row 1 has the control frequencies and row 477
the treatment frequencies. I am running my statistical procedure on
these two rows and then need to increment my syntax statemtn to read
'row 2 OR row 478', then run the analysis; and so on until I end with
'select if row_no eq  476 aOR row_no eq 952'.

I have over 500 rows of frequency data for multiple variables that I
need to run the same statistical procedure on ( a log-linear analysis if
that's relevant).
I am using the id variable CASE as my counter (1 to 500+). I tried the
following code to test out the loop but cannot get it to run:

INPUT PROGRAM.
LOOP #I = 1 TO 500.
  Do Repeat TOTAL = Case.
   Compute Total=Case+1.
  End Repeat.
END LOOP.
END FILE.
END INPUT PROGRAM.

TOTAL is the counting variable that I want to stop at 500. I am not
certain as to where I would put the statiscal command. I assume just
before the
'End Repeat' statement. I must apologize but I am a complete novice in
the use of LOOPS in SPSS. Any advice would be appreicated.

=====================
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: Help with Loop

Richard Ristow
Ah, this helps a lot. At 09:16 PM 4/10/2008, Michael Kruger wrote:

>I have frequency data in two rows ('select if row_no EQ 1 OR row_no
>EQ 477 to start with). The row 1 has the control frequencies and row
>477 the treatment frequencies. I am running my statistical procedure
>on these two rows and then need to increment my syntax statemtn to
>read 'row 2 OR row 478', then run the analysis; and so on until I
>end with 'select if row_no eq  476 aOR row_no eq 952'.

OK: you're running the same procedure on multiple sets of *cases*.

The most efficient way to do that is with SPLIT FILES, which can run
the same procedure over a set of subsets of the cases, in one data
pass. (You could also use a macro loop, but it would be MUCH harder
to write, and much less efficient.)

This isn't tested, but I think it's in the right direction:

NUMERIC ExptGrp  (F5)
         CaseCtrl (F2).
VAL LABELS
         CaseCtrl  1 'Control' 2 'Treatment'.

DO IF   row_no LE 476 /* Control lines   */.
.  COMPUTE ExptGrp  = row_no.
.  COMPUTE CaseCtrl = 1.
ELSE                  /* Treatment lines */.
.  COMPUTE ExptGrp  = row_no - 476.
.  COMPUTE CaseCtrl = 2.
END IF.

SORT CASES BY ExptGrp CaseCtrl.
SPLIT FILE BY ExptGrp.
<<run statistical procedure>>

=====================
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