counting frequencies in 30 columns of cases with specific characteristics.

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

counting frequencies in 30 columns of cases with specific characteristics.

Deepa Lakshmi Shanadi
Dear all,

I need to count the total number of cases in 30 columns of children that are aged 3 to 18 years old. 

I have the following:

COUNT age3to18frequency=B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
    B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
    B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
    B5_AGE$28 B5_AGE$29 B5_AGE$30(3 thru 18).
EXECUTE.

But now I want to count the total number of cases in the 30 columns of those children that are aged 3 to 18 AND are going to school. The other variable is currently going to school= B8- 1= yes, 2=no, SO if the variable for going to School is B8#1, B8#2, etc to B8#30, where do I put the DO If statement in?

Thanks all,
Deepa



<input onclick="jsCall();" id="jsProxy" type="hidden">

Reply | Threaded
Open this post in threaded view
|

Re: counting frequencies in 30 columns of cases with specific characteristics.

Art Kendall
see if this untested syntax is what you might mean. the long list for b5 is how to specify the variable list if the variables are not contiguous. the short version like what i used for b8 is for if the variables are contiguous.

* if you want 30 counts and a grand total.
numeric totalinschool (f5).
do repeat
   b5       = B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
              B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
              B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
              B5_AGE$28 B5_AGE$29 B5_AGE$30/
   b8       = B8#1 to B8#30/
   inschool = inschool1 to inschool30.
if b8 eq 1  and range(b5,3,18) inschool =  1.
end repeat.
compute totalinschool = sum.1(inschool1 to inschool30).


if you do not need all 30 counts something like this.
numeric totalinschool (f5).
do repeat
   b5         = B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
                B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
                B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
                B5_AGE$28 B5_AGE$29 B5_AGE$30/
   b8         = B8#1 to B8#30/.
if b8 eq 1  and range(b5,3,18) totalinschool = totalinschool + 1.
end repeat.


Art Kendall
Social Research Consultants

On 9/17/2010 2:55 PM, Deepa Lakshmi Shanadi wrote:
Dear all,

I need to count the total number of cases in 30 columns of children that are aged 3 to 18 years old. 

I have the following:

COUNT age3to18frequency=B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
    B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
    B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
    B5_AGE$28 B5_AGE$29 B5_AGE$30(3 thru 18).
EXECUTE.

But now I want to count the total number of cases in the 30 columns of those children that are aged 3 to 18 AND are going to school. The other variable is currently going to school= B8- 1= yes, 2=no, SO if the variable for going to School is B8#1, B8#2, etc to B8#30, where do I put the DO If statement in?

Thanks all,
Deepa



<input onclick="jsCall();" id="jsProxy" type="hidden">

===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: counting frequencies in 30 columns of cases with specific characteristics.

John F Hall
In reply to this post by Deepa Lakshmi Shanadi
Deepa
 
Interesting question for which Art has already supplied syntax.  If you need to come back with more requests for help, it would be useful if you could let me have a list of the variables in your file.  Can you do...?
 
display labels .
 
. . .  and send me the output?
 
There are some tutorials on COUNT in Block 3 on my site, but your request is more complex.  If your data set is not overly large I can probably offer more specific advice and assistance off-list.
 
----- Original Message -----
Sent: Friday, September 17, 2010 8:55 PM
Subject: counting frequencies in 30 columns of cases with specific characteristics.

Dear all,

I need to count the total number of cases in 30 columns of children that are aged 3 to 18 years old. 

I have the following:

COUNT age3to18frequency=B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
    B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
    B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
    B5_AGE$28 B5_AGE$29 B5_AGE$30(3 thru 18).
EXECUTE.

But now I want to count the total number of cases in the 30 columns of those children that are aged 3 to 18 AND are going to school. The other variable is currently going to school= B8- 1= yes, 2=no, SO if the variable for going to School is B8#1, B8#2, etc to B8#30, where do I put the DO If statement in?

Thanks all,
Deepa



<INPUT id=jsProxy onclick=jsCall(); type=hidden>

Reply | Threaded
Open this post in threaded view
|

Re: counting frequencies in 30 columns of cases with specific characteristics.

Richard Ristow
In reply to this post by Deepa Lakshmi Shanadi
At 02:55 PM 9/17/2010, Deepa Lakshmi Shanadi wrote:

I need to count the total number of cases in 30 columns of children that are aged 3 to 18 years old. 

I have the following:

COUNT age3to18frequency=
      B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05
      B5_AGE$06 B5_AGE$07 B5_AGE$08 B5_AGE$09 B5_AGE$10
      B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15
      B5_AGE$16 B5_AGE$17 B5_AGE$18 B5_AGE$19 B5_AGE$20
      B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25
      B5_AGE$26 B5_AGE$27 B5_AGE$28 B5_AGE$29 B5_AGE$30
      (3 thru 18).
