Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to eliminate "," thousand separator to destring a variable

    Hello everybody,


    I have downloaded some data that Stata (Stata 12 version) is not able to read as numeric because of the "," thousand separator. I run:
    destring rgdp2010, replace
    but I get the error:
    rgdp2010 contains nonnumeric characters; no replace
    how can I substitute "," with "" (nothing) in these observations?

    Thanks to anyone will help

  • #2

    See the help for destring for the ignore() option.

    Code:
    . clear
    
    . set obs 1
    number of observations (_N) was 0, now 1
    
    . gen problem = "1,234,567.8"
    
    . destring problem, gen(solution) ignore(",")
    problem: character , removed; solution generated as double
    
    . list
    
         +-------------------------+
         |     problem    solution |
         |-------------------------|
      1. | 1,234,567.8   1234567.8 |
         +-------------------------+
    Cross-posted at https://stackoverflow.com/questions/...-some-observat Our policy on cross-posting is explicit: you are asked to tell us about it.
    Last edited by Nick Cox; 24 Feb 2018, 02:06.

    Comment


    • #3
      Sorry, you are perfectly right. I didn't know anything about this. I will be careful next time, I will read about the rules of these forums.

      Comment

      Working...
      X