frequency counts

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

frequency counts

Johnny Amora
Dear SPSS users,

Suppose I have five nominal variables (v1, v2, v3, v4 and v5) each with four categories (strongly agree, agree, somewhat agree, slightly agree, disagree).  I want to present my data where the first column is the variable, the next five columns are the frequency counts for each category, then the last column the mean (I know mean here is not appropriate but the syntax will be used in another data later).  The output would look like as follows:

          stronglyagree   agree   somewhatagree  slightly agree  disagree    mean
V1            100             20                10                 4                  6
V2            100             20                10                 4                  6
V3            100             20                10                 4                  6
V4            100             20                10                 4                  6
V5            100             20                10                 4                  6

The spss syntax to produce such form of output:

CTABLES
/VLABELS VARIABLES=v1 v2 v3 v4 v5 DISPLAY=DEFAULT
/TABLE v1 [COUNT F40.0 TOTALS[MEAN]] + v2 [COUNT F40.0 TOTALS[MEAN]] + v3 [COUNT F40.0 TOTALS[MEAN]] + v4 [COUNT F40.0 TOTALS[MEAN]] + v5 [COUNT F40.0 TOTALS[MEAN]]
 /CLABELS ROWLABEL=OPPOSITE
/CATEGORIES VARIABLES=v1 v2 v3 v4 v5 ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES.

The problem is that if I have 100 variables (v1, v2, ..., v100), the third column of the syntax would be very long.  Is there a short version of the syntax above for large number of variables?

Thank you.



Johnny T. Amora
Center for Learning and Performance Assessment
De La Salle-College of Saint Benilde
Manila, Philippines

---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.

=====================
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: frequency counts

Albert-Jan Roskam
Hi Johnny,

The code below works, but I got a hunch that this
could be done more elegantly. Blame Monday ;-)
At least you could easily extend this to a hundred
variables. You could export it to xls.

Cheers!!
Albert-Jan

* sample code.
data list free /v1 to v5.
begin data
1 2 3 4 5
5 4 3 5 1
5 4 3 2 1
5 4 3 3 1
1 1 2 3 4
end data.

* actual syntax.
vector origin (5).
do repeat #x = origin1 to origin5 / #y = 1 to 5.
+ compute #x = #y.
end repeat print.
exe.
varstocases /make myvalue from v1 to v5 / make origin
from origin1 to origin5 / null = keep.
aggregate outfile = * / break = origin myvalue / n =
n.
casestovars /id = origin / index = myvalue.
recode n.1.00 to n.5.00 (sysmis = 0) (else = copy).
list.



--- Johnny Amora <[hidden email]> wrote:

> Dear SPSS users,
>
> Suppose I have five nominal variables (v1, v2, v3,
> v4 and v5) each with four categories (strongly
> agree, agree, somewhat agree, slightly agree,
> disagree).  I want to present my data where the
> first column is the variable, the next five columns
> are the frequency counts for each category, then the
> last column the mean (I know mean here is not
> appropriate but the syntax will be used in another
> data later).  The output would look like as follows:
>
>           stronglyagree   agree   somewhatagree
> slightly agree  disagree    mean
> V1            100             20                10
>               4                  6
> V2            100             20                10
>               4                  6
> V3            100             20                10
>               4                  6
> V4            100             20                10
>               4                  6
> V5            100             20                10
>               4                  6
>
> The spss syntax to produce such form of output:
>
> CTABLES
> /VLABELS VARIABLES=v1 v2 v3 v4 v5 DISPLAY=DEFAULT
> /TABLE v1 [COUNT F40.0 TOTALS[MEAN]] + v2 [COUNT
> F40.0 TOTALS[MEAN]] + v3 [COUNT F40.0 TOTALS[MEAN]]
> + v4 [COUNT F40.0 TOTALS[MEAN]] + v5 [COUNT F40.0
> TOTALS[MEAN]]
>  /CLABELS ROWLABEL=OPPOSITE
> /CATEGORIES VARIABLES=v1 v2 v3 v4 v5 ORDER=A
> KEY=VALUE EMPTY=INCLUDE TOTAL=YES.
>
> The problem is that if I have 100 variables (v1, v2,
> ..., v100), the third column of the syntax would be
> very long.  Is there a short version of the syntax
> above for large number of variables?
>
> Thank you.
>
>
>
> Johnny T. Amora
> Center for Learning and Performance Assessment
> De La Salle-College of Saint Benilde
> Manila, Philippines
>
> ---------------------------------
> Be a better friend, newshound, and know-it-all with
> Yahoo! Mobile.  Try it now.
>
> =====================
> 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
>



      ____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

