Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Creating household id for groups of persons


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

Hans Meier <[email protected]>:

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
end
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 <[email protected]> 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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index