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

From |
"Eva Poen" <eva.poen@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Programming Problem: How to prevent macro substitution |

Date |
Wed, 16 Jul 2008 17:18:14 +0100 |

Thanks, Nick. However, your suggestion does not produce the desired result: . di "`xlist'" i.land|ldep0 i.land|ldep1 i.land|ldep2 While Christoph was after: . di "`xlist'" i.land|`ldep0' i.land|`ldep1' i.land|`ldep2' Unless I am missing something here. Eva 2008/7/16 Nick Cox <n.j.cox@durham.ac.uk>: > I agree. In fact, I'd go one step further: > > foreach u of numlist 0/2{ > local xlist `xlist' i.land|ldep`u' > } > > Sometimes the quotes just make things more complicated. > > Nick > n.j.cox@durham.ac.uk > > Eva Poen > > take it in steps and it works: > > foreach u of numlist 0/2{ > local xlist "`xlist' " "i.land|" "`" "ldep`u'" "'" > } > > > -di "`xlist'"- returns > > i.land|`ldep0' i.land|`ldep1' i.land|`ldep2' > > on my machine. > > 2008/7/16 Christoph Birkel <christoph.birkel@soziologie.uni-halle.de>: > >> 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' i.land|``ldep`u'''" >> } >> The resulting macro should contain an expression like " i.land|`ldep0' >> i.land|`ldep1' i.land|`ldep2' " (when `y2' contains 2) which > can be >> used as argument in -xi: reg-, as in: xi: reg yvar i.land `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 " i.land|ldep0 i.land|ldep1 i.land|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. > > * > * 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/

**Follow-Ups**:**RE: st: Programming Problem: How to prevent macro substitution***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: Programming Problem: How to prevent macro substitution***From:*Christoph Birkel <christoph.birkel@soziologie.uni-halle.de>

**Re: st: Programming Problem: How to prevent macro substitution***From:*"Eva Poen" <eva.poen@gmail.com>

**RE: st: Programming Problem: How to prevent macro substitution***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: Programming Problem: How to prevent macro substitution** - Next by Date:
**st: Stata and biology/biomedical sciences** - Previous by thread:
**RE: st: Programming Problem: How to prevent macro substitution** - Next by thread:
**RE: st: Programming Problem: How to prevent macro substitution** - Index(es):

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