Announcement

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

  • add double quotes to values

    Someone asked how to remove double quotes from a string, but I want to add double quotes to string values, for example:
    my name is Adam
    "my name is Adam"
    What are the options for doing this? Thanks.

  • #2
    The key is to enclose the quotation mark in what Stata calls compound quotation marks, and to remember that "+" is how to concatenate strings in Stata.
    Code:
    `" and "'
    So for example
    Code:
    . clear
    
    . set obs 1
    number of observations (_N) was 0, now 1
    
    . generate str50 text = "my name is Adam"
    
    . generate str50 new  = `"""' + text + `"""'
    
    . list, clean noobs
    
                   text                 new  
        my name is Adam   "my name is Adam"  
    
    .
    Or
    Code:
    . generate str50 text = `""my name is Adam""'
    
    . list, clean noobs
    
                     text  
        "my name is Adam"
    Last edited by William Lisowski; 14 Feb 2019, 09:44.

    Comment

    Working...
    X