Modal value in aggregate function

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

Modal value in aggregate function

Hoover, Matthew
Hi list,

 

I want to do something that I thought was relatively simple, but I can't
see it as an option in the windows interface.   I have a dataset with 2
variables.  One variable is a list of companies and another variable is
a specific product code for that company.  There are several lines per
company corresponding to many different product codes associated with
that company.  What I would like to do is to aggregate the file to just
1 line per company taking the modal product code (the product code that
repeats the most per company).  In the aggregate function, I see only
"mean" and "median" but no "modal".  

 

BTW, I'm currently using SPSS 14.  

 

Is there some other way I could do this?

 

Thanks,

 

Matt
Reply | Threaded
Open this post in threaded view
|

Re: Modal value in aggregate function

King Douglas
Hi, Matthew,

Is your product code a numeric? or a string variable?

What do you want to do in the case of ties, if any (e.g., a bi-modal situation)?

King Douglas
American Airlines Customer Research

"Hoover, Matthew" <[hidden email]> wrote: Hi list,



I want to do something that I thought was relatively simple, but I can't
see it as an option in the windows interface.   I have a dataset with 2
variables.  One variable is a list of companies and another variable is
a specific product code for that company.  There are several lines per
company corresponding to many different product codes associated with
that company.  What I would like to do is to aggregate the file to just
1 line per company taking the modal product code (the product code that
repeats the most per company).  In the aggregate function, I see only
"mean" and "median" but no "modal".



BTW, I'm currently using SPSS 14.



Is there some other way I could do this?



Thanks,



Matt
Reply | Threaded
Open this post in threaded view
|

Re: Modal value in aggregate function

Hoover, Matthew
Hello,

 

The product code is numeric (I converted it from a string so it would be
easier to aggregate).  If there is an exact tie, I could take either one
them (which one wouldn't matter).  Basically, we are being forced to
give a "main" product code to each company and the only fair way to do
that is by the most occurring code.

 

Matt

 

________________________________

From: King Douglas [mailto:[hidden email]]
Sent: Tuesday, August 21, 2007 11:21 AM
To: Hoover, Matthew; [hidden email]
Subject: Re: Modal value in aggregate function

 

Hi, Matthew,

Is your product code a numeric? or a string variable?

What do you want to do in the case of ties, if any (e.g., a bi-modal
situation)?

King Douglas
American Airlines Customer Research

"Hoover, Matthew" <[hidden email]> wrote:

Hi list,



I want to do something that I thought was relatively simple, but I can't
see it as an option in the windows interface. I have a dataset with 2
variables. One variable is a list of companies and another variable is
a specific product code for that company. There are several lines per
company corresponding to many different product codes associated with
that company. What I would like to do is to aggregate the file to just
1 line per company taking the modal product code (the product code that
repeats the most per company). In the aggregate function, I see only
"mean" and "median" but no "modal".



BTW, I'm currently using SPSS 14.



Is there some other way I could do this?



Thanks,



Matt

 
Reply | Threaded
Open this post in threaded view
|

Re: Modal value in aggregate function

ViAnn Beadle
Try this:

AGGREGATE
  /OUTFILE=*
  /BREAK=company product
  /N_BREAK=N.

SORT CASES BY company N_BREAK(D).

AGGREGATE
  /OUTFILE=*
  /PRESORTED
  /BREAK=company
  /product=FIRST(product)
  /modalvalue=FIRST(N_BREAK).

The first aggregate command gets the count of product by company.

The sort then sorts the product code counts in descending value by company.

The second aggregate then picks up the first instance of product by company.

This also saves the modal value. Note that it treats ties arbitrarily and
can be used with either string or numeric company and product codes.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Hoover, Matthew
Sent: Tuesday, August 21, 2007 9:29 AM
To: [hidden email]
Subject: Re: Modal value in aggregate function

Hello,



The product code is numeric (I converted it from a string so it would be
easier to aggregate).  If there is an exact tie, I could take either one
them (which one wouldn't matter).  Basically, we are being forced to
give a "main" product code to each company and the only fair way to do
that is by the most occurring code.



Matt



________________________________

From: King Douglas [mailto:[hidden email]]
Sent: Tuesday, August 21, 2007 11:21 AM
To: Hoover, Matthew; [hidden email]
Subject: Re: Modal value in aggregate function



Hi, Matthew,

Is your product code a numeric? or a string variable?

What do you want to do in the case of ties, if any (e.g., a bi-modal
situation)?

King Douglas
American Airlines Customer Research

"Hoover, Matthew" <[hidden email]> wrote:

Hi list,



I want to do something that I thought was relatively simple, but I can't
see it as an option in the windows interface. I have a dataset with 2
variables. One variable is a list of companies and another variable is
a specific product code for that company. There are several lines per
company corresponding to many different product codes associated with
that company. What I would like to do is to aggregate the file to just
1 line per company taking the modal product code (the product code that
repeats the most per company). In the aggregate function, I see only
"mean" and "median" but no "modal".



BTW, I'm currently using SPSS 14.



Is there some other way I could do this?



Thanks,



Matt