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/