Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Macros and -subinstr-


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Macros and -subinstr-
Date   Mon, 26 Jul 2004 16:36:30 -0700 (PDT)

I would like to automate the processing of some data files. First, I
create a macro that contains a list of all data files. Then I try to
exlude one or more files from the list. For example, let's say my
directory contains these data files, in addition to some other files:

france 2002.dta
germany 2001.dta
united states 2002.dta

With the commands below I create a list of files and then try to
remove the listing for the United States.

. local files: dir . files "*.dta"
. di `files'
france 2002.dtagermany 2001.dtaunited states 2002.dta
. local files2 = subinstr(`files',"united states 2002.dta","",.)
. di "`files2'"
france 2002.dta

Is the way I create the list of files correct? Why does the macro
"files2" only contain France? Finally, why do I have to use compound
quotes to list the content of the macro "files2"?

One solution I came up with is to add an -if- condition to my loop
but I would like to understand how I can remove the United States
from the macro "files" before the -foreach- loop.

. foreach file of local files {
.   if "`file'" != "united states 2002.dta" {
.     ...
.   }
. }

Many thanks in advance,

Friedrich Huebler


		
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail
*
*   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