Announcement

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

  • removing a character from a variable that should be numeric

    I have a variable in my dataset that should be a numerical variable (ofportfoliocompanies), however when I browsed the data in Stata I noticed it looks like this ( 4" ). in other words, the number is followed by a double quotation.
    how I can remove the double quotation from all observations and keep only the number?

    Code:
    ----------------------- copy starting from the next line -----------------------
    
    
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(investmentfirm investortype shortdescription address city state country region websiteurl) str15 zip str40 contactphone int totalofdeals str5 ofportfoliocompanies
      1 21  390    .   .  .  27 4    . ""        ""                   1 `"1"        "' 
      2 14 1425    .   .  .  92 4    . ""        ""                   1 `"1"        "' 
      3 21 1474    .   .  .   4 2    . ""        ""                   1 `"1"        "' 
      4 16 1471    .   .  . 105 4    . ""        ""                   1 `"1"        "' 
      5 16 1440    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
      6 21  892    .   .  . 105 4    . ""        ""                   1 `"1"        "' 
      7 21 1472    .   .  . 105 4    . ""        ""                   1 `"1"        "' 
      8 12 1424    .   .  .  13 3    . ""        ""                   1 `"1"        "' 
      9 16  421    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     10 21  753    .   .  .  33 4    . ""        ""                   1 `"1"        "' 
     11 17 1832    .   .  . 105 4 4479 ""        ""                   1 `"1"        "' 
     12  6 1490    .   .  .  35 4    . ""        ""                   1 `"1"        "' 
     13 21    .    .   .  .  94 4    . ""        ""                   1 `"1"        "' 
     14 21    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     15  .    .    .   .  .   . .    . ""        ""                   . ""      
     16  .    .    .   .  .   . .    . ""        ""                   . ""      
     17  .    .    .   .  .   . .    . ""        ""                   . ""      
     18  .    .    .   .  .   . .    . ""        ""                   . ""      
     19  .    .    .   .  .   . .    . ""        ""                   . ""      
     20 21    . 1539 124 28 106 6  429 ""        "+1 (617) 406-3300" 12 `"5"        "' 
     21 21  850    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     22 21    .    .   .  .  43 2    . ""        ""                   1 `"1"        "' 
     23 21    .    .   .  . 106 6    . ""        ""                   3 `"1"        "' 
     24  4    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     25 21    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     26  2 2547    . 559  .  11 4 4266 ""        ""                  22 `"22"       "'
     27 21    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     28 21    .    .   .  .  46 4    . ""        ""                   2 `"2"        "' 
     29 16    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     30 21    .    .   .  . 106 6    . ""        ""                   3 `"3"        "' 
     31 10    .    .   .  .  91 1    . ""        ""                   1 `"1"        "' 
     32 21 1415    .   .  .  35 4    . ""        ""                   1 `"1"        "' 
     33 14    .    .   .  . 106 6    . ""        ""                   6 `"4"        "' 
     34 21    .    .   .  . 105 4    . ""        ""                   1 `"1"        "' 
     35 21    .    .   .  . 106 6    . ""        ""                   6 `"4"        "' 
     36 21    .    .   .  . 106 6    . ""        ""                   2 `"2"        "' 
     37 21    .    .   .  .  33 4    . ""        ""                   1 `"1"        "' 
     38 21    . 1456 775  .  33 4  419 ""        "+33 1 5533 1310"    5 `"4"        "' 
     39 21    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     40 16    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     41 21    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     42 10    .    .   .  . 106 6    . ""        ""                   2 `"2"        "' 
     43 21 3358    . 893  8 106 6 3966 ""        ""                   2 `"2"        "' 
     44 21    .    .   .  . 106 6    . ""        ""                   4 `"3"        "' 
     45 21    .    .   .  . 106 6    . ""        ""                   8 `"6"        "' 
     46 21    .    .   .  .  48 2    . ""        ""                   1 `"1"        "' 
     47 21    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     48  6    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     49  2 2906    .   .  . 106 6 4258 ""        ""                   9 `"5"        "' 
     50 21    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     51 21    .    .   .  .  88 2    . ""        ""                   1 `"1"        "' 
     52 21    .    .   .  . 106 6    . ""        ""                   2 `"1"        "' 
     53  5    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     54 21 3422    . 587  8 106 6  420 ""        ""                   6 `"3"        "' 
     55 21    .    .   .  .  88 2    . ""        ""                   1 `"1"        "' 
     56 21    .    .   .  . 106 6    . ""        ""                   5 `"3"        "' 
     57 14    .    .   .  . 106 6    . ""        ""                   2 `"1"        "' 
     58  7    .    .   .  .  43 2    . ""        ""                   2 `"2"        "' 
     59 21    .    .   .  . 106 6    . ""        ""                   1 `"1"        "' 
     60 21 1253    .   .  .  28 4    . ""        ""                   1 `"1"        "' 
    
    end
    ------------------ copy up to and including the previous line ------------------

    I tried this code
    Code:
    replace ofportfoliocompanies = subinstr(ofportfoliocompanies, "\"", "", .)
    but i receive this error
    too few quotes
    r(132);
    I am using Stata 14

    could you please give me the correct code?

    Many thanks

  • #2
    I solve the issue, i think the CSV file wasn't imported properly in stata

    thanks

    Comment

    Working...
    X