EXECUTE.

(The EXECUTE, of course, is neither necessary nor helpful.)

But now I want to count the total number of cases in the 30 columns of those children that are aged 3 to 18 AND are going to school. The other variable is currently going to school= B8- 1= yes, 2=no, SO if the variable for going to School is B8#1, B8#2, etc to B8#30, where do I put the DO If statement in?

This is an instance of multiple logical records (one for each child for each age) in a single physical record. In database parlance, the file is not 'normalized'.

My preference (hi, David Marso) is to 'unroll' the file to 'long', or normalized, form. The syntax after that is much more direct, including easier to understand and debug; and other uses of the file will likely be easier in the 'long' form, as well.

To 'unroll', something like this (untested):
VARSTOCASES 
 /MAKE    Age      
  FROM    B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05
          B5_AGE$06 B5_AGE$07 B5_AGE$08 B5_AGE$09 B5_AGE$10
          B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15
          B5_AGE$16 B5_AGE$17 B5_AGE$18 B5_AGE$19 B5_AGE$20
          B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25
          B5_AGE$26 B5_AGE$27 B5_AGE$28 B5_AGE$29 B5_AGE$30
 /MAKE    In_School
  FROM    B8#1      B8#2      B8#3      B8#4      B8#5
          B5_AGE$06 B5_AGE$07 B5_AGE$08 B5_AGE$09 B5_AGE$10
          B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15
          B5_AGE$16 B5_AGE$17 B5_AGE$18 B5_AGE$19 B5_AGE$20
          B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25
          B5_AGE$26 B5_AGE$27 B5_AGE$28 B5_AGE$29 B5_AGE$30
 /INDEX = AgeRec#(30)
 /KEEP  = Child_ID
 /NULL  = DROP.

Here's a complete example (tested), with five different ages. If you start with
|-----------------------------|---------------------------|
|Output Created               |20-SEP-2010 19:59:24       |
|-----------------------------|---------------------------|
[ShortForm]
 
Chil
d_ID B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B8#1 B8#2 B8#3 B8#4 B8#5

 001     20        11        15         8         2      1    0    1    1    1
 002     10        16        14         2         6      1    0    0    1    1
 003     18        11        16         3        15      1    1    0    0    1

Number of cases read:  3    Number of cases listed:  3

then, like this (tested):

VARSTOCASES
 /MAKE    Age
  FROM    B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05
 /MAKE    In_School
  FROM    B8#1      B8#2      B8#3      B8#4      B8#5
 /INDEX = AgeRec#(5)
 /KEEP  =  Child_ID
 /NULL  = DROP.
Variables to Cases
|-----------------------------|---------------------------|
|Output Created               |20-SEP-2010 19:59:25       |
|-----------------------------|---------------------------|
[LongForm]
Generated Variables
|---------|------|
|Name     |Label |
|---------|------|
|AgeRec#  |<none>|
|Age      |<none>|
|In_School|<none>|
|---------|------|
Processing Statistics
|-------------|--|
|Variables In |11|
|Variables Out|4 |
|-------------|--|

COMPUTE Age3to18_InSch = RANGE(Age,3,18) AND In_School.
LIST.
List
|-----------------------------|---------------------------|
|Output Created               |20-SEP-2010 19:59:26       |
|-----------------------------|---------------------------|
[LongForm]
Child_ID AgeRec# Age In_School Age3to18_InSch

   001        1   20     1             .00
   001        2   11     0             .00
   001        3   15     1            1.00
   001        4    8     1            1.00
   001        5    2     1             .00
   002        1   10     1            1.00
   002        2   16     0             .00
   002        3   14     0             .00
   002        4    2     1             .00
   002        5    6     1            1.00
   003        1   18     1            1.00
   003        2   11     1            1.00
   003        3   16     0             .00
   003        4    3     0             .00
   003        5   15     1            1.00

Number of cases read:  15    Number of cases listed:  15

DATASET DECLARE  Counts.
AGGREGATE
        OUTFILE =Counts
       /BREAK   =Child_ID
       /Total 'Ages 3-18 and in school' = SUM(Age3to18_InSch).



=============================
APPENDIX: Test data, and code
=============================
*  .................   Test data               ..................... .
SET RNG = MT       /* 'Mersenne twister' random number generator  */ .
SET MTINDEX = 6789 /*  (Just thrown in)                           */ .


INPUT PROGRAM.
.  NUMERIC  Child_ID (N3).
.  NUMERIC  B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05  (F2)
            B8#1      B8#2      B8#3      B8#4      B8#5       (F1).

LOOP Child_ID = 1 TO 3.
.  DO REPEAT 
       Age       = B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05
      /In_School = B8#1      B8#2      B8#3      B8#4      B8#5.
