Seemingly Simple Count Procedure

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

Seemingly Simple Count Procedure

Dan Riner
I have a seemingly simple problem but the solution is eluding me.

I have a data set with three columns: instructor, course, and section (see
below).  Instructors have one row of data for each student they have
taught indicating both the course and section.  I need to count the number
of classes each instructor has taught (regardless of how many students
they have taught).  In essence, for each instructor, I need to count every
unique combination of a course and section.  In the data below john doe
taught 3 classes, jane doe taught 2, and fred doe taught 1.

Any ideas will be much appreciated.

Dan

DATA LIST
/instructor 1-8 (A) course 10-14 (A) section 16-19.
BEGIN DATA
john doe calc1 1001
john doe calc1 1002
john doe calc1 1002
john doe calc2 2001
john doe calc2 2001
jane doe chem1 1011
jane doe chem1 1011
jane doe chem2 2021
fred doe hist1 1021
fred doe hist1 1021
END DATA.

=====================
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: Seemingly Simple Count Procedure

Swank, Paul R
Why can't you just use crosstabs?

Dr. Paul R. Swank,
Professor and Director of Research
Children's Learning Institute
University of Texas Health Science Center-Houston


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Dan Riner
Sent: Wednesday, October 06, 2010 12:26 PM
To: [hidden email]
Subject: Seemingly Simple Count Procedure

I have a seemingly simple problem but the solution is eluding me.

I have a data set with three columns: instructor, course, and section (see
below).  Instructors have one row of data for each student they have
taught indicating both the course and section.  I need to count the number
of classes each instructor has taught (regardless of how many students
they have taught).  In essence, for each instructor, I need to count every
unique combination of a course and section.  In the data below john doe
taught 3 classes, jane doe taught 2, and fred doe taught 1.

Any ideas will be much appreciated.

Dan

DATA LIST
/instructor 1-8 (A) course 10-14 (A) section 16-19.
BEGIN DATA
john doe calc1 1001
john doe calc1 1002
john doe calc1 1002
john doe calc2 2001
john doe calc2 2001
jane doe chem1 1011
jane doe chem1 1011
jane doe chem2 2021
fred doe hist1 1021
fred doe hist1 1021
END DATA.

=====================
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: Seemingly Simple Count Procedure

Bruce Weaver
Administrator
In reply to this post by Dan Riner
Dan Riner wrote
I have a seemingly simple problem but the solution is eluding me.

I have a data set with three columns: instructor, course, and section (see
below).  Instructors have one row of data for each student they have
taught indicating both the course and section.  I need to count the number
of classes each instructor has taught (regardless of how many students
they have taught).  In essence, for each instructor, I need to count every
unique combination of a course and section.  In the data below john doe
taught 3 classes, jane doe taught 2, and fred doe taught 1.

Any ideas will be much appreciated.

Dan

DATA LIST
/instructor 1-8 (A) course 10-14 (A) section 16-19.
BEGIN DATA
john doe calc1 1001
john doe calc1 1002
john doe calc1 1002
john doe calc2 2001
john doe calc2 2001
jane doe chem1 1011
jane doe chem1 1011
jane doe chem2 2021
fred doe hist1 1021
fred doe hist1 1021
END DATA.
* Flag first instance of each unique course-section combination.
sort cases by course section.
match files
 file = * /
 by course section /
 first = firstrec.
freq firstrec.

For that data set, the frequency distribution shows 6 unique course-section combinations.  

--
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: Seemingly Simple Count Procedure

Mike
In reply to this post by Dan Riner
The problem seems to be mutliple records at the section
level.  To eliminate the multiple records, aggregate the file
so that each case reflect a single "instructor, course,section"
combination.  Then you can count the number of records
for each instructor.  Below I have code for aggregate and
code for the report procedure that should produce the toal
number of course and section combination for each instructor.

compute one=1.
aggregrate outfile= * /
  break=instructor course section/
  section_sum=sum(one).

report format=automatic/
  var=section_sum/
  break=instructor course section (total)/
  summary=validn.

Note that section_sum is a meaningless variable but each unique
instructor, course, and section combination has this "place holder".
You may have to fiddle around a little with the syntax.

-Mike Palij
New York University
[hidden email]

