[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Programming Problem: How to prevent macro substitution

From   Christoph Birkel <>
Subject   st: Programming Problem: How to prevent macro substitution
Date   Wed, 16 Jul 2008 16:57:28 +0200

Dear All,

I want to program a loop which produces a macro `xlist' containing a list of dummy variable interaction expansion expressions with temporary variable names `ldep0' , `ldep1' etc. as a string . For this purpose I wrote:
foreach u of numlist 0/`y2'{
local ldep`u' "ldep`u'"
local xlist "`xlist'|``ldep`u'''"
The resulting macro should contain an expression like "|`ldep0'|`ldep1'|`ldep2' " (when `y2' contains 2) which can be used as argument in -xi: reg-, as in: xi: reg yvar `xlist' . (The temporary variables `ldep0' and so on, corresponding to the macros are generated later in a separate loop.)
What actually happens, is that, due to the single quotation marks, the macros containing the names of the temporary variables are subsituted by their content (which should not happen), so the content of the resulting macro is "|ldep0|ldep1|ldep2 ", which cannot be used to refer to temporary variables. For the same reason, it is not possible to define a local macro with a string as content which starts and ends with quotation marks. I found no way to avoid the unintended macro substitution using "\" or compound quotes. Any recommendation is highly appreciated.

Christoph Birkel
Christoph Birkel, M.A.
Wissenschaftlicher Mitarbeiter
-Studienfachberater BA-Studiengänge Soziologie-
Martin-Luther-Universität Halle-Wittenberg
Institut für Soziologie
D-06099 Halle (Saale)
Tel.: ++ 49 3 45 / 55 24 22 5
Fax.: ++ 49 3 45 / 55 27 14 9

* For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index