Posted by
Richard Ristow on
Apr 27, 2007; 7:25pm
URL: http://spssx-discussion.165.s1.nabble.com/count-problem-tp1075304p1075305.html
At 10:14 AM 4/26/2007, Christian Deindl wrote:
>i have a dataset with a person and a household id.
>
>id sampid
>1 1104200032700
>2 1104200032700
>3 1104200057500
>4 1104200057500
>5 1104200181600
>6 1104200181600
>7 1104200213200
>8 1104200235500
>9 1104200235500
>10 1104200245000
>
>i want spss to simply count the different households so that i would
>get a dataset that looks like the following
>
>id sampid
>1 1
>2 1
>3 2
>4 2
>5 3
>6 3
>7 4
>8 5
>9 5
>10 6
Try this. This is SPSS 15 draft output.
|-----------------------------|---------------------------|
|Output Created |27-APR-2007 14:21:53 |
|-----------------------------|---------------------------|
id sampid SID_want
1 1104200032700 1
2 1104200032700 1
3 1104200057500 2
4 1104200057500 2
5 1104200181600 3
6 1104200181600 3
7 1104200213200 4
8 1104200235500 5
9 1104200235500 5
10 1104200245000 6
Number of cases read: 10 Number of cases listed: 10
NUMERIC sampid2 (F3).
DO IF MISSING (LAG(sampid)).
. COMPUTE sampid2 = 1.
ELSE IF sampid EQ LAG(sampid).
. COMPUTE sampid2
= LAG(sampid2).
ELSE.
. COMPUTE sampid2
= LAG(sampid2) + 1.
END IF.
LIST.
List
|-----------------------------|---------------------------|
|Output Created |27-APR-2007 14:21:53 |
|-----------------------------|---------------------------|
id sampid SID_want sampid2
1 1104200032700 1 1
2 1104200032700 1 1
3 1104200057500 2 2
4 1104200057500 2 2
5 1104200181600 3 3
6 1104200181600 3 3
7 1104200213200 4 4
8 1104200235500 5 5
9 1104200235500 5 5
10 1104200245000 6 6
Number of cases read: 10 Number of cases listed: 10
===========================================
APPENDIX: Test data (from original posting)
===========================================
* ................. Test data ..................... .
DATA LIST LIST
/id sampid SID_want.
BEGIN DATA
1 1104200032700 1
2 1104200032700 1
3 1104200057500 2
4 1104200057500 2
5 1104200181600 3
6 1104200181600 3
7 1104200213200 4
8 1104200235500 5
9 1104200235500 5
10 1104200245000 6
END DATA.
FORMATS
ID (F3) SAMPID (F14) SID_want(F3).
LIST.