Statalist


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

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


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: How to make ID as 01 instead of 1
Date   Mon, 14 Dec 2009 13:46:59 +0100

<> 

You cannot -replace- the numeric variable because -replace- cannot promote
the data type to -string-. Just create a new variable, then:


*************
gen newx="0"+string(x)
*************

You could also -format- the numeric variable -format x %02.0f- to achieve a
similar effect, without changing the actual contents of the variable...


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Quang Nguyen
Gesendet: Montag, 14. Dezember 2009 13:45
An: [email protected]
Betreff: st: How to make ID as 01 instead of 1

Dear all:

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".

Any help is appreciated.

Sincerely yours,

Quang


--
"My father gave me the greatest gift anyone could give another person,
he believed in me." - Jim Valvano
*
*   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/


*
*   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