----- Original Message -----
From: "Dan Riner" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, October 06, 2010 1:26 PM
Subject: Seemingly Simple Count Procedure


>I have a seemingly simple problem but the solution is eluding me.
>
> I have a data set with three columns: instructor, course, and section (see
> below).  Instructors have one row of data for each student they have
> taught indicating both the course and section.  I need to count the number
> of classes each instructor has taught (regardless of how many students
> they have taught).  In essence, for each instructor, I need to count every
> unique combination of a course and section.  In the data below john doe
> taught 3 classes, jane doe taught 2, and fred doe taught 1.
>
> Any ideas will be much appreciated.
>
> Dan
>
> DATA LIST
> /instructor 1-8 (A) course 10-14 (A) section 16-19.
> BEGIN DATA
> john doe calc1 1001
> john doe calc1 1002
> john doe calc1 1002
> john doe calc2 2001
> john doe calc2 2001
> jane doe chem1 1011
> jane doe chem1 1011
> jane doe chem2 2021
> fred doe hist1 1021
> fred doe hist1 1021
> END DATA.
>
> =====================
> 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: Seemingly Simple Count Procedure

Luca Meyer-3
In reply to this post by Dan Riner
Another solution could be using 2 subsequent AGGREGATE commands (tested):

DATA LIST
/instructor 1-8 (A) course 10-14 (A) section 16-19.
BEGIN DATA
john doe calc1 1001
john doe calc1 1002
john doe calc1 1002
john doe calc2 2001
john doe calc2 2001
jane doe chem1 1011
jane doe chem1 1011
jane doe chem2 2021
fred doe hist1 1021
fred doe hist1 1021
END DATA.

SORT CASES BY INSTRUCTOR COURSE SECTION.

AGGREGATE
  /OUTFILE=*
  /BREAK=INSTRUCTOR COURSE SECTION
  /TEMP=N.

AGGREGATE
  /OUTFILE=*
  /BREAK=INSTRUCTOR
  /NR_CLASSES=N.

Cheers,
Luca

Luca Meyer
www.lucameyer.com
PASW Statistics v. 18.0.2 (2-apr-2010)
R version 2.9.2 (2009-08-24)
Mac OS X 10.6.4 (10F569) - kernel Darwin 10.4.0


Il giorno 06/ott/2010, alle ore 19.26, Dan Riner ha scritto:

> I have a seemingly simple problem but the solution is eluding me.
>
> I have a data set with three columns: instructor, course, and section (see
> below).  Instructors have one row of data for each student they have
> taught indicating both the course and section.  I need to count the number
> of classes each instructor has taught (regardless of how many students
> they have taught).  In essence, for each instructor, I need to count every
> unique combination of a course and section.  In the data below john doe
> taught 3 classes, jane doe taught 2, and fred doe taught 1.
>
> Any ideas will be much appreciated.
>
> Dan
>
> DATA LIST
> /instructor 1-8 (A) course 10-14 (A) section 16-19.
> BEGIN DATA
> john doe calc1 1001
> john doe calc1 1002
> john doe calc1 1002
> john doe calc2 2001
> john doe calc2 2001
> jane doe chem1 1011
> jane doe chem1 1011
> jane doe chem2 2021
> fred doe hist1 1021
> fred doe hist1 1021
> END DATA.
>
> =====================
> 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: Seemingly Simple Count Procedure

Bruce Weaver
Administrator
In reply to this post by Bruce Weaver
Bruce Weaver wrote
Dan Riner wrote
I have a seemingly simple problem but the solution is eluding me.

I have a data set with three columns: instructor, course, and section (see
below).  Instructors have one row of data for each student they have
taught indicating both the course and section.  I need to count the number
of classes each instructor has taught (regardless of how many students
they have taught).  In essence, for each instructor, I need to count every
unique combination of a course and section.  In the data below john doe
taught 3 classes, jane doe taught 2, and fred doe taught 1.

Any ideas will be much appreciated.

Dan

