Bookmark and Share

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]

SV: st: SV: leading zeros in string format


From   Petter Berg <[email protected]>
To   "[email protected]" <[email protected]>
Subject   SV: st: SV: leading zeros in string format
Date   Fri, 8 Feb 2013 20:57:08 +0100

That's probably because you have a string to start with. Start by destringing it.
________________________________________
Från: [email protected] [[email protected]] f&#246;r Michael Stewart [[email protected]]
Skickat: den 8 februari 2013 20:45
Till: [email protected]
Ämne: Re: st: SV: leading zeros in string format

I have tried it and get

type mismatch
r(109);


On Fri, Feb 8, 2013 at 2:41 PM, Petter Berg <[email protected]> wrote:
> Mike if you have a fixed string length (in this case of 7) and just want to fill up with zeros you can use:
> gen newstring  = string(oldvar,"%07.0f")
>
> Best,
> Petter
> ________________________________________
> Från: [email protected] [[email protected]] f&#246;r Michael Stewart [[email protected]]
> Skickat: den 8 februari 2013 20:24
> Till: [email protected]
> Ämne: st: leading zeros in string format
>
> HI
> I am trying to convert a string  variable to a string variable with
> fixed numbers
>
> My string variable has following observations:
> 1223435
> 34567
> 345
>
> I want to convert it to another string variable with leading zeros
> 1223435
> 0034567
> 0000345
>
> format var "%07.0f" didnt work
>
> Thank you ,
> Yours Sincerely,
> Mike.
> *
> *   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/



--
Thank you ,
Yours Sincerely,
Mike.

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index