Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: eliminating the nth digit of a numeric variable


From   Bill Rising <[email protected]>
To   "Stata Listserve" <[email protected]>
Subject   Re: st: RE: eliminating the nth digit of a numeric variable
Date   Thu, 27 Feb 2003 10:56:35 -0500

On 2/27/03 8:11, Nick Cox wrote

>Sanz De Galdeano, Anna
>> 
>> I have a numeric variable which takes, for instance, values like:
>> 
>> 1017
>> 273076
>> 518097
>> 3046
>> 
>> As you see, all these numbers have one thing in common: the 
>> third difit
>> starting from the right is always 0. That 0 should not be 
>> there and I want
>> to get rid of it so that my numeric variable looks like:
[the good solution using mod and int...]

Nick also gave a solution for replacing all 0's:

>
>	real(subinstr(string(myvar),"0","",1)) 
>

If it were known that the last zero were the evil zero, this could be 
done via:

real(reverse(subinstr(reverse(string(myvar,%30.0g)),"0","",1)))

(at least if the number is smaller than Stata's longs)


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