Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: foreach global macro not working with multiple macros
From
"Seed, Paul" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: foreach global macro not working with multiple macros
Date
Thu, 3 Feb 2011 11:45:34 +0000
I re-wrote Eric's program to collect local macro names
beginning with c, rather than global.
Like Nick Cox, I use locals more often.
There is one non-trivial change that I thought was worth sharing.
******* Grabbing list of all local macros that start with "c"
local cash "pocket asdf bank"
local check "bank"
local c3 "blah blah"
local c99 "test"
local z1 "ignore this one"
*******get names of all locals
preserve
cap log close _all
log using "macros.txt", text replace
macro li
log close _all
clear
insheet using macros.txt, tab nonames
**first 6 and last 6 lines are from log, remove those:
drop in 1/6 // Eric dropped only 4 lines. I am not sure why.
drop in `=_N+1-6'/l // Using _N-6 would drop 7 lines,
// including one of the local macros!
**keep if first two letters are _c
keep if substr(v1, 1, 2)=="_c"
*get names of all locals that start with "c"**
split v1, p(": ") // splits v1 into v11 (the local name, before the colon) & v12 (the description, after the colon).
keep v11
replace v11 = substr(v1,2,.) // Drop the initial underscore
levelsof v11, loc(local_c) clean
global local_c `local_c'
di `"$local_c"'
restore
********
foreach y of global local_c {
display "`y'"
}
****
*
* 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/