Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: handling the quote character stored in a string variable

From   Dan Blanchette <>
Subject   Re: st: handling the quote character stored in a string variable
Date   Mon, 9 Jan 2012 10:03:39 -0500 (EST)


This is a situation where using compound quotes in Stata are required
(which is what Nick Cox suggested):

 . gen type_corr= "expression"  if marqueur_type2 == `"""'

This will give you more help:

 . help strings

Also, when you expect that there are no leading or trailing blanks it
is good to make sure that is truly the case by using the function trim() :

 . gen type_corr= "expression"  if trim(marqueur_type2) == `"""'

Dan Blanchette
Research Programming Services
Carolina Population Center
University of North Carolina

Dear Statalisters,

I have a string variable ("marqueur" in the code below) which contains a single quotation mark for certain observations (the data is from Google's Adwords and keywords are enclosed in quotation marks when the correspondence type is based on the exact expression). However, Stata rejects a test on the quotation mark used as a character.  I get the error message "too few quotes" when I run the following code:

     gen type_corr = "expression" if marqueur_type2 == """

and the data is like this :


obs 1                     [

obs 2                     "

obs 3                     r

obs 4                     "


Any idea on how to run tests on the quotation mark stored in a string variable ?



*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index