Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: destring and set decimal and comma

 From Χρυσούλα Γιαννικοπούλου To statalist@hsphsun2.harvard.edu Subject st: destring and set decimal and comma Date Wed, 11 Aug 2010 12:06:54 +0200

```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!

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/
```