Search code examples
statastata-macros

How to store strings with apostrophes in a local macro


I want to create a local macro (phrases) that stores a number of phrases:

"I'm sorry"
"I can help"
"so what"

Evidently, some of these phrases have apostrophes in them and I do not know how to store them.

I have tried the following:

local phrases " `I'm sorry' "
local phrases `" `"I'm sorry"' "'
local phrases ` "I'm sorry" '
local phrases `" "I'm sorry" "'

However, none of these seem to work; Stata will not accept the phrase as a single string.


Solution

  • The following works for me:

    local foo `" "I'm sorry" "'
    
    display `"`foo'"'
     "I'm sorry" 
    
    clear
    set obs 1
    
    generate foo = `"`foo'"'
    
    list
    
         +---------------+
         |           foo |
         |---------------|
      1. |  "I'm sorry"  |
         +---------------+