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

st: RE: RE: gen strN var2=string(var1, "%fmt") does not produce leading zeros


From   "Steichen, Thomas J." <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: gen strN var2=string(var1, "%fmt") does not produce leading zeros
Date   Fri, 15 Jul 2005 14:51:12 -0400

OK, the statalist line chopper got me...
The message should have read:

Try: format ndc %012.0f

(the zero after the % is what adds leading zeros).

Tom


Thomas J. Steichen
[email protected]
----------------------------------------------------------------------------
  Facts do not cease to exist because they are ignored. - Aldous Huxley
----------------------------------------------------------------------------



> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of 
> Steichen, Thomas J.
> Sent: Friday, July 15, 2005 2:48 PM
> To: [email protected]
> Subject: st: RE: gen strN var2=string(var1, "%fmt") does not 
> produce leading zeros
> 
> 
> (the zero after the % is what adds leading zeros).
> 
> Tom
> 
> Thomas J. Steichen
> [email protected]
> --------------------------------------------------------------
> --------------
>   Facts do not cease to exist because they are ignored. - 
> Aldous Huxley
> --------------------------------------------------------------
> --------------
> 
> 
> 
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]] On Behalf Of 
> Daniel Egan
> > Sent: Friday, July 15, 2005 2:41 PM
> > To: [email protected]
> > Subject: st: gen strN var2=string(var1, "%fmt") does not 
> > produce leading zeros
> > 
> > 
> > Hello all,
> > 
> > I hope this one gets in under the wire....
> > 
> > I am working with USA National Drug Codes (NDCs). The raw
> > format I have reads them in as a number between 7 and 12 
> digits long.
> > 
> > Actual NDC codes are (usually) of the form 12345-1234-12,
> > i.e. 5-4-2 digits, for a total of 13 inclusive of the two dashes.
> > 
> > So any numeric format with less than 11 digits is actually
> > that number with leading zeros.
> > 
> > I have read the FAQ at
> > http://www.stata.com/support/faqs/data/leading0.html , and 
> > followed the directions, but for some reason the resulting 
> > string does not have leading zeroes.
> > 
> > my code runs as follows:
> > ****************************
> > format ndc %12.0f
> > gen str12 sndc=string(ndc, "%12.0f")
> > gen sndclen=length(sndc)
> > tab sndclen, missing
> > 
> >   ndclength |      Freq.     Percent        Cum.
> > ------------+-----------------------------------
> >           7 |    559,577       10.42       10.42
> >           8 |  1,843,485       34.32       44.74
> >           9 |  1,917,644       35.70       80.44
> >          10 |        203        0.00       80.44
> >          11 |  1,047,475       19.50       99.94
> >          12 |      3,260        0.06      100.00
> > ------------+-----------------------------------
> >       Total |  5,371,644      100.00
> > *********************************
> > 
> > The 12-digit figures are actually missings (all 9's), so I
> > recoded them, reverted via "real", and then re-converted with 
> > -string- again...
> > 
> > *********
> > replace sndc="" if sndclen==12
> > gen ndc2=real(sndc)
> > gen str11 sndc2=string(ndc2, "%11.0f")
> > ***********
> > 
> > This does not return leading zero's either.
> > 
> > Any suggestions?
> > 
> > TIA,
> > 
> > Daniel Egan
> > 
> > 
> > 
> > ****************
> > Stata/SE 9.0 for Windows
> > Born 05 Jul 2005
> > Total physical memory:     2097151 KB
> > Available physical memory: 1425028 KB
> > 
> > Stata executable
> >     folder:               C:\Program Files\Stata9\
> >     name of file:         wsestata.exe
> >     currently installed:  05 Jul 2005
> > 
> > Ado-file updates
> >     folder:               C:\Program Files\Stata9\ado\updates\
> >     names of files:       (various)
> >     currently installed:  05 Jul 2005
> > ******************
> > 
> > *
> > *   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/
> > 
> 
> -----------------------------------------
> CONFIDENTIALITY NOTE:  This e-mail message, including any  
> attachment(s), contains information that may be confidential, 
>  protected by the attorney- client or other legal privileges, 
> and/or  proprietary non-public information.  If you are not 
> an intended  recipient of this message or an authorized 
> assistant to an intended  recipient, please notify the sender 
> by replying to this message and  then delete it from your 
> system.  Use, dissemination, distribution,  or reproduction 
> of this message and/or any of its attachments (if  any) by 
> unintended recipients is not authorized and may be unlawful.
> 
> 
> *
> *   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/
> 

-----------------------------------------
CONFIDENTIALITY NOTE:  This e-mail message, including any  attachment(s),
contains information that may be confidential,  protected by the attorney-
client or other legal privileges, and/or  proprietary non-public
information.  If you are not an intended  recipient of this message or an
authorized assistant to an intended  recipient, please notify the sender by
replying to this message and  then delete it from your system.  Use,
dissemination, distribution,  or reproduction of this message and/or any of
its attachments (if  any) by unintended recipients is not authorized and
may be unlawful.


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