Statalist


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

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


From   gjhxmu@sina.com
To   statalist<statalist@hsphsun2.harvard.edu>
Subject   Re: AW: st: How to use the marco names?
Date   Wed, 05 Aug 2009 17:41:46 +0800

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.

Maybe someone can tell me how to learn these in the stata help file if any.

Thank you a lot.
 
Best regards,
Rose

----- Original Message -----
From: Martin Weiss <martin.weiss1@gmx.de>
To: <statalist@hsphsun2.harvard.edu>
Subject: AW: st: How to use the marco names?
Date: 2009-8-3 22:33:34


<> 


". foreach i of local r(files) {

is that r(files) is not considered a local macro."



You can use another -foreach- syntax to get the thing moving, though:


*************
fs d*.dta

foreach file in `r(files)'{
di "`file'"
}
*************



HTH
Martin


-----Urspr黱gliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Dan Blanchette
Gesendet: Montag, 3. August 2009 16:22
An: statalist
Betreff: Re: st: How to use the marco names?

The SSC command -fs-, returns the file names in the 
macro r(files) with double quotes around each filename.
So if you:

. fs *.csv
bs.csv is.csv price.csv big.csv share.csv mag.csv plu.csv


and use compound quotes around `r(files)':

. di `"`r(files)'"'
"bs.csvis.csv" "price.csv" "big.csv" "share.csv" "mag.csv" "plu.csv"

and use compound quotes again when setting the local macro hh:

. local hh `"`r(files)'"'

the double quotes around the filenames will be preserved.
The errors you experienced were due to the internal double quotes and
some of them being removed by Stata since you didn't use compound
double quotes.

The problem with:

. foreach i of local r(files) {

is that r(files) is not considered a local macro.

Hope this helps,

Dan Blanchette
Research Associate
Center for Entrepreneurship and Innovation
Duke University's Fuqua School of Business
dan.blanchette@duke.edu



------------------------------------------------------------
>From gjhxmu@sina.com
To statalist<statalist@hsphsun2.harvard.edu>
Subject st: How to use the marco names?
Date Sun, 02 Aug 2009 14:47:51 +0800

Dear statalists,

I am confused by marco names. Could anyone help me ? 
In my opinion, the following four methods should get the
same results.However, not as I expected.

. fs *.csv
bs.csv is.csv price.csv big.csv share.csv mag.csv plu.csv

. di `r(files)'
bs.csvis.csvprice.csvbig.csvshare.csvmag.csvplu.csv

. local hh `r(files)'

. foreach i of local r(files) {
2. di "`i'"
3. clear
4. insheet using `i'
5. }
{ required
r(100);

. foreach i in `r(files)' {
2. di "`i'"
3. clear
4. insheet using `i'
5. }
bs.csv
(6 vars, 13299 obs)
is.csv
(9 vars, 13403 obs)
price.csv
(4 vars, 2714 obs)
big.csv
(6 vars, 53870 obs)
share.csv
(9 vars, 2755 obs)
mag.csv
(8 vars, 45028 obs)
plu.csv
(7 vars, 2751 obs)

. foreach i in `hh' {
2. di "`i'"
3. clear
4. insheet using `i'
5. }
bs.csv
invalid '"' 
r(198);

. foreach i of local hh {
2. di "`i'"
3. clear
4. insheet using `i'
5. }
bs.csv
invalid '"' 
r(198);

Thank you for any help.

Sincerely,

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

*
*   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   |   What's new   |   Site index