Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Writing in SMCL - two issues, compound double quotes and number formats


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Writing in SMCL - two issues, compound double quotes and number formats
Date   Mon, 2 Oct 2006 11:07:28 +0100

The first issue here is illustrated by this: 

. local myif if substr(make,1,1) == "A"

. di as res "`myif'"
if substr(make,1,1) == A"" invalid name
r(198);

. di as res `"`myif'"'
if substr(make,1,1) == "A"

In other words, if a macro contains double 
quotes, -display- can easily get confused and it 
is necessary to use compound double quotes. 
David knows this and wants to know the best way 
to proceed. 

If I were in David's position I would go for 
a "slowly but surely" strategy. If the example 
above were extended to include text before and 
after then 

di <whatever> _c 
di as res `"`myif'"' _c 
di <something else> 

will work. Once you have got the equivalent working 
it may be tempting to reduce the number of command 
lines, but that's your call. Notice that this way 
nothing is displayed if the macro is empty (or 
equivalently, undefined), which is a small but useful
feature. 

The second issue is whether SMCL allows on-the-fly 
formatting. I believe the answer is No. In essence, 
you are expected to do that upstream of a SMCL call. 

-display- lets you do lots on the fly, as is evident; 
it is a hybrid calculate and display command, which 
might be regarded as in bad computing taste, but that 
is extremely useful. However, SMCL as such is 
independent of -display-. 

Nick 
[email protected] 

David Elliott wrote 

I have been converting some routines I have written to SMCL and have
run into a couple of issues.

for example the line:
        di in gr _n(2) "Category: " in ye "`ititle'" "  (" `"`if'"' ")"_n
and what one would hope could be its replacement
        di _n(2) "{txt:Category:} {res:`ititle'  ( `"`if'"' )}" _n

However, one cannot use compound double quotes, it terminates the
display at the first `"' and causes an error, but without them any
value of `if' that contains quotes will. cause an error.  One can
code:
        di _n(2) "{txt:Category:} {res:`ititle'} (" `"`if'"' ")" _n
and everything is fine.  I would have thought that one *should* be
able to put any valid display syntax within a {txt: } or {res: }
construct but this does not appear to be the case.

The other issue is not being able to apply numeric formats in the
display command itself:
        di in ye _continue %4.0f `nc' "-" %3.0f `cp' in gr "|"
does not translate to:
        di _cont  %4.0f "{res:`nc'}-" %3.0f "{res:`cp'}" "{txt:{c |}}"
and I have tried experimenting with various permutations without
success.  I could, of course, apply the formats in a prior command,
but am curious if the formats can be applied inline as they can be in
non-smcl output.

I've done searching for smcl "numeric format" and similar searches
without turning up anything useful.  I've also examined a number of
the (BASE) adofiles to see how they have been written to give smcl
output without getting much insight.

Can anyone provide illumination as to how one can use compound double
quotes and formats within a line of smcl { }

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index