.      COMPUTE Age      =TRUNC(RV.UNIFORM(1,21)).
.      COMPUTE In_School=RV.BERNOULLI(0.7).
.  END REPEAT.
.  END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
DATASET NAME     ShortForm WINDOW=FRONT.
LIST.

DATASET ACTIVATE ShortForm WINDOW=FRONT /* helpful when debugging */.
DATASET COPY     LongForm.
DATASET ACTIVATE LongForm  WINDOW=FRONT.


*  .................   Working code            ..................... .
*  ................................................................. .
VARSTOCASES 
 /MAKE    Age      
  FROM    B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05
 /MAKE    In_School
  FROM    B8#1      B8#2      B8#3      B8#4      B8#5
 /INDEX = AgeRec#(5)
 /KEEP  = Child_ID
 /NULL  = DROP.

LIST.

COMPUTE Age3to18_InSch = RANGE(Age,3,18) AND In_School.
LIST.

DATASET DECLARE  Counts.
AGGREGATE
        OUTFILE =Counts
       /BREAK   =Child_ID
       /Total 'Ages 3-18 and in school' = SUM(Age3to18_InSch).

DATASET ACTIVATE Counts    WINDOW=FRONT.
FORMATS Total (F3).
LIST.

===================== 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: counting frequencies in 30 columns of cases with specific characteristics.

Art Kendall
In reply to this post by Art Kendall
the TO convention on a list of variables (varlist in the syntax documentation) allows you to specify a set of variables that are in columns that are next to each other in the data file. You can see this in the variable view or across the top of the data view.
if these 7 variables are next to each other (contiguous) in the data file
B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
you do not have to type the whole list you can just type
B5_AGE$01  TO B5_AGE$07

In the snippet of syntax you just posted for the do repeat
B5 is defined by typing out the whole variable list as if the variables were scattered across the data file.
B8 is defined as if for that list of variables the variables were next to each other.
inschool creates a new set of 30 variables that are next to each other.

the first error message tells you that the variable totalinschool already exists, most likely from an earlier use of the same syntax.

You have an extra period which tells SPSS you have finished the DO REPEAT command.
Since you finished a command SPSS is looking for a new command and B8 is not a legitimate command
   
             B5_AGE$28 B5_AGE$29 B5_AGE$30/.
   b8       =B8_CURATSCH$1 to B8_CURATSCH$30/.

Did the syntax with simulated data work the way you wanted?

I suggest you work with the simulated data until you have logic that does what you want.

Art Kendall
Social Research Consultants

On 9/21/2010 1:45 PM, Deepa Lakshmi Shanadi wrote:
see responses in bold.
Sorry to go back and forth, but I see you are using a shortcut and that is why I am interested.

this is the syntax I am using of yours:

numeric totalinschool (f5).
do repeat
   b5       = B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
              B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
              B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
              B5_AGE$28 B5_AGE$29 B5_AGE$30/.
   b8       =B8_CURATSCH$1 to B8_CURATSCH$30/.
   inschool = inschool1 to inschool30.
if b8 eq 1  and range(b5,3,18) inschool =  1.
end repeat.
compute totalinschool (f5)= sum.1(inschool1 to inschool30).



From: Art Kendall [hidden email]
To: Deepa Lakshmi Shanadi [hidden email]
Cc: [hidden email]; [hidden email]
Sent: Mon, September 20, 2010 1:02:02 PM
Subject: Re: [SPSSX-L] counting frequencies in 30 columns of cases with specific characteristics.

The reply by Mr. Kumaran did not appear on the listserv list.
see comments interspersed below.

On 9/20/2010 11:22 AM, Deepa Lakshmi Shanadi wrote:
Thank you for your inputs.

The variable B8 is a yes or no variable.

I am leaning toward on using the compute new variable provided by Mr. Kumaran.

As you can see from my syntax, I do not know shortcuts in SPSS.
if your variables are next to each other (contiguous) you can use the TO convention on a varlist.

I don't know what TO convention on a varlist is.

Mr. Kendall, I am getting error messages using both of your syntax.
What error messages are you getting?
numeric totalinschool (f5).

>Error # 4822 in column 9.  Text: totalinschool
>A variable with this name is already defined.
>This command not executed.
do repeat
   b5       = B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
              B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
              B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
              B5_AGE$28 B5_AGE$29 B5_AGE$30/.
   b8       =B8_CURATSCH$1 to B8_CURATSCH$30/.

>Warning # 141.  Command name: b8
>DO REPEAT has no effect on this command.

>Error # 1.  Command name: b8
>The first word in the line is not recognized as an SPSS Statistics command.
>This command not executed.
   inschool = inschool1 to inschool30.

>Warning # 141.  Command name: inschool
>DO REPEAT has no effect on this command.

>Error # 1.  Command name: inschool
>The first word in the line is not recognized as an SPSS Statistics command.
>This command not executed.
if b8 eq 1  and range(b5,3,18) inschool =  1.
end repeat.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.

