Hey there,
A straightforward question, I can't believe I spend so much time figuring this out.
This is the data
clear
input long(b1_01_personid b1_02_householdid) byte(l1_00_9_personnumber l1_05_3_spousenumber)
7433071 15862 1 2
7433072 15862 2 1
7433073 15862 3 -1
7434328 15865 3 -1
7434329 15865 1 2
7434330 15865 2 1
7434331 15865 4 -1
7432840 41911 1 -1
7432841 41911 2 -1
7432842 41911 3 -1
7433365 41912 2 3
7433366 41912 1 -1
7433367 41912 3 2
7434172 41914 3 -1
7434173 41914 1 2
7434174 41914 4 -1
7434175 41914 2 1
7435341 41920 3 -1
7435342 41920 6 5
7435343 41920 1 -1
7435344 41920 5 6
7435345 41920 2 -1
7435346 41920 4 -1
b1_01_personid - person id
b1_02_householdid - household id (persons are inside households)
l1_00_9_personnumber - the person's number within a household (starts with 1 for all households)
1_05_3_spousenumber - the person with this number is a spouse
Take, for example, household 15862
it has 3 individuals, And 7433071 is a spouse of 7433072 and verse versa. So I need to construct part_id
A straightforward question, I can't believe I spend so much time figuring this out.
This is the data
clear
input long(b1_01_personid b1_02_householdid) byte(l1_00_9_personnumber l1_05_3_spousenumber)
7433071 15862 1 2
7433072 15862 2 1
7433073 15862 3 -1
7434328 15865 3 -1
7434329 15865 1 2
7434330 15865 2 1
7434331 15865 4 -1
7432840 41911 1 -1
7432841 41911 2 -1
7432842 41911 3 -1
7433365 41912 2 3
7433366 41912 1 -1
7433367 41912 3 2
7434172 41914 3 -1
7434173 41914 1 2
7434174 41914 4 -1
7434175 41914 2 1
7435341 41920 3 -1
7435342 41920 6 5
7435343 41920 1 -1
7435344 41920 5 6
7435345 41920 2 -1
7435346 41920 4 -1
b1_01_personid - person id
b1_02_householdid - household id (persons are inside households)
l1_00_9_personnumber - the person's number within a household (starts with 1 for all households)
1_05_3_spousenumber - the person with this number is a spouse
Take, for example, household 15862
b1_01_personid | b1_02_householdid | l1_00_9_personnumber | l1_05_3_spousenumber |
7433071 | 15862 | 1 | 2 |
7433072 | 15862 | 2 | 1 |
7433073 | 15862 | 3 | -1 |
b1_01_personid | b1_02_householdid | l1_00_9_personnumber | l1_05_3_spousenumber | part_id |
7433071 | 15862 | 1 | 2 | 7433072 |
7433072 | 15862 | 2 | 1 | 7433071 |
7433073 | 15862 | 3 | -1 | . |
Comment