Create a repeated id for each group

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

ana.tourino
Posts: 10
Joined: Fri Dec 06, 2013 10:17 am

Create a repeated id for each group

Postby ana.tourino » Fri Dec 06, 2013 10:20 am

Hi spss forum! I´m getting stuck with my work. Please help!
I have this kind of database:
Country_id year party
1 1 CD
1 2 CD
1 3 CD
1 1 PF
1 2 PF
1 2 DK
2 1 LP
2 2 LP
2 1 SD
2 2 SD
I need to create a party identifier (regardless of year and considering the country) to obtain a result like that:
Country_id year party party_id
1 1 CD 101
1 2 CD 101
1 3 CD 101
1 1 PF 102
1 2 PF 102
1 2 DK 103
2 1 LP 201
2 2 LP 201
2 1 SD 202
2 2 SD 202
How can I do that with spss syntax?
Thank you for your help!
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Create a repeated id for each group

Postby GerineL » Fri Dec 06, 2013 12:40 pm

look into automatic recode for the party.

then you can use if-funtions to create ID consisting of both year and partyid.
ana.tourino
Posts: 10
Joined: Fri Dec 06, 2013 10:17 am

Re: Create a repeated id for each group

Postby ana.tourino » Sat Dec 07, 2013 7:55 am

[quote="Gutnre"]look into automatic recode for the party.

Thank you for your answer!
It is a possible solution. Although, I need that the consecutive party id begins with each country.
I mean, there are groups by country and I need to create a party id within groups (the number of cases begin in each country).
Besides, I have a very long database and is unefficient to use de if command for each country.
I have been thinking in using a loop, but I don´t know how.

Have you got any suggestion?

Thank you very very much!
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Create a repeated id for each group

Postby GerineL » Mon Dec 09, 2013 10:31 am

you can change them to strings and then use concat to put the two together.
ana.tourino
Posts: 10
Joined: Fri Dec 06, 2013 10:17 am

Re: Create a repeated id for each group

Postby ana.tourino » Mon Dec 09, 2013 12:09 pm

Gutnre wrote:you can change them to strings and then use concat to put the two together.
Good idea!
Thank you very much!

Who is online

Users browsing this forum: No registered users and 2 guests

cron