=====================
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: frequency counts

ViAnn Beadle
This doesn't do what the OP gets from CTABLES.

1) the columns are not labeled approporiately.
2) the mean column is not displayed.

If the OP wanted to print this very large table, the CTABLES output would
wrap appropriately when printed while list output would just be truncated.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Albert-jan Roskam
Sent: Monday, April 21, 2008 2:13 AM
To: [hidden email]
Subject: Re: frequency counts

Hi Johnny,

The code below works, but I got a hunch that this
could be done more elegantly. Blame Monday ;-)
At least you could easily extend this to a hundred
variables. You could export it to xls.

Cheers!!
Albert-Jan

* sample code.
data list free /v1 to v5.
begin data
1 2 3 4 5
5 4 3 5 1
5 4 3 2 1
5 4 3 3 1
1 1 2 3 4
end data.

* actual syntax.
vector origin (5).
do repeat #x = origin1 to origin5 / #y = 1 to 5.
+ compute #x = #y.
end repeat print.
exe.
varstocases /make myvalue from v1 to v5 / make origin
from origin1 to origin5 / null = keep.
aggregate outfile = * / break = origin myvalue / n =
n.
casestovars /id = origin / index = myvalue.
recode n.1.00 to n.5.00 (sysmis = 0) (else = copy).
list.



--- Johnny Amora <[hidden email]> wrote:

> Dear SPSS users,
>
> Suppose I have five nominal variables (v1, v2, v3,
> v4 and v5) each with four categories (strongly
> agree, agree, somewhat agree, slightly agree,
> disagree).  I want to present my data where the
> first column is the variable, the next five columns
> are the frequency counts for each category, then the
> last column the mean (I know mean here is not
> appropriate but the syntax will be used in another
> data later).  The output would look like as follows:
>
>           stronglyagree   agree   somewhatagree
> slightly agree  disagree    mean
> V1            100             20                10
>               4                  6
> V2            100             20                10
>               4                  6
> V3            100             20                10
>               4                  6
> V4            100             20                10
>               4                  6
> V5            100             20                10
>               4                  6
>
> The spss syntax to produce such form of output:
>
> CTABLES
> /VLABELS VARIABLES=v1 v2 v3 v4 v5 DISPLAY=DEFAULT
> /TABLE v1 [COUNT F40.0 TOTALS[MEAN]] + v2 [COUNT
> F40.0 TOTALS[MEAN]] + v3 [COUNT F40.0 TOTALS[MEAN]]
> + v4 [COUNT F40.0 TOTALS[MEAN]] + v5 [COUNT F40.0
> TOTALS[MEAN]]
>  /CLABELS ROWLABEL=OPPOSITE
> /CATEGORIES VARIABLES=v1 v2 v3 v4 v5 ORDER=A
> KEY=VALUE EMPTY=INCLUDE TOTAL=YES.
>
> The problem is that if I have 100 variables (v1, v2,
> ..., v100), the third column of the syntax would be
> very long.  Is there a short version of the syntax
> above for large number of variables?
>
> Thank you.
>
>
>
> Johnny T. Amora
> Center for Learning and Performance Assessment
> De La Salle-College of Saint Benilde
> Manila, Philippines
>
> ---------------------------------
> Be a better friend, newshound, and know-it-all with
> Yahoo! Mobile.  Try it now.
>
> =====================
> 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
>




