Announcement

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

  • ustrfix is not working (alternatives?)

    Dear Stata Forum,

    I was teaching my Stata class last Thursday, and I tried to remove the strange diamond question mark symbol in the variable C3:
    Click image for larger version

Name:	Ustrfix_NotWorking.jpg
Views:	1
Size:	15.8 KB
ID:	1782136


    In the past, the following command has always worked: replace C3 = ustrfix(C3, "")

    However, that day, the ustrfix command did NOT work. I'm not sure why, since Stata18 was installed on the school computer (and also on my home laptop, where ustrfix works). During class, I also tried replace C3 = subinstr(C3, "�", "", .), but it did not work either. Can anyone suggest an alternative Stata command to remove the strange symbol when cleaning the data?

    Thanks so much,
    Michelle




  • #2
    If you install chartab from SSC, it will tell you exactly what that character is, and you can reference it directly.

    Code:
    ssc describe chartab
    Otherwise, the following will work to delete any non-ASCII characters:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str100 C3
    "The Phoenix Companies, Inc.,�"
    "Other Release No.:�34-78341"  
    end
    
    l
    replace C3=  ustrfrom(C3, "ascii", 2)
    l
    Res.:

    Code:
    . l
    
         +-------------------------------+
         |                            C3 |
         |-------------------------------|
      1. | The Phoenix Companies, Inc.,� |
      2. |   Other Release No.:�34-78341 |
         +-------------------------------+
    
    . 
    . replace C3=  ustrfrom(C3, "ascii", 2)
    (2 real changes made)
    
    . 
    . l
    
         +------------------------------+
         |                           C3 |
         |------------------------------|
      1. | The Phoenix Companies, Inc., |
      2. |   Other Release No.:34-78341 |
         +------------------------------+

    Comment


    • #3
      Dear Andrew Musau, Thank you so much! I will try this out on the school's computer tomorrow to see if it works!!! Thank you!

      Comment

      Working...
      X