Bookmark and Share

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


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

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


From   Charles Vellutini <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: handling the quote character stored in a string variable
Date   Mon, 9 Jan 2012 07:16:26 -0800

Dear Nick and Dan,

Your solution (using compound quotes) worked perfectly.
Many thanks,
Charles

-----Message d'origine-----
De : [email protected] [mailto:[email protected]] De la part de Dan Blanchette
Envoyé : lundi 9 janvier 2012 16:04
À : [email protected]
Objet : Re: st: handling the quote character stored in a string variable

Charles,

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
[email protected]



> 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 :
>
>
>                               marqueur
>
> obs 1                     [
>
> obs 2                     "
>
> obs 3                     r
>
> obs 4                     "
>
> etc.
>
> Any idea on how to run tests on the quotation mark stored in a string variable ?
>
> Thanks,
>
> Charles
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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