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 |
nigussie Tefera <nitefera@yahoo.com> |

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

Subject |
Re: st: Fwd: Constructing Household IDs |

Date |
Tue, 29 Jan 2013 23:50:34 -0800 (PST) |

Dear Andrea, Suppose each of them stand with a three digits identifiers, i.e. state has a maximum of three digits numerical values and so no. Simply, suppose you have 343 for sss, 213 for DDD, 567 for TTT … and at last you have 143 for HHH. So if you want to generate unique household id identifier of the form 343213567143, you can write the following simple command. gen double hhid=10^9*sss+10^6*DDD+10^3*TTT+HHH Note that 10^”x” could vary depending on the number of maximum digits that either of them have.... Best Nigussie ----- Original Message ----- From: Chamara Anuranga <kcanuranga@gmail.com> To: statalist@hsphsun2.harvard.edu Cc: Sent: Wednesday, January 30, 2013 10:23 AM Subject: Re: st: Fwd: Constructing Household IDs check all identifier variable and check the maximum length. state may be maximum 2 digits district may be 3 digits etc. add leading zeros to id variables base on maximum number format state %02.0f format district %03.0f here % to represent format, 0 to represent leading zero and .0 is no decimal places and f mean fix format then convert the variable to string. tostring state district,replace usedis then combine each string part using generate command gen hhid=state+district Thanks, Chamara On Wed, Jan 30, 2013 at 12:27 PM, Andrea Smurra <andrea.smurra@theigc.org> wrote: > Hello Statalists, > I am working with an household survey which doesn't have household IDs. > Each household is identified by a series of variables (State, district, > township, ..., household number). > Within each state, the numbering of districts always starts from the integer > 1, the same for towns within each district and so on up to the household in > each ward. > I tried to build unique HH identifier with the command "group", but I'd like > to build a HH ID which looks like SSSDDDTTT...HHH > where SSS is the state identifier (with the correct number of zeros appended > when necessary (i don't know how to do it)), DDD is the District identifier > and so on. I'm using STATA 12 for windows 7. I'm sure it will be an easy > task for an expert statalist, but I am still a beginner. > Thanks > Andrea > > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: Fwd: Constructing Household IDs***From:*Andrea Smurra <andrea.smurra@theigc.org>

**References**:**st: Fwd: Constructing Household IDs***From:*Andrea Smurra <andrea.smurra@theigc.org>

**Re: st: Fwd: Constructing Household IDs***From:*Chamara Anuranga <kcanuranga@gmail.com>

- Prev by Date:
**st: Problem with outreg** - Next by Date:
**Re: st: Problem with outreg** - Previous by thread:
**Re: st: Fwd: Constructing Household IDs** - Next by thread:
**Re: st: Fwd: Constructing Household IDs** - Index(es):