Counting a value in groups of cases

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

Counting a value in groups of cases

Tom

Hi

 

In order to calculate a quotient (=students with special support sss/number of students in the class Class_N) I think I have first to compute a variable which counts the number of students with special support for each class. The resulting variable should be SSS_N (for class_ID 51 it should be 2, for 52 1 as with class 53). Then, with this new Variable I can calculate the quotient.

Class_ID  SSS(No=1/Yes=2) Class_N

51           1             4

51           1             4

51           2             4

51           2             4

52           2             3

52           1             3

52           1             3

53           2             2

53           1             2

So, how I get the variable SSS_N? Or is there a smarter solution?

 

Thanks

tom

Reply | Threaded
Open this post in threaded view
|

Re: Counting a value in groups of cases

Albert-Jan Roskam
Hello,

Untested:
temporary.
recode sss (1=0)(2=1).
dataset declare result.
aggr out = result / break = class_id / sss_n = sum(sss) / n_class = n.
dataset activate result.
compute quotient = sss_n / n_class.
exe.
 
Regards,
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

From: "Balmer, Thomas" <[hidden email]>
To: [hidden email]
Sent: Monday, August 20, 2012 9:58 AM
Subject: [SPSSX-L] Counting a value in groups of cases

Hi
 
In order to calculate a quotient (=students with special support sss/number of students in the class Class_N) I think I have first to compute a variable which counts the number of students with special support for each class. The resulting variable should be SSS_N (for class_ID 51 it should be 2, for 52 1 as with class 53). Then, with this new Variable I can calculate the quotient.
Class_ID  SSS(No=1/Yes=2) Class_N
51           1             4
51           1             4
51           2             4
51           2             4
52           2             3
52           1             3
52           1             3
53           2             2
53           1             2
So, how I get the variable SSS_N? Or is there a smarter solution?
 
Thanks
tom


Reply | Threaded
Open this post in threaded view
|

Re: Counting a value in groups of cases

Jon K Peck
You probably want the result in the same dataset as the input.  So use
  /OUTFILE=* MODE=ADDVARIABLES
in the AGGREGATE command.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Albert-Jan Roskam <[hidden email]>
To:        [hidden email]
Date:        08/20/2012 05:30 AM
Subject:        Re: [SPSSX-L] Counting a value in groups of cases
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hello,

Untested:
temporary.
recode sss (1=0)(2=1).

dataset declare result.
aggr out = result / break = class_id / sss_n = sum(sss) / n_class = n.
dataset activate result.
compute quotient = sss_n / n_class.
exe.

 
Regards,
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


From: "Balmer, Thomas" <[hidden email]>
To:
[hidden email]
Sent:
Monday, August 20, 2012 9:58 AM
Subject:
[SPSSX-L] Counting a value in groups of cases


Hi
 
In order to calculate a quotient (=students with special support sss/number of students in the class Class_N) I think I have first to compute a variable which counts the number of students with special support for each class. The resulting variable should be SSS_N (for class_ID 51 it should be 2, for 52 1 as with class 53). Then, with this new Variable I can calculate the quotient.
Class_ID  SSS(No=1/Yes=2) Class_N
51           1             4
51           1             4
51           2             4
51           2             4
52           2             3
52           1             3
52           1             3
53           2             2
53           1             2
So, how I get the variable SSS_N? Or is there a smarter solution?
 
Thanks
tom