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: Quote Quote Unquote Unquote??


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Quote Quote Unquote Unquote??
Date   Fri, 25 Mar 2011 12:30:16 +0000

I got private mail requesting help in putting double quote characters
_into_ variables. For Statalist policy on not bugging active members
please do see

http://www.stata.com/support/faqs/res/statalist.html#private

In addition to the several reasons given there, some more can be added:

* Some people send a flurry of little emails to several active members
at about the same time while obscuring the fact that they are doing
it. That can lead to yet more wasted time and bad impressions.

* If you take a thread private, you can miss out on better advice.
Whoever posts first could be giving the wrong answer. (That certainly
includes me.)  Keep the thread public and better advice may follow.
Some well-informed users may initially  ignore an obscure question
they don't understand, but may nevertheless be able to improve on
other suggestions once they see what the problem is or they know that
a solution is a lousy one.

Back to the question:

The principle is just the same. To make it clear that you want literal
" characters you would have to wrap them in compound double quotes.

sysuse auto
gen make2 = `"""' + make + `"""'

Another way to do it is to use -char()-.

gen make3 = char(34) + make + char(34)

For a visual record of what -char()- does on your machine, see
-asciiplot- from SSC.

Still, it is difficult to see why anyone wants this!

Nick

On Wed, Mar 23, 2011 at 2:24 PM, Nick Cox <[email protected]> wrote:

> -subinstr()- is a function, not a command.
>
> The problem here is that the double quote character -- I will assume
> that you are not concerned with single quotes -- has two roles: it can
> be a string delimiter and it can stand for a literal character. Also,
> if you nest double quotes, the result will be  ambiguous. The solution
> to both of these problems is to use a Stata invention, compound double
> quotes, in which `"  (left single quote followed by double quote) is
> an opening delimiter and "' (double quote followed by right single
> quote) is a closing delimiter. In terms of what you type, these are
> two characters each, but they are to be interpreted as composites,
> just as == and <= and >= are two characters standing for single
> entities.
>
> You want
>
> replace variable = subinstr( variable, `"""', " ",.)
>
> Note that what you are describing is not removing double quote
> characters, so much as replacing them with spaces. If you just want to
> remove them, then
>
> replace variable = subinstr( variable, `"""', "",.)
>
> is clearly the alternative to use.
>
> Nick
>
> On Wed, Mar 23, 2011 at 2:05 PM, miyu Lee <[email protected]> wrote:
>
>> I have a small issue regarding quotation marks:
>>
>> I want to remove all quote marks from my dataset, seems it doesnt work
>> with the substring command.
>>
>> For example, "replace variable = subinstr( variable, """, " ",.)"
>>
>> (that is triple quotation marks) doesnt work, (rightly) saying "too few quotes"
>>
>> or: "replace variable = subinstr (variable, """", " ", .)" works -
>> unfortunately removing everything within quotation marks.
>>
>

*
*   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