____________________________________________________________________________
________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile.  Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

=====================
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: frequency counts

Peck, Jon
In reply to this post by Johnny Amora
An often overlooked feature of CTABLES syntax (because the dialog doesn't use it), is that table expressions and statistics can be factored by using parentheses.  So the /TABLE subcommand below can be written much more compactly as
/TABLES (v1+v2+v3+...)[ COUNT F40.0 TOTALS[MEAN]]

That still leaves the construction of v1+v2+ ... to do manually, but that, too, could be easily automated with a tiny bit of Python.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Johnny Amora
Sent: Sunday, April 20, 2008 9:57 PM
To: [hidden email]
Subject: [SPSSX-L] frequency counts

Dear SPSS users,

Suppose I have five nominal variables (v1, v2, v3, v4 and v5) each with four categories (strongly agree, agree, somewhat agree, slightly agree, disagree).  I want to present my data where the first column is the variable, the next five columns are the frequency counts for each category, then the last column the mean (I know mean here is not appropriate but the syntax will be used in another data later).  The output would look like as follows:

          stronglyagree   agree   somewhatagree  slightly agree  disagree    mean
V1            100             20                10                 4                  6
V2            100             20                10                 4                  6
V3            100             20                10                 4                  6
V4            100             20                10                 4                  6
V5            100             20                10                 4                  6

The spss syntax to produce such form of output:

CTABLES
/VLABELS VARIABLES=v1 v2 v3 v4 v5 DISPLAY=DEFAULT
/TABLE v1 [COUNT F40.0 TOTALS[MEAN]] + v2 [COUNT F40.0 TOTALS[MEAN]] + v3 [COUNT F40.0 TOTALS[MEAN]] + v4 [COUNT F40.0 TOTALS[MEAN]] + v5 [COUNT F40.0 TOTALS[MEAN]]
 /CLABELS ROWLABEL=OPPOSITE
/CATEGORIES VARIABLES=v1 v2 v3 v4 v5 ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES.

The problem is that if I have 100 variables (v1, v2, ..., v100), the third column of the syntax would be very long.  Is there a short version of the syntax above for large number of variables?

Thank you.



Johnny T. Amora
Center for Learning and Performance Assessment
De La Salle-College of Saint Benilde
Manila, Philippines

---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.

=====================
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: frequency counts

Johnny Amora
Thank you for your ideas.

I have additional questions in relation to the one I posted.  What if I want the percent, rather than count, what would be the syntax?



"Peck, Jon" <[hidden email]> wrote: An often overlooked feature of CTABLES syntax (because the dialog doesn't use it), is that table expressions and statistics can be factored by using parentheses.  So the /TABLE subcommand below can be written much more compactly as
/TABLES (v1+v2+v3+...)[ COUNT F40.0 TOTALS[MEAN]]

That still leaves the construction of v1+v2+ ... to do manually, but that, too, could be easily automated with a tiny bit of Python.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Johnny Amora
Sent: Sunday, April 20, 2008 9:57 PM
To: [hidden email]
Subject: [SPSSX-L] frequency counts

Dear SPSS users,

Suppose I have five nominal variables (v1, v2, v3, v4 and v5) each with four categories (strongly agree, agree, somewhat agree, slightly agree, disagree).  I want to present my data where the first column is the variable, the next five columns are the frequency counts for each category, then the last column the mean (I know mean here is not appropriate but the syntax will be used in another data later).  The output would look like as follows:

          stronglyagree   agree   somewhatagree  slightly agree  disagree    mean
V1            100             20                10                 4                  6
V2            100             20                10                 4                  6
V3            100             20                10                 4                  6
V4            100             20                10                 4                  6
V5            100             20                10                 4                  6

The spss syntax to produce such form of output:

CTABLES
/VLABELS VARIABLES=v1 v2 v3 v4 v5 DISPLAY=DEFAULT
/TABLE v1 [COUNT F40.0 TOTALS[MEAN]] + v2 [COUNT F40.0 TOTALS[MEAN]] + v3 [COUNT F40.0 TOTALS[MEAN]] + v4 [COUNT F40.0 TOTALS[MEAN]] + v5 [COUNT F40.0 TOTALS[MEAN]]
 /CLABELS ROWLABEL=OPPOSITE
/CATEGORIES VARIABLES=v1 v2 v3 v4 v5 ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES.

The problem is that if I have 100 variables (v1, v2, ..., v100), the third column of the syntax would be very long.  Is there a short version of the syntax above for large number of variables?

Thank you.



Johnny T. Amora
Center for Learning and Performance Assessment
De La Salle-College of Saint Benilde
Manila, Philippines

---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.

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



Johnny T. Amora
Center for Learning and Performance Assessment
De La Salle-College of Saint Benilde
Manila, Philippines

---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.

=====================
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: frequency counts

Peck, Jon
This question is very easily answered by consulting the Command Syntax Reference installed with SPSS and available on the Help menu, or by using the Custom Tables dialog to generate the syntax for such a table.  I think you would find it beneficial to become familiar with these resources.

 

Regards,

Jon Peck

 

________________________________

From: Johnny Amora [mailto:[hidden email]]
Sent: Monday, April 21, 2008 7:35 PM
To: Peck, Jon; [hidden email]
Subject: Re: frequency counts

 

Thank you for your ideas.

I have additional questions in relation to the one I posted.  What if I want the percent, rather than count, what would be the syntax?



"Peck, Jon" <[hidden email]> wrote:

An often overlooked feature of CTABLES syntax (because the dialog doesn't use it), is that table expressions and statistics can be factored by using parentheses. So the /TABLE subcommand below can be written much more compactly as
/TABLES (v1+v2+v3+...)[ COUNT F40.0 TOTALS[MEAN]]

That still leaves the construction of v1+v2+ ... to do manually, but that, too, could be easily automated with a tiny bit of Python.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Johnny Amora
Sent: Sunday, April 20, 2008 9:57 PM
To: [hidden email]
Subject: [SPSSX-L] frequency counts

Dear SPSS users,

Suppose I have five nominal variables (v1, v2, v3, v4 and v5) each with four categories (strongly agree, agree, somewhat agree, slightly agree, disagree). I want to present my data where the first column is the variable, the next five columns are the frequency counts for each category, then the last column the mean (I know mean here is not appropriate but the syntax will be used in another data later). The output would look like as follows:

stronglyagree agree somewhatagree slightly agree disagree mean
V1 100 20 10 4 6
V2 100 20 10 4 6
V3 100 20 10 4 6
V4 100 20 10 4 6
V5 100 20 10 4 6

The spss syntax to produce such form of output:

CTABLES
/VLABELS VARIABLES=v1 v2 v3 v4 v5 DISPLAY=DEFAULT
/TABLE v1 [COUNT F40.0 TOTALS[MEAN]] + v2 [COUNT F40.0 TOTALS[MEAN]] + v3 [COUNT F40.0 TOTALS[MEAN]] + v4 [COUNT F40.0 TOTALS[MEAN]] + v5 [COUNT F40.0 TOTALS[MEAN]]
/CLABELS ROWLABEL=OPPOSITE
/CATEGORIES VARIABLES=v1 v2 v3 v4 v5 ORDER=A KEY=VALUE EMPTY=INCLUDE TOTAL=YES.

The problem is that if I have 100 variables (v1, v2, ..., v100), the third column of the syntax would be very long. Is there a short version of the syntax above for large number of variables?

Thank you.



Johnny T. Amora
Center for Learning and Performance Assessment
De La Salle-College of Saint Benilde
Manila, Philippines

---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

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




Johnny T. Amora
Center for Learning and Performance Assessment
De La Salle-College of Saint Benilde
Manila, Philippines

 

________________________________

Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. <http://us.rd.yahoo.com/evt=51733/*http:/mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ%20>