Statalist


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

Re: Re: AW: st: How to use the marco names?


From   [email protected]
To   statalist<[email protected]>
Subject   Re: Re: AW: st: How to use the marco names?
Date   Fri, 07 Aug 2009 02:05:08 +0800

Nick and Martin, thank you very much!

Just as Nick pointed, I recognized my confusion was the use of -di-. However, I do need learn the use of -macro- too.

A doubt appears when learning the use of -di-. What is the difference between "" and `""'? 
In -di- help,I guess the only difference is the latter allows embedded quotes, am I right?

Additionally, there is a small question below.
. foreach i in a" "b" "c {
  2. di `"`i'"'
  3. }
a"
b
c
Where is the quote before c. Namely, I think the result should be 

a"
b
"c

Thank you again for any help!

Best regards,

Rose.

----- Original Message -----
From: Nick Cox <[email protected]>
To: [email protected]
Subject: Re: AW: st: How to use the marco names?
Date: 2009-8-6 23:47:19

Not so.

First off, a literal string here is one marked as such by " " or `" "' 
delimiters.

Second, it is key that the -display- command never sees the text

`level'

as it is a reference to a local macro. Stata replaces the reference to 
the macro with its contents _before_ -display- ever gets to work. So, 
-display- sees

a b c

and without the " " that is not a literal string.

nICK

[email protected] wrote:

> Nick, thank you for your help, which lets me understand more.
> 
> I suddenly think of the following typing,
> 
> .local level a b c
> 
> . di "`level'"
> a b c
> 
> . di `"level"'
> level
> 
> . di `level'
> a not found
> r(111);
> 
> If -di- is to display literal strings or the contents of the names 
> supplied, the results for the above three should be,
> 
> `level' // literal string
> 
> error // no local name "level",but local name level.
> 
> a b c // the contents of the names.
> 
> 
> Please forgive my ignorance, thank you.
> 
> Best regards,
> 
> Rose.
> 
> 
> 
> 
> 
> ----- Original Message -----
> From: Nick Cox <[email protected]>
> To: [email protected]
> Subject: Re: AW: st: How to use the marco names?
> Date: 2009-8-6 22:38:04
> 
> In addition to other advice, note that a major issue here is not macros, 
> but the use of -display-.
> 
> -display- is quite happy to display several things one after another. It 
> is also happy to display literal strings or the contents of the names 
> supplied. The " " or `" "' are essential to disambiguate.
> 
> Thus for example
> 
> di "a b c"
> 
> is an instruction to display the literal string "a b c". -display- 
> neither knows nor cares what that string means.
> 
> In contrast,
> 
> di a b c
> 
> is an instruction to display the contents of a, followed by the contents 
> of b, followed by the contents of c. -display- now needs to work at 
> finding out what a, b and c are.
> 
> Nick
> 
> Rose a.k.a. [email protected] wrote:
> 
>> Dear Martin,Dan and others,
>>
>> I am completely confused by the use of local marco.
>>
>> Take some examples,
>> r(files) after -fs- 
>>
>> r(names) after -est dir-
>>
>> r(mean) after -su-
>>
>> //maybe the three above are not local marco, but I need to use it in my following procedure.
>>
>> r(levels) after -levelsof-
>> // it seems different when the type of variable following -levelsof- is different.
>> ........
>>
>> How to display and use them in my follwing procedure?
>> di `r(levels)'
>> di `"`r(levels)'"'
>> di `r(files)'
>> di `"`r(files)'"'
>> di `r(names)'
>> di r(mean)
>>
>> Something similar is,
>> local x="1 2"
>> local x "1 2"
>> local x 1 2
>> local x: r(mean)
>>
>> Concretely, when to add single quote and double quote? when to use colon?
>> especially,the difference among them.
>>
> 
> *
> * 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/
> 
> 
> ------------------------------------------------------------------------
> 
> 
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.392 / Virus Database: 270.13.45/2285 - Release Date: 08/06/09 05:57:00
> 
*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index