Hi All,

I am trying to follow households over time in a panel dataset. Currently, each individual has a unique ID, and households can be identified in a given year if each observation has the same "intnumber" within that given year. The family ID means that the family units represented come from the same family tree, but not necessarily that they are in the same household.

I would like to create a variable that uniquely identifies each household over time. In the below example, there are two separate households that come from the same famid #4. The two households can be seen containing members (shown by ID#) of (4003, 4031, 4173) and (4006, 4032, and 4170). What I would like is, for example, the household containing members 4003, 4031, and 4173 to be household #1 and then household containing members 4006, 4032, and 4170 to be household #2, as shown by a new variable.

Please let me know if this was explained in a clear way. Many thanks in advance!


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float ID int year float(famid intnumber Head Spouse Child)
4003 1986 4   595 1 . .
4031 1986 4   595 . . 1
4173 1986 4   595 . 1 .
4003 1985 4   645 1 . .
4031 1985 4   645 . . 1
4173 1985 4   645 . 1 .
4003 1990 4   983 1 . .
4031 1990 4   983 . . 1
4173 1990 4   983 . 1 .
4003 1988 4  1081 1 . .
4031 1988 4  1081 . . 1
4173 1988 4  1081 . 1 .
4006 1988 4  1216 . 1 .
4032 1988 4  1216 . . 1
4170 1988 4  1216 1 . .
4003 1989 4  1225 1 . .
4031 1989 4  1225 . . 1
4173 1989 4  1225 . 1 .
4006 1986 4  1310 . 1 .
4032 1986 4  1310 . . 1
4170 1986 4  1310 1 . .
4006 1985 4  1344 . 1 .
4032 1985 4  1344 . . 1
4170 1985 4  1344 1 . .
4006 1990 4  1757 . 1 .
4032 1990 4  1757 . . 1
4170 1990 4  1757 1 . .
4003 1984 4  2332 1 . .
4006 1987 4  2332 . 1 .
4031 1984 4  2332 . . 1
4032 1987 4  2332 . . 1
4170 1987 4  2332 1 . .
4173 1984 4  2332 . 1 .
4003 1987 4  2435 1 . .
4031 1987 4  2435 . . 1
4173 1987 4  2435 . 1 .
4003 1992 4  2482 1 . .
4031 1992 4  2482 . . 1
4173 1992 4  2482 . 1 .
4006 1984 4  3142 1 . .
4032 1984 4  3142 . . 1
4006 1989 4  3235 . 1 .
4032 1989 4  3235 . . 1
4170 1989 4  3235 1 . .
4003 1991 4  4379 1 . .
4031 1991 4  4379 . . 1
4173 1991 4  4379 . 1 .
4003 1993 4  4729 1 . .
4031 1993 4  4729 . . 1
4173 1993 4  4729 . 1 .
4003 1994 4 11733 1 . .
4031 1994 4 11733 . . 1
4173 1994 4 11733 . 1 .
end