Announcement

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

  • Can't view or drop notes on variables because of "too few quotes" error?

    I inherited a data set with notes on the variables. Long story short when I try to see notes attached to some of the variables I get the error message "too few quotes." When I try to drop the notes I get the same error, so I can't even attach my own notes to these variables!
    How can I drop these bad notes? Is there a way to find a replace in the text of the notes to get rid of all parentheses and quotes in the notes? Am I simply stuck with variables that can't display the notes attached to them?

    Edit:
    Here is my code:
    Code:
    notes respmarital
    When I try to drop the note I use the code:
    Code:
    drop notes respmarital

    In both cases I get the error: "Too few quotes"
    Last edited by Daniel Ram; 02 Oct 2019, 08:31.

  • #2
    Show us your syntax, please. I would put more probability on there being some small problem with what you typed than on the notes being inaccessible.

    Comment


    • #3
      Code:
      drop notes respmarital 
      is the syntax you would use to
      Code:
       drop
      variables with those names. The syntax would start notes drop

      I would start with just

      Code:
      notes
      Otherwise I can agree that that error message is puzzling.
      Last edited by Nick Cox; 02 Oct 2019, 08:39.

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Show us your syntax, please. I would put more probability on there being some small problem with what you typed than on the notes being inaccessible.
        Alright, I added the syntax above. I believe the issue is that some notes have the character `` in them...I am confused as to how they got there in the first place but those characters seem to be what are causing the problem.

        Comment


        • #5
          Wouldn't the code to drop be the following?
          Code:
          notes drop respmarital
          Red Owl
          Stata/IC 16.0 (Windows 10, 64-bit)

          Comment


          • #6
            I am hopeful that
            Code:
            char respmarital[note1]
            will do the job, assuming that respmarital has just a single note attached.

            Or more generally, the following code functions much like notes drop.
            Code:
            . notes x
            
            x:
              1.  one
              2.  two
            
            . char list x[]
              x[note2]:                   two
              x[note0]:                   2
              x[note1]:                   one
            
            . local c : char x[]
            
            . display "`c'"
            note2 note0 note1
            
            . foreach ch of local c {
              2. char x[`ch']
              3. }
            
            . notes x
            
            .
            The problem with notes drop - having looked at the output of viewsource notes.ado - is that it reviews the value of each possible note to ensure it exists and to add 1 to the counter of notes dropped. The odd quotation mark(s) apparently confuse the do-file when the note text is placed into a local macro.
            Last edited by William Lisowski; 02 Oct 2019, 09:50.

            Comment


            • #7
              Originally posted by William Lisowski View Post
              I am hopeful that
              Code:
              char respmarital[note1]
              will do the job, assuming that respmarital has just a single note attached.

              Or more generally, the following code functions much like notes drop.
              Code:
              . notes x
              
              x:
              1. one
              2. two
              
              . char list x[]
              x[note2]: two
              x[note0]: 2
              x[note1]: one
              
              . local c : char x[]
              
              . display "`c'"
              note2 note0 note1
              
              . foreach ch of local c {
              2. char x[`ch']
              3. }
              
              . notes x
              
              .
              The problem with notes drop - having looked at the output of viewsource notes.ado - is that it reviews the value of each possible note to ensure it exists and to add 1 to the counter of notes dropped. The odd quotation mark(s) apparently confuse the do-file when the note text is placed into a local macro.
              That does work for me. Thank you!
              I worked around this by copying and renaming all the variables but this is much more elegant.

              Comment


              • #8
                Thanks for closing the loop. I was unable to generate a note to cause the problem, so it's good to know my inferences were correct.

                As to the elegance of my code, it's hard to find elegance in what is essentially a hack to overcome what is essentially non-robust code. A member of my dissertation committee referred to a similar process as "making a sow's purse from a sow's ear". (Luckily he was not referring to my dissertation itself.)

                (For those who perhaps find these sows unfamiliar, the usual metaphor is "making a silk purse from a sow's ear" to describe achieving a result far better than the input would lead you to expect.)

                Comment


                • #9
                  With a little thought, I realized that the char command allows me to construct a reproducible example of the problem in post #1. I will forward this along to Stata Technical Services.
                  Code:
                  . notes x : quarter
                  
                  . char list x[]
                    x[note1]:                   quarter
                    x[note0]:                   1
                  
                  . notes list x
                  
                  x:
                    1.  quarter
                  
                  . char x[note1] note with a ` left single quote
                  
                  . char list x[]
                    x[note1]:                   note with a ` left single quote
                    x[note0]:                   1
                  
                  . notes list x
                  too few quotes
                  r(132);
                  
                  . notes drop x
                  too few quotes
                  r(132);

                  Comment

                  Working...
                  X