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]

From |
"Fernando Rios Avila" <f.rios.a@gmail.com> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: Creating household id for groups of persons |

Date |
Wed, 6 Jul 2011 12:59:26 -0400 |

Friedrich, My apologies. It is my fault to send the private message, but half of the time, I cant send a mail through the Majordomo System. Fernando PD. Hans, Your welcome -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Friedrich Huebler Sent: Wednesday, July 06, 2011 12:55 PM To: statalist@hsphsun2.harvard.edu Subject: Re: st: Creating household id for groups of persons Hans, Would you mind elaborating? Why does Austin's solution take hours and why is using SSC a problem? Thank you for sharing the message you received privately. This is an opportunity to remind list members that the Statalist FAQ discourages private messages: "Much of the benefit of Statalist is that an answer to a question might well interest other people. [...] it is usually better to post directly to Statalist." http://www.stata.com/support/faqs/res/statalist.html#private Friedrich On Wed, Jul 6, 2011 at 11:47 AM, Hans Meier <mr.hans.meier@web.de> wrote: > Hello Austin and Robert, > > thank you for your solutions. > I'm sure they would work, but I have a very large dataset, so Austins solution would take hours, and for Roberts solution I would have to use SSC. > > But another Stata user sent me this solution: > > Von: "Fernando Rios Avila" <f.rios.a@gmail.com> > Gesendet: 06.07.2011 15:18:00 > An: "'Hans Meier'" <mr.hans.meier@web.de> > Betreff: RE: st: Creating household id for groups of persons > >>Hi Hans, >>I was playing around with a very small sample similar to yours, and come up with this small code. >>Here hid3 would be the household id code. >> >> egen hid1=group (contract) >> bysort id: egen hid2=min(hid) >> bysort contract:egen hid3=min(hid2) >> >>Hope this is what u were looking for. >>Best > > > It works perfect, and very fast. > > Thank you Fernando! > > > > -----Ursprüngliche Nachricht----- > Von: "Robert Picard" <picard@netbox.com> > Gesendet: 06.07.2011 16:50:42 > An: statalist@hsphsun2.harvard.edu > Betreff: Re: st: Creating household id for groups of persons > >>Or get -group_id- from SSC. Using Austin's data: >> >>* --------------------- begin example --------------------- 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 >> >>clonevar gid = id >>group_id gid, match(contract) >> >>list , noobs clean >> >>* --------------------- begin example --------------------- >> >> >>On Wed, Jul 6, 2011 at 10:29 AM, Austin Nichols <austinnichols@gmail.com> wrote: >>> Hans Meier <mr.hans.meier@web.de>: >>> >>> 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 * * 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/ * * 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/

**References**:**Re: st: Creating household id for groups of persons***From:*"Hans Meier" <mr.hans.meier@web.de>

**Re: st: Creating household id for groups of persons***From:*Friedrich Huebler <fhuebler@gmail.com>

- Prev by Date:
**Re: st: Creating household id for groups of persons** - Next by Date:
**Re: st: Creating household id for groups of persons** - Previous by thread:
**Re: st: Creating household id for groups of persons** - Next by thread:
**st: Private emails to those active on Statalist** - Index(es):