Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: adding leading zeros to variables


From   "Friedrich Huebler" <[email protected]>
To   [email protected]
Subject   Re: st: adding leading zeros to variables
Date   Sun, 3 Aug 2008 23:12:18 -0400

Murali,

You have to convert your variable to a string.

gen required = string(existing,"%09.0f")

This is explained in a FAQ.

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

Friedrich

On Sun, Aug 3, 2008 at 11:04 PM, Murali Kuchibhotla <[email protected]> wrote:
> Hello,
>      I need to create a 9-digit variable out of a variable that is currently
> 7 and 8 digits long by adding leading zeros to it. An example is provided
> below.
>
> existing        required
> 1234567         001234567
> 56789012        056789012
>
> Also, please note that in the actual dataset the exact no. of observations
> with either 7 or 8 digits is not known.Any suggestions would be
> appreciated.Thanks.
>
> Murali Kuchibhotla
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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