Announcement

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

  • Change a letter in the string variable

    Dear all,

    I am working on a massive data base and I am having a problem with the strings.

    I have several cases of the "ä" character being read in differently (with the currency sign) - I want to change the "ä" for "ae" in all the cases.

    One case for example would be the string variable: "Orthopädischechirurgie"
    Stata does not seem to recognize the "ä" and so returns the following "Orthop¤Adischechirurgie"

    Any thoughts on how I can change this to read: "Orthopaedischechirurgie"?

    I am using Stata13.

    Many thanks and best,
    Cam
    Last edited by Camila Plaza; 16 Jan 2018, 02:41.

  • #2
    To help find the ascii characters of interest, I'd download the packages -ascii- and -charlist- using -findit-.

    Here's an example of how to make the substitution in Stata 13:


    Code:
    clear
    set obs 2
    
    input str40 y
    `"Orthopädischechirurgie"'
    end
    
    g x =  `"Orthopädischechirurgie"'
    g z = `"Orthop¤Adischechirurgie"' //my Stata 13 sees the ä though!
    
    **stata sees the ¤A part as ascii characters 63 and 65 in var z!
    charlist z
    di `"`r(chars)'"'
    di `"`r(ascii)'"'
    ascii 
    foreach j in x y  {
        replace `j' = subinstr(`j', `"`=char(138)'"', "ae", .)
        }
      
      replace z = subinstr(z, `"`=char(65)'`=char(63)'"', "ae", .) //doesnt work?
      replace z = subinstr(z, `"?A"', "ae", .) //works
        
        l
    Last edited by eric_a_booth; 16 Jan 2018, 06:37.
    Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

    Comment


    • #3
      oh thank you so much! I had the codes for the ascii characters, but wasn't sure if I had to download packages for it.
      I will give this a shot

      Comment

      Working...
      X