In my last posting, I should have added the advice that I always use: store
long ID #s as strings, not as numbers. Instead of generating a double or
long, try:
gen str10
id=string(var1)+string(var2,"%03.0f")+string(var3,"%04.0f")+string(var4,"%02
.0f")
(unwrap any text wrapping)
The second arguments specify the format, giving you the leading zeros you
want).
Michael Blasnik
[email protected]
----- Original Message -----
From: "Tesfayi Gebre" <[email protected]>
To: <[email protected]>
Sent: Monday, June 09, 2003 8:45 AM
Subject: st: Why does Stata do it wrong?
> Dear Statlister,
>
> I want to generate a single unique id to merge files
> by using variables: var1 (F1) var2 (F3) var3 (F4) and
> var4 (F2), where F shows the integer width (f format).
> So, I used
>
> gen id = var1*10^9 + var2*10^6 + var3*10^2 + var4
>
> This is the output from stata and the true id (as it
> should be) for the following
> example:
>
> var1 var2 var3 var4 id (stata) id (true)
> 1 2 3452 1 1005452032 1002345201
> 1 121 34 10 1121033984 1121003410
> 2 23 156 2 2023155968 2023015602
> 2 45 3 2 2045003008 2045000302
> 3 6 4 3 3006003968 3006000403
> 3 70 8 5 3070008064 3070000805
>
> Why is the stata id different from the true id? Does
> stata store numbers in different format?
>
> Thank you!
>
> Tesfayi
*
* 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/