Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: statalist-digest V4 #976


From   baum <[email protected]>
To   [email protected]
Subject   st: Re: statalist-digest V4 #976
Date   Wed, 14 Aug 2002 08:31:40 -0400

--On Wednesday, August 14, 2002 2:33 -0400 Myima wrote:

I need to create a unique id variable by combining three
different numeric variables viz. "district", "house" and
"person". "District" has been entered as a four digit
number code (1000 to 1500). Each "District" has "house"s
numbered 1 to 150 (no zero in front) and each "house" has
"person" with numbers ranging from 1 to 12 (again no zero
in front). I need the uniqe id variable to merge this
dataset with another data file having other information
about these particular people.

As members may have figured out by now...I am new not only
to this list but to Stata too. I have tried looking for
help elsewhere...but the lack of Zeros in "house" and
"person" is giving me problems. Please help...

warm regards

Nyima
In this case you can get away with integer arithmetic, since the resulting code is within the range of a long:

g long code=district*100000+house*100+person


district house per~n code
1. 1000 10 1 100001001
2. 1001 150 2 100115002
3. 1002 2 6 100200206
4. 1003 22 12 100302212

But if the codes are longer than 8 digits, you will have to resort to strings. For your case it seems to work fine.

Kit

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index