Announcement

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

  • Destring-Ignore-Backtick Command with "Too Few Quotes" Error

    Hi Everyone. Started using Stata a few weeks ago and now I am addicted! I am currently trying run the following command:

    destring Strgvar, gen(Strgvar1) ignore(` - _ , ')

    but getting "too few quotes" as a response. I even tried to put all the characters to be ignored in quotes but it still returned the same error.

    With the same command also, I noticed that numbers that have a hyphen between them e.g. "10-1" are eventually not destringed. I am using Stata 15. How do I fix these issues?

  • #2
    You need to use double quotes:

    Code:
    destring stringvar, gen(stringvar1) ignore("-_,")

    Comment


    • #3
      Code:
       gen numvar = real(ustrregexra(strvar, "\D",""))

      Comment


      • #4
        Originally posted by Ali Atia View Post
        You need to use double quotes:

        Code:
        destring stringvar, gen(stringvar1) ignore("-_,")
        I tried this but it did not work. Thanks for the assistance though

        Comment


        • #5
          Well, if you destring "10-1" by ignoring the hyphen you're almost certainly destroying its meaning. I think we need to see a data example and it may well be that the advice is to use quite different syntax.

          Comment


          • #6
            Originally posted by Abiye Kalaiwo View Post

            I tried this but it did not work. Thanks for the assistance though
            Please be more specific. When you say it doesn't work, do you mean that it returned an error or that it produced a result which you weren't looking for? In the latter case, you'll need to clarify what result you are looking for so that a more useful answer can be given.

            Comment


            • #7
              Originally posted by Nick Cox View Post
              Well, if you destring "10-1" by ignoring the hyphen you're almost certainly destroying its meaning. I think we need to see a data example and it may well be that the advice is to use quite different syntax.
              Hi Nick. Thanks for weighing in. So I am trying to destring a strvarA which inadvertently had all kinds of characters erroneously (`/'-_) included in the entries. So I tried to run

              destring strvarA, gen(strvarB) ignore('`-_;:"/)

              However, I noticed this error: too few quotes r(132);. One thing I did notice though was when I removed `' characters from the ignore syntax, it worked. Following this I had to go remove ` and ' individually. Also, I tried to put them in quotes commas etc but still did not work. Don't know if this is sufficient

              Comment


              • #8
                Originally posted by Ali Atia View Post

                Please be more specific. When you say it doesn't work, do you mean that it returned an error or that it produced a result which you weren't looking for? In the latter case, you'll need to clarify what result you are looking for so that a more useful answer can be given.
                Hi Ali. I tried exactly what you suggested. So mine looked like this:

                destring strvarA, gen(strvarB) ignore("'`-_;:"/")

                As I understood it, you wanted me to put all the characters I wanted to ignore in quotes which I did but it did not work. See my response to Nick - probably would provide more context. Let me know if you need additional information. Thanks for the support

                Comment


                • #9
                  You should follow Nick's suggestion in #5 and provide a data example using dataex.

                  Code:
                  dataex stringvar in 1/5
                  where you replace "stringvar" with the name of your string variable.

                  Comment


                  • #10
                    Not sure I really understand how to use dataex but I have attached an example of the specific data I am having issues with.

                    Thanks
                    Attached Files

                    Comment


                    • #11
                      For this, you need to present a dataex example. Screenshots are not very useful. Run the following and copy and paste to the forum.


                      Code:
                      ssc install dataex, replace
                      dataex Systol* in 1/12

                      Comment


                      • #12
                        . dataex SystolicBP in 1/12

                        ----------------------- copy starting from the next line -----------------------
                        Code:
                        * Example generated by -dataex-. To install: ssc install dataex
                        clear
                        input str4 SystolicBP
                        "120"
                        "118"
                        "100"
                        "120"
                        "120"
                        "120"
                        "140"
                        "115"
                        "100"
                        "130"
                        "110"
                        "109"
                        end
                        ------------------ copy up to and including the previous line ------------------

                        Listed 12 out of 53146 observations

                        .

                        Comment


                        • #13
                          Try instead

                          Code:
                          dataex if missing(real(SystolicBP))

                          Comment


                          • #14
                            Originally posted by Andrew Musau View Post
                            Try instead

                            Code:
                            dataex if missing(real(SystolicBP))
                            dataex if missing(SystolicBP)
                            input statement exceeds linesize limit. Try specifying fewer variables
                            r(1000);

                            Comment


                            • #15
                              You just need the one variable.

                              Code:
                              dataex SystolicBP if missing(real(SystolicBP))

                              Comment

                              Working...
                              X