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]

RE: st: How to make ID as 01 instead of 1


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: How to make ID as 01 instead of 1
Date   Thu, 25 Feb 2010 17:04:36 -0000

The thread is a little cold here, but this advice can be improved on any way. 

If you want a string equivalent of a single-digit numeric identifier, then you can do it directly by 

gen strid = "0" + string(id) 

Firing up -tostring- is firing up a more general, fairly complicated command with hundreds of lines of code, and quite unnecessary here. 

However, this solution is not good For multiple digit identifiers. In that case, use -string()- with a format argument or just change the format so that leading zeros are displayed. These points were probably made in the thread in December. 

Nick 
[email protected] 

Hung Ðoàn Quang

You can try to use the following command
tostring ID, replace
gen strID = "0" + ID

It is hopeful that can help you.

On Mon, Dec 14, 2009 at 7:44 PM, Quang Nguyen <[email protected]> wrote:

> Can you show me how I can generate ID in the following manner: 01,
> 02..... instead of 1, 2, 3...?
>
> From the original data, I have ID in the form of 1, 2, ...... I then
> use the following commands:
>
> tostring ID, replace
> replace x = "01" if x=="1"
>
> There was a message "type mismatch".

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index