Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: how to handle this type of strings: "text (i.e it containes only one ")


From   Eric Booth <ebooth@ppri.tamu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: how to handle this type of strings: "text (i.e it containes only one ")
Date   Sat, 20 Feb 2010 10:44:42 -0600

>

A couple of issues that I can see:  1) there is no -delete- command (though you got the right error
message, so that is probably just a typo) (2) if you want to say -drop- if a condition is true (say 
variable is "a"), then you type "drop if variable=="a" with double equal signs.  The trick is to work
with single and double quotes (see -help quotes-). When Stata evaluates your expression, it see the
first set of double quotes in ""text" and sees the extra double quote (after the word "text") as an 
unmatched pair.  If you put single left and right hand quotes around this expression then it will work.  

Here's an example:

*---------------------------BEGIN EXAMPLE
clear
input str8 var
 `""text"'
 "text"
  end
  
 g flag = strpos(var, `"""')
drop if flag>0

**or to just get rid of the quotes:
clear
input str8 var
 `""text"'
 "text"
  end
  
replace var = subinstr(var, `"""', "", .)
*---------------------------END EXAMPLE


~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
ebooth@ppri.tamu.edu
Office: +979.845.6754
Fax: +979.845.0249
http://ppri.tamu.edu

On Feb 20, 2010, at 10:18 AM, Adrian Gonzalez wrote:

> Dear members
> 
> I have a string VARIABLE that contains the following value "text (the " is part of the string value).
> 
> and I want to delete those rows , but when i write
> delete if VARIABLE=""text"
> 
> I get the following error
> too few quotes
> r(132);
> 
> i am using Stata 10.1
> 
> Thanks for your help
> 
> 
> 
> 
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index