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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: RE: RE: literal single quotes


From   Nick Winter <nwinter@virginia.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: literal single quotes
Date   Thu, 04 Mar 2010 12:58:25 -0500

Try

local bull = "count if " + char(96) + "temp" + char(39) + ">0"

You need to get the char() function to be evaluated, which doesn't happen inside the quotes.

Seems likely to me that costs of making the code more confusing might outweigh the benefits of clean-looking code, but to all their own, I suppose. :-)

Nick Winter

On 3/4/2010 12:48 PM, Feiveson, Alan H. (JSC-SK311) wrote:
Thanks, Roger, Nick

Both suggestions work, but something like

. local bull =  "count if char(96)tempchar(39)>0"
. `bull'

unknown function ()
r(133);


does not work.




. local lq = char(96)

. local rq = char(39)

. local bull =  "count if `lq'temp`rq'>0"

. `bull'
   334

(works)


. local bull   "count if  \`temp\'>0"

. `bull'
   334

(works)


Nick - I see a legitimate need for this when you have a long expression involving temporary variables or names that may make the code look ugly if written out next to some other long statement.

Al




-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Thursday, March 04, 2010 11:37 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: literal single quotes

This sounds like the urge for setting up a delayed evaluation, on which
my advice is

1. Use \` to insert a literal left quote if the urge is overwhelming.

2. Better, resist the urge. Rewrite your code so that you don't need to
do it.

This came up a few months ago, but I can't find my post. Martin Weiss
will probably remember it.

Nick
n.j.cox@durham.ac.uk

Feiveson, Alan H. (JSC-SK311)

Can someone please tell me how to define a local macro  that contains
literal single quotes? For example Suppose I want to do something like

local bull "count if `temp'>  0"

where `temp' is to be interpreted literally, not evaluated.

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

--
--------------------------------------------------------------
Nicholas Winter                                 434.924.6994 t
Assistant Professor                             434.924.3359 f
Department of Politics                  nwinter@virginia.edu e
University of Virginia          faculty.virginia.edu/nwinter w
S385 Gibson Hall, South Lawn  Map: http://tinyurl.com/uvaSLmap
*
*   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