Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How to lengthen a number


From   Eric Booth <ebooth@ppri.tamu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to lengthen a number
Date   Wed, 10 Feb 2010 12:47:02 -0600

>

Use the 'fixed' format in Stata, e.g., 

*********
sysuse auto, clear

keep price 
format price %06.0f
tostring price, gen(p_string_version) format(%06.0f)

**now there is a numeric "price" with leading zeros
**up to 6 digits; and there is a string version

*********

~Eric


__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754


On Feb 10, 2010, at 12:37 PM, Nathan Hutto wrote:

> Hi all,
> 
> I have a numeric variable "x". Some of the values are 5 digits and
> others are 6 digits. I would like all of the values to be 6 digits, so
> I would like to add a zero to the beginning of the 5 digit values. I
> converted "x" to a string variable, created another string
> variable=="0" and added them together, but that didn't work. Anyone
> know how I can do this?
> 
> thank you,
> Nathan
> *
> *   For searches and help try:


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index