Announcement

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

  • Convert variables to numeric

    Hello,
    I have the following dataset (below) and I want to convert the variables "tfertrate", "mofertrate", "tafertrate" to numeric. I tried to do it with the command "encode# but the numbers that appear in the upper bar in the data editor don´t match the values of the observations. Can you help me with the code to convert this observations to numeric
    Thank you in advance.

    ​​​​​​
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str31 territory int year str4 tfertrate str5(mofertrate fafertrate) long(tferrate motfertrate fatavrate)
    "Piemonte"                        1999 "1,12" "30,6"  "34,22" 12  43  30
    "Piemonte"                        2000 "1,17" "30,65" "34,31" 17  48  37
    "Piemonte"                        2001 "1,15" "30,68" "34,27" 15  50  35
    "Piemonte"                        2002 "1,2"  "30,73" "34,46" 20  55  48
    "Piemonte"                        2003 "1,22" "30,96" "34,64" 22  75  63
    "Piemonte"                        2004 "1,26" "30,81" "34,7"  26  61  67
    "Piemonte"                        2005 "1,27" "30,96" "34,78" 27  75  74
    "Piemonte"                        2006 "1,32" "30,95" "34,8"  32  74  76
    "Piemonte"                        2007 "1,37" "30,96" "34,81" 37  75  77
    "Piemonte"                        2008 "1,41" "31,07" "34,84" 41  85  80
    "Piemonte"                        2009 "1,42" "31,09" "34,87" 42  87  83
    "Piemonte"                        2010 "1,42" "31,15" "34,81" 42  93  77
    "Piemonte"                        2011 "1,43" "31,3"  "34,95" 43 108  91
    "Piemonte"                        2012 "1,43" "31,39" "34,99" 43 114  95
    "Piemonte"                        2013 "1,41" "31,45" "35,05" 41 119 101
    "Piemonte"                        2014 "1,41" "31,49" "35,06" 41 123 102
    "Piemonte"                        2015 "1,37" "31,69" "35,17" 37 142 112
    "Piemonte"                        2016 "1,36" "31,76" "35,25" 36 147 120
    "Piemonte"                        2017 "1,35" "31,82" "35,39" 35 152 133
    "Piemonte"                        2018 "1,3"  "31,94" "35,41" 30 161 135
    "Piemonte"                        2019 "1,27" "32,07" "35,63" 27 172 153
    "Piemonte"                        2020 "1,25" "32,16" "35,49" 25 180 141
    "Valle d'Aosta / Vallée d'Aoste" 1999 "1,19" "30,51" "33,89" 19  37  18
    "Valle d'Aosta / Vallée d'Aoste" 2000 "1,27" "30,53" "34,31" 27  38  37
    "Valle d'Aosta / Vallée d'Aoste" 2001 "1,22" "30,87" "34,57" 22  67  58
    "Valle d'Aosta / Vallée d'Aoste" 2002 "1,25" "30,38" "34,38" 25  32  42
    "Valle d'Aosta / Vallée d'Aoste" 2003 "1,28" "30,92" "34,73" 28  71  69
    "Valle d'Aosta / Vallée d'Aoste" 2004 "1,33" "30,93" "34,49" 33  72  51
    "Valle d'Aosta / Vallée d'Aoste" 2005 "1,34" "30,65" "34,44" 34  48  46
    "Valle d'Aosta / Vallée d'Aoste" 2006 "1,44" "31,12" "34,98" 44  90  94
    "Valle d'Aosta / Vallée d'Aoste" 2007 "1,47" "30,9"  "34,75" 47  69  71
    "Valle d'Aosta / Vallée d'Aoste" 2008 "1,57" "30,81" "34,6"  57  61  59
    "Valle d'Aosta / Vallée d'Aoste" 2009 "1,62" "30,99" "34,75" 62  78  71
    "Valle d'Aosta / Vallée d'Aoste" 2010 "1,62" "30,72" "34,33" 62  54  39
    "Valle d'Aosta / Vallée d'Aoste" 2011 "1,6"  "31,07" "34,96" 60  85  92
    "Valle d'Aosta / Vallée d'Aoste" 2012 "1,57" "31,18" "34,75" 57  96  71
    "Valle d'Aosta / Vallée d'Aoste" 2013 "1,44" "31,23" "35,01" 44 101  97
    "Valle d'Aosta / Vallée d'Aoste" 2014 "1,54" "31,68" "35"    54 141  96
    "Valle d'Aosta / Vallée d'Aoste" 2015 "1,41" "31,55" "35,17" 41 129 112
    "Valle d'Aosta / Vallée d'Aoste" 2016 "1,42" "31,64" "34,85" 42 137  81
    "Valle d'Aosta / Vallée d'Aoste" 2017 "1,35" "32,1"  "35,62" 35 174 152
    "Valle d'Aosta / Vallée d'Aoste" 2018 "1,39" "32,02" "35,62" 39 169 152
    "Valle d'Aosta / Vallée d'Aoste" 2019 "1,31" "32,14" "35,4"  31 178 134
    "Valle d'Aosta / Vallée d'Aoste" 2020 "1,23" "32,28" "35,68" 23 189 157
    "Liguria"                         1999 "0,99" "31,31" "34,98"  2 109  94
    "Liguria"                         2000 "1,04" "31,25" "35,06"  5 103 102
    "Liguria"                         2001 "1,06" "31,2"  "34,9"   6  98  86
    "Liguria"                         2002 "1,09" "31,35" "35,2"   9 111 115
    "Liguria"                         2003 "1,11" "31,45" "34,88" 11 119  84
    "Liguria"                         2004 "1,18" "31,23" "35,22" 18 101 117
    "Liguria"                         2005 "1,19" "31,31" "35,18" 19 109 113
    "Liguria"                         2006 "1,24" "31,41" "35,38" 24 116 132
    "Liguria"                         2007 "1,28" "31,36" "35,26" 28 112 121
    "Liguria"                         2008 "1,35" "31,24" "35,24" 35 102 119
    "Liguria"                         2009 "1,36" "31,49" "35,39" 36 123 133
    "Liguria"                         2010 "1,35" "31,52" "35,19" 35 126 114
    "Liguria"                         2011 "1,33" "31,55" "35,25" 33 129 120
    "Liguria"                         2012 "1,38" "31,48" "35,3"  38 122 125
    "Liguria"                         2013 "1,35" "31,58" "35,27" 35 132 122
    "Liguria"                         2014 "1,35" "31,74" "35,37" 35 145 131
    "Liguria"                         2015 "1,32" "31,81" "35,45" 32 151 137
    "Liguria"                         2016 "1,31" "31,87" "35,53" 31 155 145
    "Liguria"                         2017 "1,29" "32,01" "35,66" 29 168 155
    "Liguria"                         2018 "1,24" "31,95" "35,58" 24 162 150
    "Liguria"                         2019 "1,21" "32,21" "35,88" 21 185 172
    "Liguria"                         2020 "1,23" "32,17" "35,75" 23 181 163
    "Lombardia"                       1999 "1,16" "30,87" "34,53" 16  67  54
    "Lombardia"                       2000 "1,21" "30,95" "34,6"  21  74  59
    "Lombardia"                       2001 "1,22" "30,96" "34,6"  22  75  59
    "Lombardia"                       2002 "1,26" "30,94" "34,78" 26  73  74
    "Lombardia"                       2003 "1,27" "31,11" "34,86" 27  89  82
    "Lombardia"                       2004 "1,36" "30,93" "34,93" 36  72  89
    "Lombardia"                       2005 "1,37" "31,02" "34,98" 37  81  94
    "Lombardia"                       2006 "1,43" "31,02" "35,04" 43  81 100
    "Lombardia"                       2007 "1,47" "31,04" "35,02" 47  83  98
    "Lombardia"                       2008 "1,53" "31,04" "34,99" 53  83  95
    "Lombardia"                       2009 "1,56" "31,1"  "35,08" 56  88 104
    "Lombardia"                       2010 "1,56" "31,23" "35,15" 56 101 111
    "Lombardia"                       2011 "1,52" "31,39" "35,28" 52 114 123
    "Lombardia"                       2012 "1,51" "31,43" "35,34" 51 118 129
    "Lombardia"                       2013 "1,47" "31,53" "35,33" 47 127 128
    "Lombardia"                       2014 "1,46" "31,65" "35,4"  46 138 134
    "Lombardia"                       2015 "1,45" "31,79" "35,55" 45 149 147
    "Lombardia"                       2016 "1,43" "31,89" "35,54" 43 157 146
    "Lombardia"                       2017 "1,4"  "32,02" "35,7"  40 169 159
    "Lombardia"                       2018 "1,36" "32,13" "35,71" 36 177 160
    "Lombardia"                       2019 "1,33" "32,19" "35,81" 33 183 168
    "Lombardia"                       2020 "1,27" "32,31" "35,8"  27 192 167
    "Trentino Alto Adige / Südtirol" 1999 "1,45" "30,57" "34,6"  45  40  59
    "Trentino Alto Adige / Südtirol" 2000 "1,46" "30,64" "34,74" 46  47  70
    "Trentino Alto Adige / Südtirol" 2001 "1,46" "30,65" "34,68" 46  48  65
    "Trentino Alto Adige / Südtirol" 2002 "1,45" "30,74" "34,82" 45  56  78
    "Trentino Alto Adige / Südtirol" 2003 "1,46" "30,93" "34,96" 46  72  92
    "Trentino Alto Adige / Südtirol" 2004 "1,55" "30,94" "35,1"  55  73 106
    "Trentino Alto Adige / Südtirol" 2005 "1,55" "30,9"  "35,11" 55  69 107
    "Trentino Alto Adige / Südtirol" 2006 "1,54" "31,01" "35,17" 54  80 112
    "Trentino Alto Adige / Südtirol" 2007 "1,57" "31,02" "35,08" 57  81 104
    "Trentino Alto Adige / Südtirol" 2008 "1,61" "31,1"  "35,13" 61  88 109
    "Trentino Alto Adige / Südtirol" 2009 "1,58" "31,2"  "35,04" 58  98 100
    "Trentino Alto Adige / Südtirol" 2010 "1,63" "31,26" "35,18" 63 104 113
    end
    format %ty year
    label values tferrate tferrate
    label def tferrate 2 "0,99", modify
    label def tferrate 5 "1,04", modify
    label def tferrate 6 "1,06", modify
    label def tferrate 9 "1,09", modify
    label def tferrate 11 "1,11", modify
    label def tferrate 12 "1,12", modify
    label def tferrate 15 "1,15", modify
    label def tferrate 16 "1,16", modify
    label def tferrate 17 "1,17", modify
    label def tferrate 18 "1,18", modify
    label def tferrate 19 "1,19", modify
    label def tferrate 20 "1,2", modify
    label def tferrate 21 "1,21", modify
    label def tferrate 22 "1,22", modify
    label def tferrate 23 "1,23", modify
    label def tferrate 24 "1,24", modify
    label def tferrate 25 "1,25", modify
    label def tferrate 26 "1,26", modify
    label def tferrate 27 "1,27", modify
    label def tferrate 28 "1,28", modify
    label def tferrate 29 "1,29", modify
    label def tferrate 30 "1,3", modify
    label def tferrate 31 "1,31", modify
    label def tferrate 32 "1,32", modify
    label def tferrate 33 "1,33", modify
    label def tferrate 34 "1,34", modify
    label def tferrate 35 "1,35", modify
    label def tferrate 36 "1,36", modify
    label def tferrate 37 "1,37", modify
    label def tferrate 38 "1,38", modify
    label def tferrate 39 "1,39", modify
    label def tferrate 40 "1,4", modify
    label def tferrate 41 "1,41", modify
    label def tferrate 42 "1,42", modify
    label def tferrate 43 "1,43", modify
    label def tferrate 44 "1,44", modify
    label def tferrate 45 "1,45", modify
    label def tferrate 46 "1,46", modify
    label def tferrate 47 "1,47", modify
    label def tferrate 51 "1,51", modify
    label def tferrate 52 "1,52", modify
    label def tferrate 53 "1,53", modify
    label def tferrate 54 "1,54", modify
    label def tferrate 55 "1,55", modify
    label def tferrate 56 "1,56", modify
    label def tferrate 57 "1,57", modify
    label def tferrate 58 "1,58", modify
    label def tferrate 60 "1,6", modify
    label def tferrate 61 "1,61", modify
    label def tferrate 62 "1,62", modify
    label def tferrate 63 "1,63", modify
    label values motfertrate motfertrate
    label def motfertrate 32 "30,38", modify
    label def motfertrate 37 "30,51", modify
    label def motfertrate 38 "30,53", modify
    label def motfertrate 40 "30,57", modify
    label def motfertrate 43 "30,6", modify
    label def motfertrate 47 "30,64", modify
    label def motfertrate 48 "30,65", modify
    label def motfertrate 50 "30,68", modify
    label def motfertrate 54 "30,72", modify
    label def motfertrate 55 "30,73", modify
    label def motfertrate 56 "30,74", modify
    label def motfertrate 61 "30,81", modify
    label def motfertrate 67 "30,87", modify
    label def motfertrate 69 "30,9", modify
    label def motfertrate 71 "30,92", modify
    label def motfertrate 72 "30,93", modify
    label def motfertrate 73 "30,94", modify
    label def motfertrate 74 "30,95", modify
    label def motfertrate 75 "30,96", modify
    label def motfertrate 78 "30,99", modify
    label def motfertrate 80 "31,01", modify
    label def motfertrate 81 "31,02", modify
    label def motfertrate 83 "31,04", modify
    label def motfertrate 85 "31,07", modify
    label def motfertrate 87 "31,09", modify
    label def motfertrate 88 "31,1", modify
    label def motfertrate 89 "31,11", modify
    label def motfertrate 90 "31,12", modify
    label def motfertrate 93 "31,15", modify
    label def motfertrate 96 "31,18", modify
    label def motfertrate 98 "31,2", modify
    label def motfertrate 101 "31,23", modify
    label def motfertrate 102 "31,24", modify
    label def motfertrate 103 "31,25", modify
    label def motfertrate 104 "31,26", modify
    label def motfertrate 108 "31,3", modify
    label def motfertrate 109 "31,31", modify
    label def motfertrate 111 "31,35", modify
    label def motfertrate 112 "31,36", modify
    label def motfertrate 114 "31,39", modify
    label def motfertrate 116 "31,41", modify
    label def motfertrate 118 "31,43", modify
    label def motfertrate 119 "31,45", modify
    label def motfertrate 122 "31,48", modify
    label def motfertrate 123 "31,49", modify
    label def motfertrate 126 "31,52", modify
    label def motfertrate 127 "31,53", modify
    label def motfertrate 129 "31,55", modify
    label def motfertrate 132 "31,58", modify
    label def motfertrate 137 "31,64", modify
    label def motfertrate 138 "31,65", modify
    label def motfertrate 141 "31,68", modify
    label def motfertrate 142 "31,69", modify
    label def motfertrate 145 "31,74", modify
    label def motfertrate 147 "31,76", modify
    label def motfertrate 149 "31,79", modify
    label def motfertrate 151 "31,81", modify
    label def motfertrate 152 "31,82", modify
    label def motfertrate 155 "31,87", modify
    label def motfertrate 157 "31,89", modify
    label def motfertrate 161 "31,94", modify
    label def motfertrate 162 "31,95", modify
    label def motfertrate 168 "32,01", modify
    label def motfertrate 169 "32,02", modify
    label def motfertrate 172 "32,07", modify
    label def motfertrate 174 "32,1", modify
    label def motfertrate 177 "32,13", modify
    label def motfertrate 178 "32,14", modify
    label def motfertrate 180 "32,16", modify
    label def motfertrate 181 "32,17", modify
    label def motfertrate 183 "32,19", modify
    label def motfertrate 185 "32,21", modify
    label def motfertrate 189 "32,28", modify
    label def motfertrate 192 "32,31", modify
    label values fatavrate fatavrate
    label def fatavrate 18 "33,89", modify
    label def fatavrate 30 "34,22", modify
    label def fatavrate 35 "34,27", modify
    label def fatavrate 37 "34,31", modify
    label def fatavrate 39 "34,33", modify
    label def fatavrate 42 "34,38", modify
    label def fatavrate 46 "34,44", modify
    label def fatavrate 48 "34,46", modify
    label def fatavrate 51 "34,49", modify
    label def fatavrate 54 "34,53", modify
    label def fatavrate 58 "34,57", modify
    label def fatavrate 59 "34,6", modify
    label def fatavrate 63 "34,64", modify
    label def fatavrate 65 "34,68", modify
    label def fatavrate 67 "34,7", modify
    label def fatavrate 69 "34,73", modify
    label def fatavrate 70 "34,74", modify
    label def fatavrate 71 "34,75", modify
    label def fatavrate 74 "34,78", modify
    label def fatavrate 76 "34,8", modify
    label def fatavrate 77 "34,81", modify
    label def fatavrate 78 "34,82", modify
    label def fatavrate 80 "34,84", modify
    label def fatavrate 81 "34,85", modify
    label def fatavrate 82 "34,86", modify
    label def fatavrate 83 "34,87", modify
    label def fatavrate 84 "34,88", modify
    label def fatavrate 86 "34,9", modify
    label def fatavrate 89 "34,93", modify
    label def fatavrate 91 "34,95", modify
    label def fatavrate 92 "34,96", modify
    label def fatavrate 94 "34,98", modify
    label def fatavrate 95 "34,99", modify
    label def fatavrate 96 "35", modify
    label def fatavrate 97 "35,01", modify
    label def fatavrate 98 "35,02", modify
    label def fatavrate 100 "35,04", modify
    label def fatavrate 101 "35,05", modify
    label def fatavrate 102 "35,06", modify
    label def fatavrate 104 "35,08", modify
    label def fatavrate 106 "35,1", modify
    label def fatavrate 107 "35,11", modify
    label def fatavrate 109 "35,13", modify
    label def fatavrate 111 "35,15", modify
    label def fatavrate 112 "35,17", modify
    label def fatavrate 113 "35,18", modify
    label def fatavrate 114 "35,19", modify
    label def fatavrate 115 "35,2", modify
    label def fatavrate 117 "35,22", modify
    label def fatavrate 119 "35,24", modify
    label def fatavrate 120 "35,25", modify
    label def fatavrate 121 "35,26", modify
    label def fatavrate 122 "35,27", modify
    label def fatavrate 123 "35,28", modify
    label def fatavrate 125 "35,3", modify
    label def fatavrate 128 "35,33", modify
    label def fatavrate 129 "35,34", modify
    label def fatavrate 131 "35,37", modify
    label def fatavrate 132 "35,38", modify
    label def fatavrate 133 "35,39", modify
    label def fatavrate 134 "35,4", modify
    label def fatavrate 135 "35,41", modify
    label def fatavrate 137 "35,45", modify
    label def fatavrate 141 "35,49", modify
    label def fatavrate 145 "35,53", modify
    label def fatavrate 146 "35,54", modify
    label def fatavrate 147 "35,55", modify
    label def fatavrate 150 "35,58", modify
    label def fatavrate 152 "35,62", modify
    label def fatavrate 153 "35,63", modify
    label def fatavrate 155 "35,66", modify
    label def fatavrate 157 "35,68", modify
    label def fatavrate 159 "35,7", modify
    label def fatavrate 160 "35,71", modify
    label def fatavrate 163 "35,75", modify
    label def fatavrate 167 "35,8", modify
    label def fatavrate 168 "35,81", modify
    label def fatavrate 172 "35,88", modify
    Last edited by Ana Vasconcelos; 16 Jun 2022, 16:54. Reason: For what I understood I have value labeled variables and I need actual numbers. Can you help me with this

  • #2
    Those are value labels. Try:

    Code:
    foreach var in tferrate motfertrate fatavrate{
        decode `var', g(`var'_n)
        destring `var'_n, replace dpcomma
    }

    Comment


    • #3
      Thank you very much! It´s perfect now.

      Comment


      • #4
        The same point was made in your previous thread https://www.statalist.org/forums/for...aphs-by-groups

        Comment


        • #5
          Hello,

          Although the code worket to convert some of the variables, there are three variables that I´m not being able to convert: "pollution", "noise" and "criminality".
          They are stored in excatly the same way as the others but the command it´s not working. Can you help me with this?
          I send the example of the data below. Thank you very much in advance.
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input str34 territory int year str4(pollution noise criminality) long(pol noi crim) str4(pol_n noi_n crim_n)
          "Piemonte"                           2004 "25,4" "25,7" "15,5" 117 127  49 "25,4" "25,7" "15,5"
          "Piemonte"                           2005 "24"   "23,8" "15,3" 112 111  47 "24"   "23,8" "15,3"
          "Piemonte"                           2006 "22,8" "24,5" "17,7" 107 115  63 "22,8" "24,5" "17,7"
          "Piemonte"                           2007 "21,3" "25,6" "19,8"  98 126  76 "21,3" "25,6" "19,8"
          "Piemonte"                           2008 "22,4" "26,9" "20,6" 105 137  79 "22,4" "26,9" "20,6"
          "Piemonte"                           2009 "22,3" "24,2" "14,8" 104 114  44 "22,3" "24,2" "14,8"
          "Piemonte"                           2010 "19,3" "25,3" "14,7"  81 123  43 "19,3" "25,3" "14,7"
          "Piemonte"                           2011 "14,2" "16,7" "11,8"  36  53  19 "14,2" "16,7" "11,8"
          "Piemonte"                           2012 "12,4" "13,4" "10,5"  21  26   7 "12,4" "13,4" "10,5"
          "Piemonte"                           2013 "16,7" "17,9" "15,6"  60  63  50 "16,7" "17,9" "15,6"
          "Piemonte"                           2014 "15,9" "16,2" "16,2"  52  49  55 "15,9" "16,2" "16,2"
          "Piemonte"                           2015 "17,1" "18,7" "19,4"  64  70  74 "17,1" "18,7" "19,4"
          "Piemonte"                           2016 "11,8" "13,2" "12,5"  15  24  25 "11,8" "13,2" "12,5"
          "Piemonte"                           2017 "9,2"  "10,6" "8,6"  166   8 138 "9,2"  "10,6" "8,6" 
          "Piemonte"                           2018 "8,5"  "12,6" "7,3"  161  21 128 "8,5"  "12,6" "7,3" 
          "Piemonte"                           2019 "10,4" "14,7" "10,3"   5  37   5 "10,4" "14,7" "10,3"
          "Valle d'Aosta / Vallée d'Aoste"    2004 "8,1"  "15,9" "5,4"  158  47 113 "8,1"  "15,9" "5,4" 
          "Valle d'Aosta / Vallée d'Aoste"    2005 "10,7" "17,3" ".."     7  59   1 "10,7" "17,3" ".."  
          "Valle d'Aosta / Vallée d'Aoste"    2006 "8"    "18,9" "5,4"  157  72 113 "8"    "18,9" "5,4" 
          "Valle d'Aosta / Vallée d'Aoste"    2007 "6,9"  "17,3" "7,2"  148  59 127 "6,9"  "17,3" "7,2" 
          "Valle d'Aosta / Vallée d'Aoste"    2008 "9,5"  "13,3" "4,8"  169  25 108 "9,5"  "13,3" "4,8" 
          "Valle d'Aosta / Vallée d'Aoste"    2009 "12,3" "20,2" "12,5"  20  82  25 "12,3" "20,2" "12,5"
          "Valle d'Aosta / Vallée d'Aoste"    2010 "8,4"  "18,7" "8,5"  160  70 137 "8,4"  "18,7" "8,5" 
          "Valle d'Aosta / Vallée d'Aoste"    2011 "11,3" "16,3" "7,4"   12  50 129 "11,3" "16,3" "7,4" 
          "Valle d'Aosta / Vallée d'Aoste"    2012 "17,7" "15,5" "14,8"  69  44  44 "17,7" "15,5" "14,8"
          "Valle d'Aosta / Vallée d'Aoste"    2013 "10,6" "10,6" "9,6"    6   8 147 "10,6" "10,6" "9,6" 
          "Valle d'Aosta / Vallée d'Aoste"    2014 "15,1" "18,6" "13,1"  44  69  29 "15,1" "18,6" "13,1"
          "Valle d'Aosta / Vallée d'Aoste"    2015 "9,7"  "14,4" "15,1" 171  34  46 "9,7"  "14,4" "15,1"
          "Valle d'Aosta / Vallée d'Aoste"    2016 "5,8"  "6,1"  ".."   142 164   1 "5,8"  "6,1"  ".."  
          "Valle d'Aosta / Vallée d'Aoste"    2017 ".."   ".."   "4"      1   1 102 ".."   ".."   "4"   
          "Valle d'Aosta / Vallée d'Aoste"    2018 ".."   ".."   ".."     1   1   1 ".."   ".."   ".."  
          "Valle d'Aosta / Vallée d'Aoste"    2019 ".."   ".."   ".."     1   1   1 ".."   ".."   ".."  
          "Liguria"                            2004 "22,8" "26,3" "14,8" 107 132  44 "22,8" "26,3" "14,8"
          "Liguria"                            2005 "20,6" "24,8" "10,2"  93 118   4 "20,6" "24,8" "10,2"
          "Liguria"                            2006 "16,5" "18,5" "10,9"  58  68  11 "16,5" "18,5" "10,9"
          "Liguria"                            2007 "17,3" "19,8" "14"    66  79  37 "17,3" "19,8" "14"  
          "Liguria"                            2008 "18,7" "21,4" "11,1"  76  93  13 "18,7" "21,4" "11,1"
          "Liguria"                            2009 "20,4" "25"   "12,6"  91 120  26 "20,4" "25"   "12,6"
          "Liguria"                            2010 "15,9" "19,4" "7,5"   52  76 130 "15,9" "19,4" "7,5" 
          "Liguria"                            2011 "17,8" "23,8" "12,4"  70 111  24 "17,8" "23,8" "12,4"
          "Liguria"                            2012 "17,4" "21,1" "11,8"  67  90  19 "17,4" "21,1" "11,8"
          "Liguria"                            2013 "16,5" "23,1" "14"    58 105  37 "16,5" "23,1" "14"  
          "Liguria"                            2014 "15,5" "22,7" "12,5"  48 102  25 "15,5" "22,7" "12,5"
          "Liguria"                            2015 "14,6" "21,9" "13,6"  39  94  33 "14,6" "21,9" "13,6"
          "Liguria"                            2016 "17,3" "20,5" "12,5"  66  85  25 "17,3" "20,5" "12,5"
          "Liguria"                            2017 "13,5" "15"   "11,2"  29  39  14 "13,5" "15"   "11,2"
          "Liguria"                            2018 "11,6" "10,7" "9,1"   14   9 143 "11,6" "10,7" "9,1" 
          "Liguria"                            2019 "15,2" "15,6" "9,2"   45  45 144 "15,2" "15,6" "9,2" 
          "Lombardia"                          2004 "25,7" "26,9" "15,9" 120 137  53 "25,7" "26,9" "15,9"
          "Lombardia"                          2005 "26,7" "25,1" "13,6" 121 121  33 "26,7" "25,1" "13,6"
          "Lombardia"                          2006 "25,4" "24"   "14,5" 117 112  41 "25,4" "24"   "14,5"
          "Lombardia"                          2007 "24,9" "25,8" "16,6" 115 128  58 "24,9" "25,8" "16,6"
          "Lombardia"                          2008 "22,8" "25,7" "12,4" 107 127  24 "22,8" "25,7" "12,4"
          "Lombardia"                          2009 "24,4" "25,8" "14,8" 114 128  44 "24,4" "25,8" "14,8"
          "Lombardia"                          2010 "20"   "23,5" "11,6"  87 109  17 "20"   "23,5" "11,6"
          "Lombardia"                          2011 "23"   "23,5" "18"   108 109  66 "23"   "23,5" "18"  
          "Lombardia"                          2012 "21,6" "20"   "19,3" 100  80  73 "21,6" "20"   "19,3"
          "Lombardia"                          2013 "17,2" "18,4" "18,8"  65  67  70 "17,2" "18,4" "18,8"
          "Lombardia"                          2014 "16,9" "18,2" "17,9"  62  65  65 "16,9" "18,2" "17,9"
          "Lombardia"                          2015 "17"   "18,1" "18"    63  64  66 "17"   "18,1" "18"  
          "Lombardia"                          2016 "15,2" "17,9" "15,1"  45  63  46 "15,2" "17,9" "15,1"
          "Lombardia"                          2017 "12,2" "13,8" "13,2"  19  30  30 "12,2" "13,8" "13,2"
          "Lombardia"                          2018 "13,7" "13,8" "10,8"  31  30  10 "13,7" "13,8" "10,8"
          "Lombardia"                          2019 "15"   "14,1" "10,5"  43  32   7 "15"   "14,1" "10,5"
          "Provincia Autonoma Bolzano / Bozen" 2004 "19,9" "22,3" "3,7"   86  98  95 "19,9" "22,3" "3,7" 
          "Provincia Autonoma Bolzano / Bozen" 2005 "19"   "25,8" "4,1"   78 128 103 "19"   "25,8" "4,1" 
          "Provincia Autonoma Bolzano / Bozen" 2006 "19,4" "24,6" ".."    82 116   1 "19,4" "24,6" ".."  
          "Provincia Autonoma Bolzano / Bozen" 2007 "16,1" "21,2" "4,3"   54  91 105 "16,1" "21,2" "4,3" 
          "Provincia Autonoma Bolzano / Bozen" 2008 "16,1" "22,5" "4,9"   54 100 109 "16,1" "22,5" "4,9" 
          "Provincia Autonoma Bolzano / Bozen" 2009 "11,3" "22"   ".."    12  95   1 "11,3" "22"   ".."  
          "Provincia Autonoma Bolzano / Bozen" 2010 "9,6"  "16,7" "5,7"  170  53 114 "9,6"  "16,7" "5,7" 
          "Provincia Autonoma Bolzano / Bozen" 2011 "8,9"  "13,4" "7,5"  164  26 130 "8,9"  "13,4" "7,5" 
          "Provincia Autonoma Bolzano / Bozen" 2012 "14,9" "18,7" "8"     42  70 132 "14,9" "18,7" "8"   
          "Provincia Autonoma Bolzano / Bozen" 2013 "15,8" "20,9" ".."    51  89   1 "15,8" "20,9" ".."  
          "Provincia Autonoma Bolzano / Bozen" 2014 "9,7"  "16,5" "14,1" 171  51  38 "9,7"  "16,5" "14,1"
          "Provincia Autonoma Bolzano / Bozen" 2015 "11,8" "18,4" "9,8"   15  67 149 "11,8" "18,4" "9,8" 
          "Provincia Autonoma Bolzano / Bozen" 2016 "6,4"  "7,3"  "9,2"  146 172 144 "6,4"  "7,3"  "9,2" 
          "Provincia Autonoma Bolzano / Bozen" 2017 ".."   "5,5"  ".."     1 160   1 ".."   "5,5"  ".."  
          "Provincia Autonoma Bolzano / Bozen" 2018 "9,2"  "13,8" "6,8"  166  30 124 "9,2"  "13,8" "6,8" 
          "Provincia Autonoma Bolzano / Bozen" 2019 "7,9"  "9,4"  "9,7"  156 183 148 "7,9"  "9,4"  "9,7" 
          "Provincia Autonoma Trento"          2004 "14,9" "18,9" ".."    42  72   1 "14,9" "18,9" ".."  
          "Provincia Autonoma Trento"          2005 "16,1" "17,3" ".."    54  59   1 "16,1" "17,3" ".."  
          "Provincia Autonoma Trento"          2006 "12,3" "17,5" ".."    20  61   1 "12,3" "17,5" ".."  
          "Provincia Autonoma Trento"          2007 "12,4" "16,2" "5,4"   21  49 113 "12,4" "16,2" "5,4" 
          "Provincia Autonoma Trento"          2008 "14,1" "19,8" "5,4"   35  79 113 "14,1" "19,8" "5,4" 
          "Provincia Autonoma Trento"          2009 "11,1" "17,7" "5,1"   11  62 111 "11,1" "17,7" "5,1" 
          "Provincia Autonoma Trento"          2010 "8,6"  "17,2" ".."   162  58   1 "8,6"  "17,2" ".."  
          "Provincia Autonoma Trento"          2011 "7,2"  "10,2" ".."   151   4   1 "7,2"  "10,2" ".."  
          "Provincia Autonoma Trento"          2012 "7,3"  "7,2"  "4,9"  152 171 109 "7,3"  "7,2"  "4,9" 
          "Provincia Autonoma Trento"          2013 "6,1"  "8,7"  ".."   144 178   1 "6,1"  "8,7"  ".."  
          "Provincia Autonoma Trento"          2014 ".."   ".."   ".."     1   1   1 ".."   ".."   ".."  
          "Provincia Autonoma Trento"          2015 ".."   "6,6"  "6,2"    1 167 118 ".."   "6,6"  "6,2" 
          "Provincia Autonoma Trento"          2016 "4,6"  "6,9"  "5"    137 169 110 "4,6"  "6,9"  "5"   
          "Provincia Autonoma Trento"          2017 ".."   "5,8"  ".."     1 162   1 ".."   "5,8"  ".."  
          "Provincia Autonoma Trento"          2018 ".."   "4"    ".."     1 158   1 ".."   "4"    ".."  
          "Provincia Autonoma Trento"          2019 "5,6"  "5,2"  "5,7"  141 159 114 "5,6"  "5,2"  "5,7" 
          "Veneto"                             2004 "20,8" "24,9" "10,6"  95 119   8 "20,8" "24,9" "10,6"
          "Veneto"                             2005 "20,7" "25,6" "10,5"  94 126   7 "20,7" "25,6" "10,5"
          "Veneto"                             2006 "21,2" "25"   "10,2"  97 120   4 "21,2" "25"   "10,2"
          "Veneto"                             2007 "20,5" "26,3" "12,1"  92 132  22 "20,5" "26,3" "12,1"
          end
          label values pol pol
          label def pol 1 "..", modify
          label def pol 5 "10,4", modify
          label def pol 6 "10,6", modify
          label def pol 7 "10,7", modify
          label def pol 11 "11,1", modify
          label def pol 12 "11,3", modify
          label def pol 14 "11,6", modify
          label def pol 15 "11,8", modify
          label def pol 19 "12,2", modify
          label def pol 20 "12,3", modify
          label def pol 21 "12,4", modify
          label def pol 29 "13,5", modify
          label def pol 31 "13,7", modify
          label def pol 35 "14,1", modify
          label def pol 36 "14,2", modify
          label def pol 39 "14,6", modify
          label def pol 42 "14,9", modify
          label def pol 43 "15", modify
          label def pol 44 "15,1", modify
          label def pol 45 "15,2", modify
          label def pol 48 "15,5", modify
          label def pol 51 "15,8", modify
          label def pol 52 "15,9", modify
          label def pol 54 "16,1", modify
          label def pol 58 "16,5", modify
          label def pol 60 "16,7", modify
          label def pol 62 "16,9", modify
          label def pol 63 "17", modify
          label def pol 64 "17,1", modify
          label def pol 65 "17,2", modify
          label def pol 66 "17,3", modify
          label def pol 67 "17,4", modify
          label def pol 69 "17,7", modify
          label def pol 70 "17,8", modify
          label def pol 76 "18,7", modify
          label def pol 78 "19", modify
          label def pol 81 "19,3", modify
          label def pol 82 "19,4", modify
          label def pol 86 "19,9", modify
          label def pol 87 "20", modify
          label def pol 91 "20,4", modify
          label def pol 92 "20,5", modify
          label def pol 93 "20,6", modify
          label def pol 94 "20,7", modify
          label def pol 95 "20,8", modify
          label def pol 97 "21,2", modify
          label def pol 98 "21,3", modify
          label def pol 100 "21,6", modify
          label def pol 104 "22,3", modify
          label def pol 105 "22,4", modify
          label def pol 107 "22,8", modify
          label def pol 108 "23", modify
          label def pol 112 "24", modify
          label def pol 114 "24,4", modify
          label def pol 115 "24,9", modify
          label def pol 117 "25,4", modify
          label def pol 120 "25,7", modify
          label def pol 121 "26,7", modify
          label def pol 137 "4,6", modify
          label def pol 141 "5,6", modify
          label def pol 142 "5,8", modify
          label def pol 144 "6,1", modify
          label def pol 146 "6,4", modify
          label def pol 148 "6,9", modify
          label def pol 151 "7,2", modify
          label def pol 152 "7,3", modify
          label def pol 156 "7,9", modify
          label def pol 157 "8", modify
          label def pol 158 "8,1", modify
          label def pol 160 "8,4", modify
          label def pol 161 "8,5", modify
          label def pol 162 "8,6", modify
          label def pol 164 "8,9", modify
          label def pol 166 "9,2", modify
          label def pol 169 "9,5", modify
          label def pol 170 "9,6", modify
          label def pol 171 "9,7", modify
          label values noi noi
          label def noi 1 "..", modify
          label def noi 4 "10,2", modify
          label def noi 8 "10,6", modify
          label def noi 9 "10,7", modify
          label def noi 21 "12,6", modify
          label def noi 24 "13,2", modify
          label def noi 25 "13,3", modify
          label def noi 26 "13,4", modify
          label def noi 30 "13,8", modify
          label def noi 32 "14,1", modify
          label def noi 34 "14,4", modify
          label def noi 37 "14,7", modify
          label def noi 39 "15", modify
          label def noi 44 "15,5", modify
          label def noi 45 "15,6", modify
          label def noi 47 "15,9", modify
          label def noi 49 "16,2", modify
          label def noi 50 "16,3", modify
          label def noi 51 "16,5", modify
          label def noi 53 "16,7", modify
          label def noi 58 "17,2", modify
          label def noi 59 "17,3", modify
          label def noi 61 "17,5", modify
          label def noi 62 "17,7", modify
          label def noi 63 "17,9", modify
          label def noi 64 "18,1", modify
          label def noi 65 "18,2", modify
          label def noi 67 "18,4", modify
          label def noi 68 "18,5", modify
          label def noi 69 "18,6", modify
          label def noi 70 "18,7", modify
          label def noi 72 "18,9", modify
          label def noi 76 "19,4", modify
          label def noi 79 "19,8", modify
          label def noi 80 "20", modify
          label def noi 82 "20,2", modify
          label def noi 85 "20,5", modify
          label def noi 89 "20,9", modify
          label def noi 90 "21,1", modify
          label def noi 91 "21,2", modify
          label def noi 93 "21,4", modify
          label def noi 94 "21,9", modify
          label def noi 95 "22", modify
          label def noi 98 "22,3", modify
          label def noi 100 "22,5", modify
          label def noi 102 "22,7", modify
          label def noi 105 "23,1", modify
          label def noi 109 "23,5", modify
          label def noi 111 "23,8", modify
          label def noi 112 "24", modify
          label def noi 114 "24,2", modify
          label def noi 115 "24,5", modify
          label def noi 116 "24,6", modify
          label def noi 118 "24,8", modify
          label def noi 119 "24,9", modify
          label def noi 120 "25", modify
          label def noi 121 "25,1", modify
          label def noi 123 "25,3", modify
          label def noi 126 "25,6", modify
          label def noi 127 "25,7", modify
          label def noi 128 "25,8", modify
          label def noi 132 "26,3", modify
          label def noi 137 "26,9", modify
          label def noi 158 "4", modify
          label def noi 159 "5,2", modify
          label def noi 160 "5,5", modify
          label def noi 162 "5,8", modify
          label def noi 164 "6,1", modify
          label def noi 167 "6,6", modify
          label def noi 169 "6,9", modify
          label def noi 171 "7,2", modify
          label def noi 172 "7,3", modify
          label def noi 178 "8,7", modify
          label def noi 183 "9,4", modify
          label values crim crim
          label def crim 1 "..", modify
          label def crim 4 "10,2", modify
          label def crim 5 "10,3", modify
          label def crim 7 "10,5", modify
          label def crim 8 "10,6", modify
          label def crim 10 "10,8", modify
          label def crim 11 "10,9", modify
          label def crim 13 "11,1", modify
          label def crim 14 "11,2", modify
          label def crim 17 "11,6", modify
          label def crim 19 "11,8", modify
          label def crim 22 "12,1", modify
          label def crim 24 "12,4", modify
          label def crim 25 "12,5", modify
          label def crim 26 "12,6", modify
          label def crim 29 "13,1", modify
          label def crim 30 "13,2", modify
          label def crim 33 "13,6", modify
          label def crim 37 "14", modify
          label def crim 38 "14,1", modify
          label def crim 41 "14,5", modify
          label def crim 43 "14,7", modify
          label def crim 44 "14,8", modify
          label def crim 46 "15,1", modify
          label def crim 47 "15,3", modify
          label def crim 49 "15,5", modify
          label def crim 50 "15,6", modify
          label def crim 53 "15,9", modify
          label def crim 55 "16,2", modify
          label def crim 58 "16,6", modify
          label def crim 63 "17,7", modify
          label def crim 65 "17,9", modify
          label def crim 66 "18", modify
          label def crim 70 "18,8", modify
          label def crim 73 "19,3", modify
          label def crim 74 "19,4", modify
          label def crim 76 "19,8", modify
          label def crim 79 "20,6", modify
          label def crim 95 "3,7", modify
          label def crim 102 "4", modify
          label def crim 103 "4,1", modify
          label def crim 105 "4,3", modify
          label def crim 108 "4,8", modify
          label def crim 109 "4,9", modify
          label def crim 110 "5", modify
          label def crim 111 "5,1", modify
          label def crim 113 "5,4", modify
          label def crim 114 "5,7", modify
          label def crim 118 "6,2", modify
          label def crim 124 "6,8", modify
          label def crim 127 "7,2", modify
          label def crim 128 "7,3", modify
          label def crim 129 "7,4", modify
          label def crim 130 "7,5", modify
          label def crim 132 "8", modify
          label def crim 137 "8,5", modify
          label def crim 138 "8,6", modify
          label def crim 143 "9,1", modify
          label def crim 144 "9,2", modify
          label def crim 147 "9,6", modify
          label def crim 148 "9,7", modify
          label def crim 149 "9,8", modify

          Comment


          • #6
            you have other non-numeric characters; so, first I did:
            Code:
            ta pollution if real(pollution)==.
            and I noticed that some of the values were ".."; so I did
            Code:
            destring pollution, replace dpcomma ignore(".")
            which worked

            so, in general, you need to find the problem as I did above and then use the "ignore" option (if that is the right thing to do as it appeared to be here - in other cases, the problems found may require you to do something else with the data first

            Comment


            • #7
              Hello,

              Thank you for the messages. Although the code worked for some variables, it does not work for the others. I´m not being able to solve it. I want to convert the variables "inc_dep" "inc_self" "inc_pub" "inc_cap" and "rel_poverty" to numeric. Can you help me with this? I send the example of the dataset below. Thank you very much in advance.

              ​​​​​​
              Code:
              * Example generated by -dataex-. For more info, type help dataex
              clear
              input str4(inc_dep inc_self inc_pub) str3 inc_cap long rel_poverty
              "42.6" "10.8" "45.2" "."    28
              "39,0" "15,0" "44.9" "."    95
              "42.1" "11.4" "44.7" "."    48
              "42.6" "14.2" "40.1" "3.1"  68
              "45.2" "15.2" "37.6" "2,0" 104
              "47.8" "9.8"  "41.8" "."   138
              "45.2" "14.8" "37.2" "2.9" 123
              "37.8" "13.8" "45.2" "3.3"   8
              "47.7" "13.5" "37.5" "1.3"  56
              "40.6" "14.1" "43.9" "."    18
              "35.8" "14,0" "48.9" "."    30
              "40.3" "14.7" "42.8" "2.3" 116
              "58.3" "8.7"  "30.8" "."    58
              "47.4" "15.4" "34.2" "."   142
              "40.9" "13,0" "44,0" "."    32
              "42,0" "13.5" "42.1" "."     8
              "42.9" "10.7" "44.4" "1.9"  62
              "41.5" "14.6" "40.1" "3.7" 135
              ""     ""     ""     ""    134
              "40.7" "14,0" "43.8" "."   110
              "46.1" "14.2" "38.3" "."   122
              "46.2" "15.7" "36.3" "1.8" 108
              "42.8" "12.7" "43.4" "."    23
              "39.5" "17,0" "42.9" "."    76
              "40.9" "12.4" "44.5" "."    50
              "43.5" "14.4" "38.8" "3.3"  71
              "45.7" "13.9" "38.6" "1.8" 110
              "44.5" "12.1" "41.9" "."   131
              "45.5" "14.3" "37.6" "2.6" 125
              "35.5" "16,0" "45.2" "3.3" 150
              "47.8" "13.9" "36.8" "1.5" 100
              "43.4" "14,0" "41.3" "."   149
              "37.8" "13.7" "47.7" "."    36
              "40,0" "14.8" "42.9" "2.3" 116
              "56.4" "9.1"  "33,0" "."    56
              "47.5" "13.9" "36.3" "."   115
              "39.6" "14.4" "44.4" "."    48
              "40.4" "12,0" "44.5" "."    16
              "43.9" "10.5" "42.8" "2.7"  63
              "42.4" "13.4" "40.6" "3.5" 144
              ""     ""     ""     ""    122
              "39.1" "17,0" "41.3" "2.7" 135
              "41.9" "14.4" "41.8" "."    59
              "45.4" "16.4" "36.4" "1.8"  98
              "41.6" "10.9" "46.1" "."    31
              "37.6" "13,0" "46.6" "."    81
              "41,0" "14.4" "43.2" "."    74
              "42.6" "12.5" "41.8" "3,0"  79
              "46.7" "13.2" "38.2" "1.9" 107
              "44.3" "12.4" "41.9" "."   145
              "46.8" "14,0" "36.5" "2.8" 107
              "37.3" "13.7" "44.7" "4.2"  11
              "47.7" "12.3" "38,0" "2,0" 104
              "43.2" "12.6" "42.7" "."    20
              "34.3" "10.4" "54.9" "."    37
              "42.6" "14.3" "40.4" "2.7" 133
              "51.4" "10.4" "34.3" "."    54
              "50.8" "13.6" "34.9" "."   119
              "41.4" "13.3" "43.7" "."    75
              "43.1" "10,0" "44.6" "."    15
              "41.9" "10.7" "45.9" "."    69
              "41.1" "15,0" "41.1" "2.7" 151
              ""     ""     ""     ""    118
              "39.4" "16,0" "42.6" "."   138
              "45.9" "9.9"  "43.1" "."   126
              "47.6" "14.4" "36.5" "1.5" 111
              "41.6" "10.1" "45.9" "."    29
              "37.5" "12.5" "47.5" "."    84
              "38.7" "14.3" "44.3" "."    89
              "43.2" "12.6" "41.1" "3.1"  65
              "46.3" "14.1" "37.9" "1.6" 103
              "46.5" "10.7" "41.9" "."   144
              "45,0" "15.1" "36.6" "3.3" 121
              "37.7" "13.6" "45.1" "3.6" 141
              "48.2" "12.6" "37.1" "2.1" 103
              "43.1" "12.7" "42.4" "."     5
              "37.9" "11.9" "49.1" "."    41
              "44.7" "12.8" "40.2" "2.3" 114
              "48.8" "14.7" "33.1" "."     1
              "50.5" "10.3" "36.9" "."   124
              "39.9" "13.6" "44.4" "2.2"  61
              "42.2" "9.7"  "45,0" "."    26
              "41.7" "11.8" "44.7" "."    82
              "42.4" "13.9" "40.9" "2.9" 128
              ""     ""     ""     ""    102
              "40.5" "16.1" "41.4" "."   134
              "46,0" "10.6" "42.2" "."   116
              "47,0" "14.4" "37.5" "."   109
              "41.8" "10.7" "45.6" "."     .
              "44.6" "10.4" "44,0" "."     .
              "46.3" "10.2" "42.4" "."     .
              "46.3" "11.3" "40,0" "2.4"   .
              "48.1" "13.3" "36.4" "2.2"   .
              "45.2" "12.4" "40.7" "."     .
              "47.7" "13,0" "37.2" "2.1"   .
              "39.7" "13.2" "43.6" "3.5"   .
              "47.8" "12.4" "37.9" "1.8"   .
              "43.6" "11.6" "43.5" "."     .
              "31,0" "15.9" "53,0" "."     .
              "44.8" "13.6" "40.3" "1.3"   .
              end
              label values rel_poverty rel_poverty
              label def rel_poverty 1 "..", modify
              label def rel_poverty 5 "10", modify
              label def rel_poverty 8 "10,6", modify
              label def rel_poverty 11 "11,2", modify
              label def rel_poverty 15 "12,3", modify
              label def rel_poverty 16 "12,6", modify
              label def rel_poverty 18 "13,1", modify
              label def rel_poverty 20 "13,3", modify
              label def rel_poverty 23 "14,5", modify
              label def rel_poverty 26 "15,1", modify
              label def rel_poverty 28 "15,4", modify
              label def rel_poverty 29 "15,5", modify
              label def rel_poverty 30 "15,6", modify
              label def rel_poverty 31 "15,7", modify
              label def rel_poverty 32 "16", modify
              label def rel_poverty 36 "17", modify
              label def rel_poverty 37 "17,2", modify
              label def rel_poverty 41 "17,6", modify
              label def rel_poverty 48 "19", modify
              label def rel_poverty 50 "19,7", modify
              label def rel_poverty 54 "2,3", modify
              label def rel_poverty 56 "2,6", modify
              label def rel_poverty 58 "2,8", modify
              label def rel_poverty 59 "2,9", modify
              label def rel_poverty 61 "20,3", modify
              label def rel_poverty 62 "20,4", modify
              label def rel_poverty 63 "21", modify
              label def rel_poverty 65 "21,4", modify
              label def rel_poverty 68 "21,8", modify
              label def rel_poverty 69 "21,9", modify
              label def rel_poverty 71 "22,1", modify
              label def rel_poverty 74 "22,8", modify
              label def rel_poverty 75 "23", modify
              label def rel_poverty 76 "23,4", modify
              label def rel_poverty 79 "23,8", modify
              label def rel_poverty 81 "24", modify
              label def rel_poverty 82 "24,1", modify
              label def rel_poverty 84 "24,3", modify
              label def rel_poverty 89 "26,6", modify
              label def rel_poverty 95 "29,1", modify
              label def rel_poverty 98 "3,2", modify
              label def rel_poverty 100 "3,5", modify
              label def rel_poverty 102 "3,7", modify
              label def rel_poverty 103 "3,8", modify
              label def rel_poverty 104 "3,9", modify
              label def rel_poverty 107 "4,1", modify
              label def rel_poverty 108 "4,2", modify
              label def rel_poverty 109 "4,4", modify
              label def rel_poverty 110 "4,5", modify
              label def rel_poverty 111 "4,6", modify
              label def rel_poverty 114 "5,1", modify
              label def rel_poverty 115 "5,2", modify
              label def rel_poverty 116 "5,3", modify
              label def rel_poverty 118 "5,5", modify
              label def rel_poverty 119 "5,6", modify
              label def rel_poverty 121 "5,8", modify
              label def rel_poverty 122 "5,9", modify
              label def rel_poverty 123 "6", modify
              label def rel_poverty 124 "6,1", modify
              label def rel_poverty 125 "6,2", modify
              label def rel_poverty 126 "6,3", modify
              label def rel_poverty 128 "6,5", modify
              label def rel_poverty 131 "6,8", modify
              label def rel_poverty 133 "7", modify
              label def rel_poverty 134 "7,1", modify
              label def rel_poverty 135 "7,2", modify
              label def rel_poverty 138 "7,5", modify
              label def rel_poverty 141 "7,8", modify
              label def rel_poverty 142 "7,9", modify
              label def rel_poverty 144 "8,1", modify
              label def rel_poverty 145 "8,2", modify
              label def rel_poverty 149 "8,9", modify
              label def rel_poverty 150 "9", modify
              label def rel_poverty 151 "9,1", modify

              Comment


              • #8
                destring with the option dpcomma will not work if you have a mix of decimal separators, some commas and some periods (stops). With a mix of decimal separators. the best thing to do is to standardize on periods as decimal separators before destring.

                As explained previously, the variable rel_poverty is utter garbage as it stands as it arises from an encode where destring was needed, although again some clean-up is needed before you can do that.


                Code:
                * Example generated by -dataex-. For more info, type help dataex
                clear
                input str4(inc_dep inc_self inc_pub) str3 inc_cap long rel_poverty
                "42.6" "10.8" "45.2" "."    28
                "39,0" "15,0" "44.9" "."    95
                "42.1" "11.4" "44.7" "."    48
                "42.6" "14.2" "40.1" "3.1"  68
                "45.2" "15.2" "37.6" "2,0" 104
                "47.8" "9.8"  "41.8" "."   138
                "45.2" "14.8" "37.2" "2.9" 123
                "37.8" "13.8" "45.2" "3.3"   8
                "47.7" "13.5" "37.5" "1.3"  56
                "40.6" "14.1" "43.9" "."    18
                "35.8" "14,0" "48.9" "."    30
                "40.3" "14.7" "42.8" "2.3" 116
                "58.3" "8.7"  "30.8" "."    58
                "47.4" "15.4" "34.2" "."   142
                "40.9" "13,0" "44,0" "."    32
                "42,0" "13.5" "42.1" "."     8
                "42.9" "10.7" "44.4" "1.9"  62
                "41.5" "14.6" "40.1" "3.7" 135
                ""     ""     ""     ""    134
                "40.7" "14,0" "43.8" "."   110
                "46.1" "14.2" "38.3" "."   122
                "46.2" "15.7" "36.3" "1.8" 108
                "42.8" "12.7" "43.4" "."    23
                "39.5" "17,0" "42.9" "."    76
                "40.9" "12.4" "44.5" "."    50
                "43.5" "14.4" "38.8" "3.3"  71
                "45.7" "13.9" "38.6" "1.8" 110
                "44.5" "12.1" "41.9" "."   131
                "45.5" "14.3" "37.6" "2.6" 125
                "35.5" "16,0" "45.2" "3.3" 150
                "47.8" "13.9" "36.8" "1.5" 100
                "43.4" "14,0" "41.3" "."   149
                "37.8" "13.7" "47.7" "."    36
                "40,0" "14.8" "42.9" "2.3" 116
                "56.4" "9.1"  "33,0" "."    56
                "47.5" "13.9" "36.3" "."   115
                "39.6" "14.4" "44.4" "."    48
                "40.4" "12,0" "44.5" "."    16
                "43.9" "10.5" "42.8" "2.7"  63
                "42.4" "13.4" "40.6" "3.5" 144
                ""     ""     ""     ""    122
                "39.1" "17,0" "41.3" "2.7" 135
                "41.9" "14.4" "41.8" "."    59
                "45.4" "16.4" "36.4" "1.8"  98
                "41.6" "10.9" "46.1" "."    31
                "37.6" "13,0" "46.6" "."    81
                "41,0" "14.4" "43.2" "."    74
                "42.6" "12.5" "41.8" "3,0"  79
                "46.7" "13.2" "38.2" "1.9" 107
                "44.3" "12.4" "41.9" "."   145
                "46.8" "14,0" "36.5" "2.8" 107
                "37.3" "13.7" "44.7" "4.2"  11
                "47.7" "12.3" "38,0" "2,0" 104
                "43.2" "12.6" "42.7" "."    20
                "34.3" "10.4" "54.9" "."    37
                "42.6" "14.3" "40.4" "2.7" 133
                "51.4" "10.4" "34.3" "."    54
                "50.8" "13.6" "34.9" "."   119
                "41.4" "13.3" "43.7" "."    75
                "43.1" "10,0" "44.6" "."    15
                "41.9" "10.7" "45.9" "."    69
                "41.1" "15,0" "41.1" "2.7" 151
                ""     ""     ""     ""    118
                "39.4" "16,0" "42.6" "."   138
                "45.9" "9.9"  "43.1" "."   126
                "47.6" "14.4" "36.5" "1.5" 111
                "41.6" "10.1" "45.9" "."    29
                "37.5" "12.5" "47.5" "."    84
                "38.7" "14.3" "44.3" "."    89
                "43.2" "12.6" "41.1" "3.1"  65
                "46.3" "14.1" "37.9" "1.6" 103
                "46.5" "10.7" "41.9" "."   144
                "45,0" "15.1" "36.6" "3.3" 121
                "37.7" "13.6" "45.1" "3.6" 141
                "48.2" "12.6" "37.1" "2.1" 103
                "43.1" "12.7" "42.4" "."     5
                "37.9" "11.9" "49.1" "."    41
                "44.7" "12.8" "40.2" "2.3" 114
                "48.8" "14.7" "33.1" "."     1
                "50.5" "10.3" "36.9" "."   124
                "39.9" "13.6" "44.4" "2.2"  61
                "42.2" "9.7"  "45,0" "."    26
                "41.7" "11.8" "44.7" "."    82
                "42.4" "13.9" "40.9" "2.9" 128
                ""     ""     ""     ""    102
                "40.5" "16.1" "41.4" "."   134
                "46,0" "10.6" "42.2" "."   116
                "47,0" "14.4" "37.5" "."   109
                "41.8" "10.7" "45.6" "."     .
                "44.6" "10.4" "44,0" "."     .
                "46.3" "10.2" "42.4" "."     .
                "46.3" "11.3" "40,0" "2.4"   .
                "48.1" "13.3" "36.4" "2.2"   .
                "45.2" "12.4" "40.7" "."     .
                "47.7" "13,0" "37.2" "2.1"   .
                "39.7" "13.2" "43.6" "3.5"   .
                "47.8" "12.4" "37.9" "1.8"   .
                "43.6" "11.6" "43.5" "."     .
                "31,0" "15.9" "53,0" "."     .
                "44.8" "13.6" "40.3" "1.3"   .
                end
                label values rel_poverty rel_poverty
                label def rel_poverty 1 "..", modify
                label def rel_poverty 5 "10", modify
                label def rel_poverty 8 "10,6", modify
                label def rel_poverty 11 "11,2", modify
                label def rel_poverty 15 "12,3", modify
                label def rel_poverty 16 "12,6", modify
                label def rel_poverty 18 "13,1", modify
                label def rel_poverty 20 "13,3", modify
                label def rel_poverty 23 "14,5", modify
                label def rel_poverty 26 "15,1", modify
                label def rel_poverty 28 "15,4", modify
                label def rel_poverty 29 "15,5", modify
                label def rel_poverty 30 "15,6", modify
                label def rel_poverty 31 "15,7", modify
                label def rel_poverty 32 "16", modify
                label def rel_poverty 36 "17", modify
                label def rel_poverty 37 "17,2", modify
                label def rel_poverty 41 "17,6", modify
                label def rel_poverty 48 "19", modify
                label def rel_poverty 50 "19,7", modify
                label def rel_poverty 54 "2,3", modify
                label def rel_poverty 56 "2,6", modify
                label def rel_poverty 58 "2,8", modify
                label def rel_poverty 59 "2,9", modify
                label def rel_poverty 61 "20,3", modify
                label def rel_poverty 62 "20,4", modify
                label def rel_poverty 63 "21", modify
                label def rel_poverty 65 "21,4", modify
                label def rel_poverty 68 "21,8", modify
                label def rel_poverty 69 "21,9", modify
                label def rel_poverty 71 "22,1", modify
                label def rel_poverty 74 "22,8", modify
                label def rel_poverty 75 "23", modify
                label def rel_poverty 76 "23,4", modify
                label def rel_poverty 79 "23,8", modify
                label def rel_poverty 81 "24", modify
                label def rel_poverty 82 "24,1", modify
                label def rel_poverty 84 "24,3", modify
                label def rel_poverty 89 "26,6", modify
                label def rel_poverty 95 "29,1", modify
                label def rel_poverty 98 "3,2", modify
                label def rel_poverty 100 "3,5", modify
                label def rel_poverty 102 "3,7", modify
                label def rel_poverty 103 "3,8", modify
                label def rel_poverty 104 "3,9", modify
                label def rel_poverty 107 "4,1", modify
                label def rel_poverty 108 "4,2", modify
                label def rel_poverty 109 "4,4", modify
                label def rel_poverty 110 "4,5", modify
                label def rel_poverty 111 "4,6", modify
                label def rel_poverty 114 "5,1", modify
                label def rel_poverty 115 "5,2", modify
                label def rel_poverty 116 "5,3", modify
                label def rel_poverty 118 "5,5", modify
                label def rel_poverty 119 "5,6", modify
                label def rel_poverty 121 "5,8", modify
                label def rel_poverty 122 "5,9", modify
                label def rel_poverty 123 "6", modify
                label def rel_poverty 124 "6,1", modify
                label def rel_poverty 125 "6,2", modify
                label def rel_poverty 126 "6,3", modify
                label def rel_poverty 128 "6,5", modify
                label def rel_poverty 131 "6,8", modify
                label def rel_poverty 133 "7", modify
                label def rel_poverty 134 "7,1", modify
                label def rel_poverty 135 "7,2", modify
                label def rel_poverty 138 "7,5", modify
                label def rel_poverty 141 "7,8", modify
                label def rel_poverty 142 "7,9", modify
                label def rel_poverty 144 "8,1", modify
                label def rel_poverty 145 "8,2", modify
                label def rel_poverty 149 "8,9", modify
                label def rel_poverty 150 "9", modify
                label def rel_poverty 151 "9,1", modify
                
                foreach v of var inc* { 
                    replace `v' = subinstr(`v', ",", ".", 1)
                }
                
                destring inc*, replace 
                
                
                decode rel_poverty, gen(rel_poverty2)
                replace rel_poverty2 = "." if rel_poverty2 == ".."
                destring rel_poverty2, dpcomma replace

                The main principles here were all explained in previous posts by Andrew Musau, Rich Goldstein and myself.

                Compare again https://www.statalist.org/forums/for...aphs-by-groups

                encode is quite wrong if a string variable just contains numbers.

                Comment


                • #9
                  Thank you very much!

                  Comment

                  Working...
                  X