>Error # 4285 in column 4.  Text: b8
>Incorrect variable name: either the name is more than 64 characters, or it is
>not defined by a previous command.
>This command not executed.
compute totalinschool (f5)= sum.1(inschool1 to inschool30).

>Error # 4030 in column 9.  Text: totalinschool
>The operand appearing on the left side of the assignment operator (equals
>sign) is not a known vector name or function name.
>This command not executed.



Why is the Do repeat in the second version in red?
the only thing I can think of is the distinction between fixed and variable fonts was lost and perhaps you pasted text that was not posted in a fixed font.

The reason the data is in 30 columns is that each row represents a family and there are upto 30 people per family. The sample size is 524 families. I am trying to see how many families have children 3 to 18 who are going to school and also then how many children in the total dataset are 3 to 18 and are going to school.

THANK YOU in advance for your assistance.




assuming that your variables are contiguous and you just want 3 new variables something like this should do it.
(open a new instance of SPSS copy and paste this syntax in to syntax window and run it.  Is this what you are looking for?

* make up data to test syntax.
data list list /id (f3) b5_age$01 to b5_age$03 (3f3) b8#1 to b8#3 (3f3).
begin data
001 20 21  3  2  2  2
002 22  7 18  2  1  2
003 19  2  4  2  1  2
004 21  7  7  2  1  1
005 35 18 19  2  1  1
006 40 41 -1  2  2 -1
007 22  6 -1  2  1 -1
008 22  6  7  2  1 -1
end data.
missing values  b5_age$01 to  b8#3 (-1).
list.
* adapt this by changing "03" to "30".
numeric familysize kids kidsinschool (f2).
compute familysize = nvalid(B5_AGE$01 to B5_AGE$03).
compute kids =0.
compute kidsinschool = 0.
do repeat
   b5         = B5_AGE$01 to B5_AGE$03/
   b8         = B8#1 to B8#3.
if  range(b5,3,18) kids = kids +1.
if  range(b5,3,18) and b8 eq 1 kidsinschool = kidsinschool + 1.
end repeat.

list.



Art Kendall
Social Research Consultants

From: Art Kendall [hidden email]
To: Deepa Lakshmi Shanadi [hidden email]
Cc: [hidden email]
Sent: Fri, September 17, 2010 3:35:56 PM
Subject: Re: [SPSSX-L] counting frequencies in 30 columns of cases with specific characteristics.

see if this untested syntax is what you might mean. the long list for b5 is how to specify the variable list if the variables are not contiguous. the short version like what i used for b8 is for if the variables are contiguous.

* if you want 30 counts and a grand total.
numeric totalinschool (f5).
do repeat
   b5       = B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
              B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
              B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
              B5_AGE$28 B5_AGE$29 B5_AGE$30/
   b8       = B8#1 to B8#30/
   inschool = inschool1 to inschool30.
if b8 eq 1  and range(b5,3,18) inschool =  1.
end repeat.
compute totalinschool = sum.1(inschool1 to inschool30).


if you do not need all 30 counts something like this.
numeric totalinschool (f5).
do repeat
   b5         = B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
                B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
                B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
                B5_AGE$28 B5_AGE$29 B5_AGE$30/
   b8         = B8#1 to B8#30/.
if b8 eq 1  and range(b5,3,18) totalinschool = totalinschool + 1.
end repeat.


Art Kendall
Social Research Consultants

On 9/17/2010 2:55 PM, Deepa Lakshmi Shanadi wrote:
Dear all,

I need to count the total number of cases in 30 columns of children that are aged 3 to 18 years old. 

I have the following:

COUNT age3to18frequency=B5_AGE$01 B5_AGE$02 B5_AGE$03 B5_AGE$04 B5_AGE$05 B5_AGE$06 B5_AGE$07
    B5_AGE$08 B5_AGE$09 B5_AGE$10 B5_AGE$11 B5_AGE$12 B5_AGE$13 B5_AGE$14 B5_AGE$15 B5_AGE$16 B5_AGE$17
    B5_AGE$18 B5_AGE$19 B5_AGE$20 B5_AGE$21 B5_AGE$22 B5_AGE$23 B5_AGE$24 B5_AGE$25 B5_AGE$26 B5_AGE$27
    B5_AGE$28 B5_AGE$29 B5_AGE$30(3 thru 18).
EXECUTE.

But now I want to count the total number of cases in the 30 columns of those children that are aged 3 to 18 AND are going to school. The other variable is currently going to school= B8- 1= yes, 2=no, SO if the variable for going to School is B8#1, B8#2, etc to B8#30, where do I put the DO If statement in?

Thanks all,
Deepa





<input onclick="jsCall();" id="jsProxy" type="hidden">

===================== 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
Art Kendall
Social Research Consultants