Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: add zero to values of variable


From   "Rosy Reynolds" <[email protected]>
To   <[email protected]>
Subject   st: Re: add zero to values of variable
Date   Sat, 3 Jun 2006 13:51:43 +0100

If the variable is numeric
replace x = x*10 if x<100
(trusting that you really do only have 2- and 3-digit positive values, so anything less than 100 is a 2-digit value)

or, if the variable is string,
replace x = x + "0" if length(s)==2

Rosy

----- Original Message ----- From: "raoul reulen" <[email protected]>
To: <[email protected]>
Sent: Saturday, June 03, 2006 1:15 PM
Subject: st: add zero to values of variable



Hi,

I have a variable which has 2-digit values and 3-values. I would like
to change all 2-digit values into 3 digits by adding a zero. How can
I do this? Thanks.

Raoul
see example below

the list of values looks like this:

12
148
456
21
364
390

and I would like to add a zero to the third and fourth values.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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