Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Creating household id for groups of persons

From   Austin Nichols <>
Subject   Re: st: Creating household id for groups of persons
Date   Wed, 6 Jul 2011 10:29:11 -0400

Hans Meier <>:

Maybe this is what you want?

clear all
input contract id
 123  1
 123  2
 123  3
 456  4
 456  5
 678  1
 456  3
 789  6
 789  7
 456  8
g long obs=_n
egen long i=group(id)
la var i "Person id from 1 to M"
egen long gp=group(contract)
la var gp "Contract id from 1 to G"
bys i (gp):g long ct=sum(gp!=gp[_n-1])
la var ct "n distinct contract by id"
sort i ct
su i, mean
forv i=1/`r(max)' {
 su ct if i==`i', mean
 if r(max)==1 continue
 loc max=r(max)
 su gp if ct==1&i==`i', mean
 loc g1=r(max)
 forv j=2/`max' {
  su gp if ct==`j'&i==`i', mean
  replace gp=`g1' if gp==r(max)
sort obs
drop obs ct i
l, noo clean

On Wed, Jul 6, 2011 at 8:45 AM, Hans Meier <> wrote:
> Yes, now you got my question right.
> I don't know who lives in in which household, and I also don't have further information about this.
> But I assume, that if people have an insurance contract together, they are somehow connected and I define them as one household.
> (I look only at non-life insurance, no pension funds etc.)
> In my example, I define the persons from contract "123" (id's "1", "2", "3") as one household, let's say household A, and those in contract "456" (id's "4", "5") as another household B.
> Now, in contract "678", the id "1" tells me that this is the same person who is also in the contract "123", so I want this contract to be put in household A.
> To your question:
> Unfortunately,  I have a very large dataset, so I can't tell if I have one contract in each household that covers all household members.
> To err on the side of caution, I would rather assume I don't have such complete contracts.

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index