dear list members,
i have a supposingly simple problem, but unfourtenately i'm not able to find my way through it. 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 how can i do this? Thanks in advance, christian |
Christian,
>i have a dataset with a person and a household id. May I assume that the person id is called 'id and the household id is called 'sampid'? >i want spss to simply count the different households so that i would get a dataset that looks like the following The simplest way to count households (sampid) is to use the Aggregate command. Aggregate outfile=*\break=sampid\count=n. Read up on it in the syntax reference. But, the resulting dataset will look like this. Sampid count 1104200032700 2 1104200057500 2 1104200181600 2 1104200213200 1 1104200235500 2 1104200245000 1 Please explain how you computed this id sampid 1 1 2 1 3 2 4 2 5 3 6 3 7 4 8 5 9 5 10 6 From this id sampid 1 1104200032700 2 1104200032700 3 1104200057500 4 1104200057500 5 1104200181600 6 1104200181600 7 1104200213200 8 1104200235500 9 1104200235500 10 1104200245000 Gene Maguin |
In reply to this post by Christian Deindl
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. |
Free forum by Nabble | Edit this page |