Split file and $casenum

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

gandalf
Posts: 11
Joined: Mon Apr 16, 2012 12:25 pm

Split file and $casenum

Postby gandalf » Mon Feb 17, 2014 11:31 pm

My data has these fields.

Case, House, Person. There could be more than one unique combination for these columns. I am posting a sample below.

Code: Select all

Case House Person
1	1	1
1	1	1
1	1	1
2	1	2
2	1	2
2	1	2
2	1	2
3	2	1
3	2	1
3	2	1
3	2	1
3	2	1
I want to create a serial number column which uses $casenum function. But, the $casenum should start from 1 for every unique combination. So, the output should look something like this.

Code: Select all

Case House Person Casenum
1	1	1           1
1	1	1           2
1	1	1           3
2	1	2           1
2	1	2           2
2	1	2           3
2	1	2           4
3	2	1           1
3	2	1           2
3	2	1           3
3	2	1           4
3	2	1           5
I have split my file based on the Case, House, and Person variables and created a casenumber variable. But, I am not getting the required output. I have posted the code below. Can anyone let me know the issues here.

Code: Select all

SPLIT FILE LAYERED BY Case House Person.

COMPUTE Casenum=$CASENUM.
EXECUTE.
My code is simply giving me an output with sequential casenumbers. Its not considering the split file.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Split file and $casenum

Postby GerineL » Tue Feb 18, 2014 9:13 am

1. create id code for case/house/person combination (e.g., 1000000*case + 10000*house+person, but take something that makes them unique for your dataset).

2.

compute casenumb = 1.
execute.

if (uniqueID= lag(uniqueID)) casenumb = lag(casenumb)+1.
execute.
gandalf
Posts: 11
Joined: Mon Apr 16, 2012 12:25 pm

Re: Split file and $casenum

Postby gandalf » Tue Feb 18, 2014 7:10 pm

Gutnre wrote:1. create id code for case/house/person combination (e.g., 1000000*case + 10000*house+person, but take something that makes them unique for your dataset).

2.

compute casenumb = 1.
execute.

if (uniqueID= lag(uniqueID)) casenumb = lag(casenumb)+1.
execute.

Thanks for your response Gutnre. I don't want to sound unthankful, but I figured out that we could do this using lag or lead functions.

Anyways, I was trying to figure out the issue with my approach. Why would my approach not work even when I have split the file. Shouldn't the $casenum command start from 1 for every unique combination?
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Split file and $casenum

Postby GerineL » Wed Feb 19, 2014 8:40 am

split file doesn't work on computing variables (as far as I know, it's only for organizing output from analyses)

Who is online

Users browsing this forum: No registered users and 2 guests

cron