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 |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: AW: destring and set decimal and comma |

Date |
Wed, 11 Aug 2010 13:37:25 +0200 |

<> So this code should do exactly what you want. The only source of uncertainty here is the fact that we do not know how your strings find their way into Stata on your end, i.e. whether you -insheet- or -infix- or whatever. Hence the use of -input- to recreate your data on our end... ************* clear* //inputting data inp str15 num "72,000.00" "-1" "1,164.24" "-1" "179,857.26" "1,473,464.97" "9,900.00" "-1" end //code that changes data replace num=subinstr(num,",","",.) destring, replace form num %15.2fc set dp com //checking the result list, noobs ************* HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von ???s???a G?a?????p????? Gesendet: Mittwoch, 11. August 2010 12:07 An: statalist@hsphsun2.harvard.edu Betreff: st: destring and set decimal and comma Hi Statalist, I am facing a problem with destring a variable! My variable named "Dealvalue" has 72914 observations. It's type is str14! All observations are numbers. Some of them are missing, some have the value -1 and the rest of them are usually a very big number like 3,834,848.07 (here I have both comma and dot - in other cases "observations" I have either only comma or only dot or another combination different from this!!! Each observation of my variable, actually each value has different number of digits! So firstly, I would like to destring the variable "Dealvalue". I tried it with the below command (I dont know if it is right!) *** destring dealvalue, generate (dealvalue2) ignore (".,") **** The new variable "Dealvalue2" gives me just the values of "Dealvalue" but without dot and comma! dealvalue dealvalue2 72,000.00 7200000 -1 -1 1,164.24 116424 -1 -1 179,857.26 17985726 1,473,464.97 1,47E+08 9,900.00 990000 -1 -1 118,449.70 11844970 Secondly, I would like to set "," as the decimal point and the dot "." as the 1000 separator!! As I understand, I need a command that will start to reed the number from the end and after two digits to set comma and after three digits to set period. Something like this generally! But the value "-1 " is a specific case and need another command! Any idea please?? Yesterday, Martin suggested me the follow: ***** replace num = reverse(subinstr /// (reverse(num), ".", ",", 1)) destring num, replace ignore(.) dpcomma format num %9,0gc ***** Unfortunately, it doesn't work and I am not familiar with - subinstr - and even don'k know what "num" means. Have I to substitute my variable name there? I would be more than grateful if you send me exactly what I have to run with my variable names in order not to be confused and not disturb you all the time!!! Many thanks, Chrysoula * * 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/

**References**:**st: destring and set decimal and comma***From:*Χρυσούλα Γιαννικοπούλου <chrygiann@gmail.com>

- Prev by Date:
**RE: AW: st: a specific data management question** - Next by Date:
**Re: st: RE: AR(1) Test in panel data** - Previous by thread:
**st: AW: destring and set decimal and comma** - Index(es):