Company News Products Projects Texts Museum Download Contact Map RSS Polski
YAC Software Texts SPSS SPSS Syntax - COUNT Function Trybiks' Dive
  Back

List

Data

Excel

Media research

Market research

Respondent quotas

SPSS

VBA

YAC Data Language

SPSS Syntax - COUNT Function
In the comments to the previous article on some SPSS Syntax Tips, Rich asked the following question:

Is there a syntax for computing a new variable, depending on how people responded to a set of items in a multiple response question?

Let me explain: there is a multiple response question, with 20 items. We consider all items in the question as all to pointing to healthy life style.

I want to create a new variable "healthy life style" (YES/NO)... So, if a person responded "yes" to ANY of the items in the multiple response question, she/he would be categorized as having a healthy life style.

The very simple solution to that would be to use the COUNT syntax function; the simplified syntax for that function would go something like this:
  count newvar = oldvar1 to oldvarN (value1 thru valueM).
This works for any set of variables and values, but probably is most often used for:
  • Calculating the number of positive responses to a multi-coded question coded using dichotomous variables (with values 0 for "no" and 1 for "yes").
  • Calculating the number of positive responses to a multi-coded question coded using numeric variables (with values 1..N to specify the different responses (like brands) and 0 for "no").
  • The COUNT function can also be used, in the example above, to check which respondents gave a particular response (or one response from a set of responses).
  • Calculating the number of positive response in a battery of scales (where, for instance, 1 and 2 are negative responses, 4 and 5 - positive, and you want to calculate the percentage of people that gave at least N positive responses).
In the examples above, instead of positive responses, we may need to find missing values, or negative responses, or a specific response - whatever; the syntax will always be the same.

So, let's take a look at each of the mentioned scenarios:

Calculate the number of positive responses to a multi-coded question coded using dichotomous variables:

Let's assume that we have multi-coded data on variables v1 to v10. The syntax would go like this:
  count positive = v1 to v10 (1).
positive will just have the number of ones in variables v1 to v10, for each case. Just remember that v1 to v10 is a range defined by the order of variables in SPSS; if, for instance, you have variables v1, v2, a, v10, then v1 to v10 denotes a set containing all those variables.

Calculate the number of positive responses to a multi-coded question coded using numeric variables:

Let's assume again that we have multi-coded data on variables v1 to v10. And the positive values are from the range 1 to 100 (we're just entering the data for top-10 responses, I guess). The syntax would go like this:
  count positive = v1 to v10 (1 thru 100).
We're just calculating the number of responses; if you get a zero on positive, the respondent didn't mention a single "positive" response.

Check who mentioned brands A (23), A-color (24), and B (67):

With the data coded just like in the example above, we can use the following syntax:
  count brands = v1 to v10 (23 24 67).
Basically, in place of lists of variables and lists of values we can use standard SPSS Syntax notation for ranges / lists (where to / thru denotes a range of variables / values respectively, and subsequent variables / values / ranges are separated using blanks).

Calculate the number of positive response (4 or 5) in a battery of scales:

The syntax is just like the previous ones:
  count positive = v1 to v10 (4 5).
Having a new variable (that counts the number of responses; it's not dichotomous itself yet) you can either calculate a new variable (using if, for instance); recode it (all values above 1 to 1; then this can be used as a filter) or use it in filter expressions directly. But, obviously, you can also use them for just calculating frequencies (to get the fraction of respondents that gave more than 5 positive responses, for instance).

The example syntax at the top describes the function in general. We've seen some of the other possible uses above, but here's a quick summary:
  count new1 = old1 (1).
  count new2 = old1 (1 to 10).
  count new3 = old1 to old5 (1).
new1 counts one value for one variable only, new2 - a range of values for one variable, and new3 - a value for a range of variables.

Finally, you can use sets of variables and/or values, like so:
  count new4 = old1 to old5 old10 (1 thru 3 99).
HTH

Top

Comments
Alas!
No comments yet...

Top

Add a comment (fields with an asterisk are required)
Name / nick *
Mail (will remain hidden) *
Your website
Comment (no tags) *
Enter the text displayed below *
 

Top

Tags

SPSS


Related pages

SPSS Syntax Tips