title: egen sum() not giving correct total (datatype problem?)
body: <p>My problem is that neither <code>egen sum()</code> nor <code>egen total()</code> sums correctly.</p>
  
  <p>The variable <code>eqvalueusd</code> I am trying to sum was imported from a .csv file as <code>str20</code>; then I <code>encode</code>d it in a new variable called <code>marketusd</code>, which had <code>long</code> (<code>%16.0g</code>) format.</p>
  
  <p>I want the total of the values in that variable.</p>
  
  <p>What have I tried so far (that has not worked)</p>
  
  <p>1: <code>summarize marketusd, meanonly</code> and <code>display r(sum)</code>, which showed a wrong sum</p>
  
  <p>2: <code>egen sum = sum(marketusd)</code> and <code>egen sum = total(marketusd)</code>, which put in a new variable the wrong sum</p>
  
  <p>3: <code>egen double sum = sum(marketusd)</code>, <code>egen double sum = total(marketusd)</code>, <code>egen float sum = sum(marketusd)</code> and <code>egen float sum = total(marketusd)</code>, which put in a new variable the wrong sum</p>
  
  <p>4: I also combined the previous with converting the original variable not with <code>encode</code> but with <code>generate newvar = real(eqvalueusd)</code>, which filled <code>newvar</code> with missing points "."; and with <code>destring eqvalueusd, replace</code>, which returns the following error message <code>contains nonnumeric characters</code> (which is weird as well, as <code>eqvalueusd</code> contains only numerical characters).</p>
  
  <p>5: When I copy the <code>marketusd</code> data and calculate the sum in Excel, I obtain the correct number. So whatever is wrong, it is  in my Stata code. </p>
  
  <pre><code>* Example generated by -dataex-. To install: ssc install dataex
  clear
  input str20 eqvalueusd long marketusd float newvar
  "4.606.727,95"   424 192510
  "1.132.456,29"    27 192510
  "5.596.517,16"   472 192510
  "3.292.918,01"   339 192510
  "6.748.732,71"   512 192510
  "6.139.518,59"   500 192510
  "2.927.484,83"   272 192510
  "11.474.461,50"  168 192510
  "1.253.316,28"    54 192510
  "1.717.925,38"   130 192510
  "1.336.232,93"    73 192510
  "4.863.581,14"   433 192510
  "4.370.258,61"   412 192510
  "1.526.748,61"   105 192510
  "20.280.664,62"  276 192510
  "5.643.416,65"   476 192510
  "2.098.390,40"   228 192510
  "2.853.095,83"   268 192510
  "72.674,07"      549 192510
  "224.362,66"     298 192510
  "2.358.856,20"   238 192510
  "0,37"             1 192510
  "5.761.013,33"   479 192510
  "1.421.174,00"    89 192510
  "6.315.874,00"   503 192510
  "1.458.139,03"    96 192510
  "7.310.413,83"   535 192510
  "2.203.177,49"   231 192510
  "1.176.210,24"    38 192510
  "1.252.117,44"    53 192510
  "20.824.291,28"  284 192510
  "3.338.046,79"   341 192510
  "3.756.050,52"   361 192510
  "5.676.796,74"   477 192510
  "1.560.603,03"   114 192510
  "534.372,36"     487 192510
  "29.592.046,17"  323 192510
  "4.281.136,11"   409 192510
  "821.142,00"     578 192510
  "2.535.309,35"   248 192510
  "23.026.731,10"  301 192510
  "49.629.060,26"  458 192510
  "1.052.654,93"    11 192510
  "1.001.017,50"     2 192510
  "3.483.488,91"   349 192510
  "370.816.160,01" 388 192510
  "7.716.727,72"   542 192510
  "3.432.478,63"   344 192510
  "28.481.992,67"  318 192510
  "369.580,98"     385 192510
  "9.975.296,70"   599 192510
  "6.136.398,05"   499 192510
  "6.791.545,74"   514 192510
  "8.349.073,42"   563 192510
  "19.297.647,24"  219 192510
  "2.900.280,82"   271 192510
  "3.798,33"       363 192510
  "4.129.903,95"   403 192510
  "831.718,20"     579 192510
  "18.559.520,16"  215 192510
  "7.937.960,14"   544 192510
  "14.267.003,27"  191 192510
  "1.326.491,92"    69 192510
  "13.011,32"      183 192510
  "993.512,11"     620 192510
  "4.772.173,35"   430 192510
  "14.772,85"      194 192510
  "5.204.176,80"   464 192510
  "25.717.006,99"  312 192510
  "2.346.906,70"   237 192510
  "9.675.531,03"   596 192510
  "3.557.999,40"   352 192510
  "1.711.335,49"   129 192510
  "5.324.698,44"   465 192510
  "98.745.322,26"  615 192510
  "5.421.793,96"   468 192510
  "24.111.888,32"  309 192510
  "20.720.051,22"  282 192510
  "46.803.838,01"  453 192510
  "20.820.859,94"  283 192510
  "1.504.028,44"   102 192510
  "2.301.295,57"   234 192510
  "5.478.638,14"   471 192510
  "6.062.898,51"   496 192510
  "756.133,96"     554 192510
  "8.147.619,93"   561 192510
  "50.793.535,72"  486 192510
  "840.738,25"     581 192510
  "1.363.147,24"    81 192510
  "7.306.628,55"   534 192510
  "74.690,62"      552 192510
  "1.354.018,89"    76 192510
  "1.141.966,42"    31 192510
  "2.055.183,94"   224 192510
  "7.980.821,15"   545 192510
  "244.754,81"     310 192510
  "1.458.217,93"    97 192510
  "7.518.664,69"   539 192510
  "1.875.695,95"   148 192510
  "2.190.106,38"   230 192510
  end
  label values marketusd a
  label def a 1 "0,37", modify
  label def a 2 "1.001.017,50", modify
  label def a 11 "1.052.654,93", modify
  label def a 27 "1.132.456,29", modify
  label def a 31 "1.141.966,42", modify
  label def a 38 "1.176.210,24", modify
  label def a 53 "1.252.117,44", modify
  label def a 54 "1.253.316,28", modify
  label def a 69 "1.326.491,92", modify
  label def a 73 "1.336.232,93", modify
  label def a 76 "1.354.018,89", modify
  label def a 81 "1.363.147,24", modify
  label def a 89 "1.421.174,00", modify
  label def a 96 "1.458.139,03", modify
  label def a 97 "1.458.217,93", modify
  label def a 102 "1.504.028,44", modify
  label def a 105 "1.526.748,61", modify
  label def a 114 "1.560.603,03", modify
  label def a 129 "1.711.335,49", modify
  label def a 130 "1.717.925,38", modify
  label def a 148 "1.875.695,95", modify
  label def a 168 "11.474.461,50", modify
  label def a 183 "13.011,32", modify
  label def a 191 "14.267.003,27", modify
  label def a 194 "14.772,85", modify
  label def a 215 "18.559.520,16", modify
  label def a 219 "19.297.647,24", modify
  label def a 224 "2.055.183,94", modify
  label def a 228 "2.098.390,40", modify
  label def a 230 "2.190.106,38", modify
  label def a 231 "2.203.177,49", modify
  label def a 234 "2.301.295,57", modify
  label def a 237 "2.346.906,70", modify
  label def a 238 "2.358.856,20", modify
  label def a 248 "2.535.309,35", modify
  label def a 268 "2.853.095,83", modify
  label def a 271 "2.900.280,82", modify
  label def a 272 "2.927.484,83", modify
  label def a 276 "20.280.664,62", modify
  label def a 282 "20.720.051,22", modify
  label def a 283 "20.820.859,94", modify
  label def a 284 "20.824.291,28", modify
  label def a 298 "224.362,66", modify
  label def a 301 "23.026.731,10", modify
  label def a 309 "24.111.888,32", modify
  label def a 310 "244.754,81", modify
  label def a 312 "25.717.006,99", modify
  label def a 318 "28.481.992,67", modify
  label def a 323 "29.592.046,17", modify
  label def a 339 "3.292.918,01", modify
  label def a 341 "3.338.046,79", modify
  label def a 344 "3.432.478,63", modify
  label def a 349 "3.483.488,91", modify
  label def a 352 "3.557.999,40", modify
  label def a 361 "3.756.050,52", modify
  label def a 363 "3.798,33", modify
  label def a 385 "369.580,98", modify
  label def a 388 "370.816.160,01", modify
  label def a 403 "4.129.903,95", modify
  label def a 409 "4.281.136,11", modify
  label def a 412 "4.370.258,61", modify
  label def a 424 "4.606.727,95", modify
  label def a 430 "4.772.173,35", modify
  label def a 433 "4.863.581,14", modify
  label def a 453 "46.803.838,01", modify
  label def a 458 "49.629.060,26", modify
  label def a 464 "5.204.176,80", modify
  label def a 465 "5.324.698,44", modify
  label def a 468 "5.421.793,96", modify
  label def a 471 "5.478.638,14", modify
  label def a 472 "5.596.517,16", modify
  label def a 476 "5.643.416,65", modify
  label def a 477 "5.676.796,74", modify
  label def a 479 "5.761.013,33", modify
  label def a 486 "50.793.535,72", modify
  label def a 487 "534.372,36", modify
  label def a 496 "6.062.898,51", modify
  label def a 499 "6.136.398,05", modify
  label def a 500 "6.139.518,59", modify
  label def a 503 "6.315.874,00", modify
  label def a 512 "6.748.732,71", modify
  label def a 514 "6.791.545,74", modify
  label def a 534 "7.306.628,55", modify
  label def a 535 "7.310.413,83", modify
  label def a 539 "7.518.664,69", modify
  label def a 542 "7.716.727,72", modify
  label def a 544 "7.937.960,14", modify
  label def a 545 "7.980.821,15", modify
  label def a 549 "72.674,07", modify
  label def a 552 "74.690,62", modify
  label def a 554 "756.133,96", modify
  label def a 561 "8.147.619,93", modify
  label def a 563 "8.349.073,42", modify
  label def a 578 "821.142,00", modify
  label def a 579 "831.718,20", modify
  label def a 581 "840.738,25", modify
  label def a 596 "9.675.531,03", modify
  label def a 599 "9.975.296,70", modify
  label def a 615 "98.745.322,26", modify
  label def a 620 "993.512,11", modify
  </code></pre>