Announcement

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

  • Stata 17 prompt/dofile editor does not support curvy quotes/apostrophes ( ’ ), only normal quotes/apostrophes ( ' )

    Hi everyone!

    I'm dealing with my own dataset and I wanted to create a variable called "exch_contact_no_temp" and assign numerical values to it based on an existing string variable called "exch_contact_no". The only problem is that some of the strings of "exch_contact_no" contain curvy quotes ( ’ ) which are automatically transformed into normal quotes ( ' ) once I paste the string on the do-file/on the prompt. However, while running the command, Stata does not recognize both as interchangeable. My code is as follows:

    Code:
    gen exch_contact_no_temp = .
    replace exch_contact_no_temp = 1 if exch_contact_no == "they didn't   ask about it"
    replace exch_contact_no_temp = 2 if exch_contact_no == "they both  didn’t  ask for each other's  contacts"
    But Stata does zero replacements! I'm attaching a (very short) extract of the original dataset containing two observations of "exch_contact_no" that have curvy quotes ("they didn’t ask about it" and "they both didn’t ask for each other's contacts"). I have tried copying and pasting curvy quotes from old Stata 16 dofiles -- in which I can still see the curvy quotes --, but every time I paste them to the prompt of Stata 17 (or to a do-file of Stata 17), they are automatically converted into normal quotes.

    Since the data set has an identifying variable, I guess I can maneuver this issue by assigning numerical values to exch_contact_no_temp based on the identifying variable (and not based on the string variable exch_contact_no). Still, this is very annoying and I don't understand why Stata 17 seems not to support curvy quotes in the prompt but still treats curvy and normal quotes differently when inside a string.

    In short, my problem is: there is no way of writing a curvy quote in a prompt or in a do-file (even if I copy and paste from an old dofile containing a curvy quote), but when I run a command like "replace if equal", Stata considers the string with the curvy quote as a different from the string with the same characters but bearing the normal quote.

    Many thanks!

    Pedro

    PS: This is what I mean by a "curvy quote":
    Click image for larger version

Name:	image_2021-11-17_194629.png
Views:	1
Size:	379 Bytes
ID:	1636981




    PS2: This is a "normal quote":
    Click image for larger version

Name:	image_2021-11-17_194601.png
Views:	1
Size:	374 Bytes
ID:	1636980

    Attached Files
    Last edited by Pedro dSFerreira; 17 Nov 2021, 11:57.

  • #2
    Open Stata's General preferences and uncheck the checkbox for Paste curly quotes as ASCII quotes. This feature exists because users were copying commands from PDFs that contained the curly quotes which of course don't work so we were asked to automatically convert the quotes.
    -Chinh Nguyen

    Comment


    • #3
      Hi Pedro, welcome to the StataList.

      Originally posted by Pedro dSFerreira View Post
      I have tried copying and pasting curvy quotes from old Stata 16 dofiles -- in which I can still see the curvy quotes --, but every time I paste them to the prompt of Stata 17 (or to a do-file of Stata 17), they are automatically converted into normal quotes.
      This is by design and new in Stata 17.

      Originally posted by Pedro dSFerreira View Post
      Stata does not recognize both as interchangeable.
      [...]
      but when I run a command like "replace if equal", Stata considers the string with the curvy quote as a different from the string with the same characters but bearing the normal quote.
      That's because they are actually different characters and Stata does not treat them equivalently.

      Originally posted by Pedro dSFerreira View Post
      my problem is: there is no way of writing a curvy quote in a prompt or in a do-file (even if I copy and paste from an old dofile containing a curvy quote)
      This demonstrates some technique. Essentially, you assign the character you want to a local macro and call that macro in strings when needed. (Note: you can actually type in those characters into the Do -file editor if you are savvy with Unicode keyboard shortcuts, but this is fragile as they will be replaced if you ever copy/paste that text.)

      Code:
      local ldq = ustrunescape("\u201c")
      local rdq = ustrunescape("\u201d")
      local lsq = ustrunescape("\u2018")
      local rsq = ustrunescape("\u2019")
      
      di "`ldq'dobule quotes`rdq'"
      di "`lsq'single quotes`rsq'"
      Result

      Code:
      . di "`ldq'dobule quotes`rdq'"
      “dobule quotes”
      
      . di "`lsq'single quotes`rsq'"
      ‘single quotes’
      Edit: crossed with #2.

      Comment


      • #4
        Awesome! Managed to solve the issue! Many many thanks!

        Comment

        Working...
        X