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

st: RE: RE: Leading Zero's


From   "Alexander Quarshie" <Alexander_Quarshie@msm.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Leading Zero's
Date   Tue, 01 Jul 2003 14:25:16 -0400

Thanks everyone. All your comments were very helpful.

Alex

Alexander Quarshie, MD, MS
Biostatistician
Clinical Research Center
Morehouse School of Medicine
720 Westview Dr. S.W.
Atlanta, GA 30310
(office) 404.752.8681
(fax) 404.752.1154
email:aquarshi@msm.edu

>>> n.j.cox@durham.ac.uk 07/01/03 02:21PM >>>
Alexander Quarshie, MD, MS

> Does anyone know a quick way in STATA to add leading zeros 
> to a numeric variable (even if I have to convert it to a 
> string, that would be okay). 
> A typical example might be to convert the following numbers 
> to a standard five-digit number with leading zeros:
> 2 -->  00002
> 33 --> 00033
> 473 --> 00473
> 59724 --> 59724

Display with leading zeros is a matter of format. 

di %05.0f 2 

A more fundamental change is 

gen str5 s_foo = string(foo,"%05.0f") 

Note that 

. search leading zero 

points to an FAQ 

http://www.stata.com/support/faqs/data/leading0.html 

so all this is one command line away in Stata. 

Nick 
n.j.cox@durham.ac.uk 

*
*   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/

BEGIN:VCARD
VERSION:2.1
X-GWTYPE:USER
FN:Quarshie, Alexander
EMAIL;WORK;PREF;NGW:aquarshi@msm.edu
N:Quarshie;Alexander
TITLE:Biostatistician
X-GWUSERID:aquarshi
END:VCARD




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