Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: How to insert decimal point? |

Date |
Wed, 24 Aug 2011 07:49:41 +0100 |

You are confusing what a number is and how it is displayed. For example, Stata does not remove trailing zeros; it is just not displaying them with your format. You need to assign a format with leading zeros and two decimal places to get numbers displayed as you want. See -help format-. That said, you won't get exact arithmetic with such numeric variables unless your nunbers hold cents, not dollars. Nick On Tue, Aug 23, 2011 at 11:08 PM, Lucie Vlach <Lucie.Vlach@albertahealthservices.ca> wrote: > hello Rich! > > I tried your command for the string version and it worked! Thank you very much! > > I also tried to destring that _after_ your command, and it simply removed all zeros, and in some cases the decimal point, if the value was only 1. (original number 000000100) > > ------------------- > . replace Claimed_Amount=substr(Claimed_Amount,1,7)+"."+substr(Claimed_Amount,8,2) > Claimed_Amount was str9 now str10 > (27819 real changes made) > > . destring Claimed_Amount, replace > Claimed_Amount has all characters numeric; replaced as double > ------------------- > > I think I can live with that, basically in our data, 000005161 got changed to 0000051.61 though the first command and to 51.61 using 'destring' command. To us here it means $51.61 in plain language. > > Thank you! > > 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. >> * * 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/

**Follow-Ups**:**RE: st: How to insert decimal point?***From:*Lucie Vlach <Lucie.Vlach@albertahealthservices.ca>

**References**:**st: How to insert decimal point?***From:*Lucie Vlach <Lucie.Vlach@albertahealthservices.ca>

**Re: st: How to insert decimal point?***From:*Richard Goldstein <richgold@ix.netcom.com>

**RE: st: How to insert decimal point?***From:*Lucie Vlach <Lucie.Vlach@albertahealthservices.ca>

- Prev by Date:
**random effects logit model [was: st: From: Emma Gorman ...]** - Next by Date:
**Re: st: Nearest neighbor distance** - Previous by thread:
**RE: st: How to insert decimal point?** - Next by thread:
**RE: st: How to insert decimal point?** - Index(es):