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

st: AW: destring and set decimal and comma


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 12:20:17 +0200

<> 


You have to separate two issues: One is to transfer your initial data so
that Stata understands them. 

Once that has happened, you merely -format- the data without changing them.
See -h format- where you will find the command -set dp- which gives you the
comma as the representation of a decimal point. Also, as I said yesterday,
-format num %9,0gc- will see to it that you get your separator as you want
it. But bear in mind, all of the second part only affects how numbers are
displayed, not how Stata holds them internally.

And yes, to make my code work, change "num" to your -varname-. BTW, the
first part of yesterday`s code was T`s idea...



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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index