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 insert decimal point?


From   Lucie Vlach <Lucie.Vlach@albertahealthservices.ca>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: How to insert decimal point?
Date   Tue, 23 Aug 2011 15:19:07 -0600

Hello Rich!

Here is more detail:

The variable starts off as a string (type: str9, format: %9s), I then 'destring Claimed_Amount, replace' and it becomes numeric (type: long, format %10.0g). I just realized that when I destring it, the leading zeros do not display, but I still need to insert that decimal point 2 spaces from the right.

We did divide by 100 last week, but I thought that maybe there is a better way to insert that decimal point. A command that we can use in our DO file later. I tried all kinds of 'format' options, but I got everything but the right thing so far.

Lucie


________________________________________
From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] On Behalf Of Richard Goldstein [richgold@ix.netcom.com]
Sent: August 23, 2011 1:32 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: How to insert decimal point?

you don't tell us whether this is a number or a string variable; nor do
you tell us what the format is

if it is a number, divide by 100; if you need to change the format, see
-help format-

if it is a string and you want to leave it as a string, try the following:

replace
Claimed_Amount=substr(Claimed_Amount,1,7)+"."+substr(Claimed_Amount,8,2)

but note that this will make it 10 characters long; if you want it to
stay 9 characters, replace the "1" in the first substr() with a "2"
(assuming you won't lose any information that way)

Rich

On 8/23/11 3:21 PM, Lucie Vlach wrote:
> Hello all!
>
> I have a problem, trying to format my data in my 'Claimed_Amount' variable to say 0000051.61 (not 000005161) and 0000067.31 etc.
>
> I am trying to insert the decimal point, two spaces from the end, in this numeric variable.
> Each is number is 9 spaces long.
>
> 000005161 should display 0000051.61
>
> DATA:
> Claimed_Amount
> 000005161
> 000006731
> 000006666
> 000008890
> 000002256
> 000008301
> 000005161
> 000005161
> 000006731
> 000008890
> 000002256
> 000007449
> 000011889
> 000005879
> 000009019
> 000005161
> etc.
>
> Thank you all very much for any help!
>
> Lucie
*
*   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/

This message and any attached documents are only for the use of the intended recipient(s), are confidential and may contain privileged information. Any unauthorized review, use, retransmission, or other disclosure is strictly prohibited. If you have received this message in error, please notify the sender immediately, and then delete the original message. Thank you.

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