Number of differents responses

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

Number of differents responses

Ekoué KOUEVIDJIN
Hello,
I have a dataset like this
 
id    var1    var2    var3    var4    var5    
1    10        20        20     30         40  
2    100    110       100    100       80
3    50        60        13      12        11
 
For id =1 , we are 4 differents responses (10, 20, 30 and 40).
For id =1 , 3 differents responses (100, 110 and 80).
For the last id, 5 differents responses.
I want to compute by id any variable which those differents enswers.
Please help me.
I hope i am clear.
Thanks.
 
Ekoué KOUEVIDJIN
Ingénieur Statisticien
Technicien Supérieur en Electronique


      _____________________________________________________________________________
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
Reply | Threaded
Open this post in threaded view
|

Re: Number of differents responses

Richard Ristow
At 11:45 AM 8/3/2007, Ekoué KOUEVIDJIN wrote:

>I have a dataset like this
|-----------------------------|---------------------------|
|Output Created               |03-AUG-2007 13:07:12       |
|-----------------------------|---------------------------|
id var1 var2 var3 var4 var5

  1   10   20   20   30   40
  2  100  110  100  100   80
  3   50   60   13   12   11

Number of cases read:  3    Number of cases listed:  3

>For id =1 , we are 4 differents responses (10, 20, 30 and 40).
>For id =1 , 3 differents responses (100, 110 and 80).
>For the last id, 5 differents responses.
>I want to compute by id any variable which those differents enswers.

I believe Jan Spousta had a cute way of doing
this. This is cruder; for a very large number of
variables it would be computationally
inefficient; but it works. (See also "Another
approach", below.) This is SPSS 15 draft output
(WRR:not saved separately):

VECTOR Response= var1 TO var5.
VECTOR #Distinct (5,F5) /* At least as long as vector Response */.

RECODE #Distinct1 TO #Distinct5
       (ELSE=SYSMIS)     /* Crucially necessary to initialize   */
                         /* this way                            */.

COMPUTE #DstnctR = 0.
LOOP    #RespIdx = 1 TO 5.

.  DO IF   MISSING(Response(#RespIdx))  /* No response means  */.
.     COMPUTE #New = 0                  /*   no new value     */.
.  ELSE IF #DstnctR EQ 0                /* First reponse is   */.
.     COMPUTE #New = 1                  /*   always new value */.
.  ELSE                                 /* Seen this before?  */.
.     COMPUTE #New = 1.
.     LOOP #Seen = 1 TO #DstnctR.
.        DO IF   Response (#RespIdx)
               EQ #Distinct(#Seen).
.           COMPUTE #New = 0.
.           BREAK.
.        END IF.
.     END  LOOP.
.  END IF.

.  /*-- PRINT / 'Response ' #RespIdx': ' Response(#RespIdx) /*-*/.

.  DO IF #New.
.     COMPUTE #DstnctR =#DstnctR + 1.
.     COMPUTE #Distinct(#DstnctR)
             =  Response(#RespIdx).
.  END IF.
END LOOP.
NUMERIC   DISTINCT (F3).
VAR LABEL DISTINCT 'Number of distinct responses'.
COMPUTE   DISTINCT = #DstnctR.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |03-AUG-2007 13:57:12       |
|-----------------------------|---------------------------|
id var1 var2 var3 var4 var5 DISTINCT

  1   10   20   20   30   40      4
  2  100  110  100  100   80      3
  3   50   60   13   12   11      5

Number of cases read:  3    Number of cases listed:  3

....................
Another approach is to sort the values, probably
in MATRIX; then, it's easy to count distinct
values. To sort in MATRIX, use what's sometimes
called the "Ristow-Peck algorithm". The correct
version of the code is in

Date:         Wed, 16 Mar 2005 08:31:27 -0600
From:         "Peck, Jon" <[hidden email]>
Subject:      Re: Sorting matrices
To:           [hidden email]

For discussion, see

Date:         Wed, 16 Mar 2005 00:44:39 -0500
From:         Richard Ristow <[hidden email]>
Subject:      Re: Sorting matrices
To:           [hidden email]

===================
APPENDIX: Test data
===================
DATA LIST LIST SKIP=1/
    id    var1    var2    var3    var4    var5
   (F2,   5F4).
BEGIN DATA
    id    var1    var2    var3    var4    var5
    1    10        20        20     30         40
    2    100    110       100    100       80
    3    50        60        13      12        11
END DATA.
FORMATS id           (F2).
FORMATS var1 TO var5 (F4).
LIST.