Bookmark and Share

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]

st: Recursively build local macro with "" around each addition


From   Richard Herron <[email protected]>
To   [email protected]
Subject   st: Recursively build local macro with "" around each addition
Date   Mon, 13 Feb 2012 15:01:19 -0500

I would like to recursively build a local macro that wraps each
addition in double quotes.

For example, I loop slowly over "lo" and "hi" states of words in the
first local macro, and quickly over "lo" and "hi" states of the second
local macro. The following code generates a local macro that properly
orders the states, but doesn't wrap each addition in double quotes.

* begin code
local output
local arg1 ten
local arg2 one two
local state lo hi

foreach a1 of local arg1 {
    foreach a2 of local arg2 {
        foreach s1 of local state {
            foreach s2 of local state {
                local output "`output'" "`a1' `s1', `a2' `s2' "
            }
        }
    }
}
display "`output'"
* end code

The output is in the correct order, but doesn't have double quotes
around each addition.

. ten lo, one lo ten lo, one hi ten hi, one lo ten hi, one hi ten lo, two
> lo ten lo, two hi ten hi, two lo ten hi, two hi

Instead, I would like the following.

. "ten lo, one lo" "ten lo, one hi" "ten hi, one lo" "ten hi, one hi"
"ten lo, two
> lo" "ten lo, two hi" "ten hi, two lo" "ten hi, two hi"

I will use this string as an argument for the -mtitles()- option in
-esttab- in SSC's -estout- package (-ssc install estout-).

I tried combinations of `' and "" that seemed logical, but got either
-invalid syntax- or only the last addition without double quotes and
-lo not found-. (E.g., I thought that -local output "`output'" `""`a1'
`s1', `a2' `s2' ""'- would provide double quotes, but this also yields
-invalid syntax-).

Thanks!
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index