DATA LIST
/instructor 1-8 (A) course 10-14 (A) section 16-19.
BEGIN DATA
john doe calc1 1001
john doe calc1 1002
john doe calc1 1002
john doe calc2 2001
john doe calc2 2001
jane doe chem1 1011
jane doe chem1 1011
jane doe chem2 2021
fred doe hist1 1021
fred doe hist1 1021
END DATA.
* Flag first instance of each unique course-section combination.
sort cases by course section.
match files
 file = * /
 by course section /
 first = firstrec.
freq firstrec.

For that data set, the frequency distribution shows 6 unique course-section combinations.  
After reading some of the other responses, I see that I neglected to include INSTRUCTOR.  Here is the revised code.

* Flag first instance of each unique instructor-course-section combination.
sort cases by instructor course section.
match files
 file = * /
 by instructor course section /
 first = firstrec.

temp.
select if firstrec.
freq instructor.

OUTPUT (view in a fixed font, such as Courier):

instructor
|--------------|---------|-------|-------------|------------------|
|              |Frequency|Percent|Valid Percent|Cumulative Percent|
|-----|--------|---------|-------|-------------|------------------|
|Valid|fred doe|1        |16.7   |16.7         |16.7              |
|     |--------|---------|-------|-------------|------------------|
|     |jane doe|2        |33.3   |33.3         |50.0              |
|     |--------|---------|-------|-------------|------------------|
|     |john doe|3        |50.0   |50.0         |100.0             |
|     |--------|---------|-------|-------------|------------------|
|     |Total   |6        |100.0  |100.0        |                  |
|-----|--------|---------|-------|-------------|------------------|

 
--
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: Seemingly Simple Count Procedure

Dan Riner
In reply to this post by Dan Riner
Many thanks for the posted solutions.  I assumed that aggregate would be
the way to go but I rarely use the command and couldn't get it to work the
way I wanted it to.  I would never have thought to use match files (a
procedure I use all the time) but it works too.

Dan



On Wed, 6 Oct 2010 20:48:54 +0200, Luca Meyer <[hidden email]>
wrote:

>Another solution could be using 2 subsequent AGGREGATE commands (tested):
>
>DATA LIST
>/instructor 1-8 (A) course 10-14 (A) section 16-19.
>BEGIN DATA
>john doe calc1 1001
>john doe calc1 1002
>john doe calc1 1002
>john doe calc2 2001
>john doe calc2 2001
>jane doe chem1 1011
>jane doe chem1 1011
>jane doe chem2 2021
>fred doe hist1 1021
>fred doe hist1 1021
>END DATA.
>
>SORT CASES BY INSTRUCTOR COURSE SECTION.
>
>AGGREGATE
>  /OUTFILE=*
>  /BREAK=INSTRUCTOR COURSE SECTION
>  /TEMP=N.
>
>AGGREGATE
>  /OUTFILE=*
>  /BREAK=INSTRUCTOR
>  /NR_CLASSES=N.
>
>Cheers,
>Luca
>
>Luca Meyer
>www.lucameyer.com
>PASW Statistics v. 18.0.2 (2-apr-2010)
>R version 2.9.2 (2009-08-24)
>Mac OS X 10.6.4 (10F569) - kernel Darwin 10.4.0
>
>
>Il giorno 06/ott/2010, alle ore 19.26, Dan Riner ha scritto:
>
>> I have a seemingly simple problem but the solution is eluding me.
>>
>> I have a data set with three columns: instructor, course, and section
(see
>> below).  Instructors have one row of data for each student they have
>> taught indicating both the course and section.  I need to count the
number
>> of classes each instructor has taught (regardless of how many students
>> they have taught).  In essence, for each instructor, I need to count
every

>> unique combination of a course and section.  In the data below john doe
>> taught 3 classes, jane doe taught 2, and fred doe taught 1.
>>
>> Any ideas will be much appreciated.
>>
>> Dan
>>
>> DATA LIST
>> /instructor 1-8 (A) course 10-14 (A) section 16-19.
>> BEGIN DATA
>> john doe calc1 1001
>> john doe calc1 1002
>> john doe calc1 1002
>> john doe calc2 2001
>> john doe calc2 2001
>> jane doe chem1 1011
>> jane doe chem1 1011
>> jane doe chem2 2021
>> fred doe hist1 1021
>> fred doe hist1 1021
>> END DATA.
>>
>> =====================
>> 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

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