Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[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" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
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 
n.j.cox@durham.ac.uk 

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 <quangn@gmail.com> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index