Announcement

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

  • Stata says I have non_numeric characters although all are numbers

    Hey Stata community,

    I want to destring a variable by the normal command:

    destring variable, gen(newvariable)

    Unfortunately, Stata tells me that I have non-numeric characters and that it can not destring the variable, although all characters are numbers. Maybe someone knows how to solve this problem.

    I already tried to list the non-numeric characters, but here again: nothing shown.

    Kind regards!

    Here is part of my dataset:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int PZN str5 preis str6(fb difference)
      655 "18,54" "18,55"  "-0,01"
     3056 "86,77" "108,89" "-22,12"
     3458 "86,94" "89,70"  "-2,76"
     5291 "17,21" "17,21"  "0,00"  
     5925 "17,21" "17,21"  "0,00"  
     6267 "51,94" "52,90"  "-0,96"
     7350 "32,32" "33,62"  "-1,30"
     8125 "26,31" "26,31"  "0,00"  
     8131 "35,37" "35,46"  "-0,09"
     8148 "57,27" "57,18"  "0,09"  
     9923 "18,79" "24,38"  "-5,59"
     9946 "27,98" "36,76"  "-8,78"
     9952 "11,94" "12,42"  "-0,48"
     9969 "13,05" "13,52"  "-0,47"
     9975 "13,61" "14,52"  "-0,91"
    10518 "29,65" "29,65"  "0,00"  
    10636 "52,65" "57,18"  "-4,53"
    10760 "20,83" "15,72"  "5,11"  
    10808 "15,85" "8,50"   "7,35"  
    11162 "28,07" "12,14"  "15,93"
    11280 "16,30" "12,32"  "3,98"  
    11297 "20,86" "12,89"  "7,97"  
    11305 "24,03" "14,04"  "9,99"  
    11788 "70,02" "70,08"  "-0,06"
    12486 "14,49" "15,95"  "-1,46"
    12813 "24,22" "24,22"  "0,00"  
    12842 "31,76" "31,76"  "0,00"  
    12931 "60,52" "67,96"  "-7,44"
    end

  • #2
    The comma is a non-numeric character. You have the option to ignore it.

    Code:
    destring variable, gen(newvariable) ignore(",")

    EDIT: Actually, do not ignore. You are using European format which has commas as decimals. The needed option is -dpcomma-


    Code:
    destring variable, gen(newvariable) dpcomma
    Last edited by Andrew Musau; 17 May 2021, 10:29.

    Comment


    • #3
      The comma here is probably a decimal comma. In Europe we use the comma for the decimal point and the period for indicating multiples of 1000. So you don't want to use ignore() instead you would want to use the dpcomma option:
      Code:
      destring variable, gen(newvariable) dpcomma
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Many of us also in Europe use stops or periods as decimal points.

        Comment


        • #5
          Didn't the UK leave Europe...
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            Thank you very much for all your answers!! It works now.

            Comment


            • #7
              Re #5. Probably meant tongue-in-cheek and I'm being ridiculous here. But, I have a really hard time resisting pedantry. The UK left the European Union. It didn't, and can't, by definition, leave Europe. I suspect some of the Brexit supporters wanted to leave Europe, but, alas for them, they can't. The UK isn't the only European country that is outside the EU. Switzerland comes first to my mind, but there are others, particularly in the east, like Russia. And let's not forget Norway.

              Comment


              • #8
                https://en.wikipedia.org/wiki/Decimal_separator has lots of information. As Clyde Schechter guessed, I was digressing on how Europe is not defined by EU membership and hinting at my own views on Brexit.

                Comment

                Working...
                X