Date: Tue, 25 Oct 2005 08:54:48 +0200
Reply-To: Spousta Jan <JSpousta@CSAS.CZ>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Spousta Jan <JSpousta@CSAS.CZ>
Subject: Re: I: Creating cases genealogies
Content-Type: text/plain; charset="iso-8859-1"
Hi Luca,
try this:
DATA LIST LIST /SubjectId FatherId NrBelonging BirthDate.
BEGIN DATA
1 99 3 19471113
2 3 1 19701007
3 99 1 19650204
4 1 1 19720116
5 2 0 19980505
6 1 0 19750927
7 99 0 19270702
8 4 0 20030411
9 1 0 19781201
10 3 0 19951111
END DATA.
recode FatherId (99=sysmis).
* it is much better to mark the missing fatherID by a missing than by 99.
define geneal ().
* assign family numbers - just a sequence 1, 2, ...
if ($casenum = 1) #fam = 1.
if ($casenum > 1) #fam = lag(#fam).
do if (missing(FatherId)).
- compute Family = #fam.
- compute #fam = #fam + 1.
- compute Level = 1.
end if.
!do !i = 1 !to 10.
* the limit of the loop is the maximum possible number of generations.
compute noassign = missing(Family).
compute persno = FatherId.
if not missing(Family) persno = SubjectId.
exe.
sort cases by persno noassign.
do if ($casenum > 1 & missing(Family) & not missing(lag(Family)) & persno = lag(persno)).
- compute Family = lag(Family).
- compute Level = lag(Level) + (lag(noassign)=0).
end if.
exe.
!doend.
dele var noassign persno.
!enddefine.
geneal.
form all (f8).
Greetings
Jan
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Luca Meyer
Sent: Monday, October 24, 2005 11:12 AM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: I: Creating cases genealogies
I am not sure whether my prior message (it was in html format) was correctly distributed to the mailing list so I post it again. Apologizes if you should have already received it.
Luca
-----Messaggio originale-----
Da: Luca Meyer [mailto:lucameyer@tiscali.it]
Inviato: venerd́ 21 ottobre 2005 9.23
A: 'SPSSX-L@LISTSERV.UGA.EDU'
Oggetto: Creating cases genealogies
Dear All,
I have some data that indicate the dependencies between cases. More specifically, for each case I have data about the case that originate it (FatherId). I need to create genealogies, that is I need to add the variables Family and Level: while the earlier indicates genetical belongness from one individual to another, the latter assigns value 1 to the founder of the family, 2 to his/her son/daughter, 3 to his/her grandchildren/grandaughter, ecc.... (I can have up to several generations showing up in the database).
For instance, in the following sample data subject 2 is son/daugther of subject 3 and had has got one son/daugther - subject 5 - while subject 7 has got no traced father and no belongings:
DATA LIST LIST /SubjectId FatherId NrBelonging BirthDate.
BEGIN DATA
1 99 3 19471113
2 3 1 19701007
3 99 1 19650204
4 1 1 19720116
5 2 0 19980505
6 1 0 19750927
7 99 0 19270702
8 4 0 20030411
9 1 0 19781201
10 3 0 19951111
END DATA.
The data I have look like this:
SubjectId FatherId NrBelonging BirthDate
1,00 99,00 3,00 19471113
2,00 3,00 1,00 19701007
3,00 99,00 1,00 19650204
4,00 1,00 1,00 19720116
5,00 2,00 ,00 19980505
6,00 1,00 ,00 19750927
7,00 99,00 ,00 19270702
8,00 4,00 ,00 20030411
9,00 1,00 ,00 19781201
10,00 3,00 ,00 19951111
Number of cases read: 10 Number of cases listed: 10
The data I would like to obtain should look like this:
SubjectId FatherId NrBelonging BirthDate Family Level
1,00 99,00 3,00 19471113 1 1
2,00 3,00 1,00 19701007 2 2
3,00 99,00 1,00 19650204 3 1
4,00 1,00 1,00 19720116 1 2
5,00 2,00 ,00 19980505 2 3
6,00 1,00 ,00 19750927 1 2
7,00 99,00 ,00 19270702 4 1
8,00 4,00 ,00 20030411 1 3
9,00 1,00 ,00 19781201 1 2
10,00 3,00 ,00 19951111 3 3
Number of cases read: 9 Number of cases listed: 9
Anyone has already developed a similar procedure?
TIA,
Luca
Mr. Luca MEYER
Survey research, data analysis & more: http://www.lucameyer.com/
Tel: +390122854456 - Fax: +390122854837 - Mobile: + 393394950021
"If you can't feed a hundred people, then feed just one." - Mother Teresa - www.thehungersite.com
|