Announcement

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

  • how to replace the quotation marks in the data

    For the variables v1 in my database, it has quotation marks. For example, the first line is ", the second line is "50, the third line is 70". I want to delete all the "in the data, how can i do? Thanks very much.

  • #2
    Code:
    generate clean_v1 = subinstr(v1, `"""', "", .)
    will change all double quotes in v1 to an empty string.

    May this is what you want.

    Best
    Daniel

    Comment


    • #3
      For the variables v1 in my database, it has quotation marks. For example, the first line is ", the second line is "50, the third line is 70". Some data only has quotation marks. I want to delete all the "in the data, how can i do? Thanks very much.

      Comment


      • #4
        Originally posted by daniel klein View Post
        Code:
        generate clean_v1 = subinstr(v1, `"""', "", .)
        will change all double quotes in v1 to an empty string.

        May this is what you want.

        Best
        Daniel
        Got it.

        Thanks

        Comment


        • #5
          Code:
          replace v1 = subinstr(v1, `"""', `""', .)
          David Radwin
          Senior Researcher, California Competes
          californiacompetes.org
          Pronouns: He/Him

          Comment


          • #6
            Hi. I'm doing exactly the same but it doesn't work. I have a string variable and one of the values is just a quote ("). I need to replace that value with a 12 but every time I try to use the code you suggested it doesn't do anything. All it says is "0 real changes made". I'd appreciate your assitance.

            Comment


            • #7
              Welcome to StataList. Please post back with exactly the command you typed at the command line or the line from your syntax file. There's a possibility that there's an error in what you typed, but we can't know if we don't see it.

              Also, there's a possibility that the string you think contains a quotation mark is not quite what you think it is. For someone to diagnose that possibility, please use the -dataex- command to create a data example to present here. You example need contain only a few observations and only the string variable in question, but one or more of your observations must (of course) be one with the offending quotation mark. If you don't know about the -dataex- command, take a look at the StataList FAQ on this topic (top of the page), and also look at -help dataex- in Stata. (Except in relatively unusual circumstances, presenting such a data example is always expected on StataList.) To prepare this example, you can trim down your data set to just a few relevant observations by temporarily deleting irrelevant observations or using -drop- or -keep- if you know those commands. Then, paste this example into a message and surround it with code delimiters, per item 12.3 in the StataListFAQ.

              Comment

              Working...
              X