Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Maria Ana Vitorino <vitorino@wharton.upenn.edu> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: RE: macro of macros? |

Date |
Sun, 6 Nov 2011 10:20:06 -0500 |

Thanks Nick. This is very helpful.

If I add another set, say set 4 I need to do: local set4 "x5 x6" local index `index' 4 but suppose that what I do (by mistake) is local set4 "x5 x6" local index `index' 3

Thanks! Ana On Nov 6, 2011, at 10:07 AM, Nick Cox wrote:

Wildcards are for variable names only. But you don't need any suchdevice here. There are various ways to approach what you want.Here's one:local index local set1 "x1 x2" local index `index' 1 local set2 "x2 x3" local index `index' 2 foreach i of local index { reg y xvars `set`i'' } Nick n.j.cox@durham.ac.uk Maria Ana Vitorino I've only recently started experimenting with macros and I have the following question: can we have a macro of macros and loop through the different sub-macros without having to set beforehand how many sub- macros there are in the macro? Maybe it's easier to understand what I'm looking for with an example: I know that the following can be done: local set1 "x1 x2" local set2 "x2 x3" local sets ""`set1'" "`set2'"" *** foreach xvars of local sets { reg y xvars } But, instead of having to list all the macros in the line ***, can we have something like: local set1 "x1 x2" local set2 "x2 x3" local sets ""`set'*"" foreach xvars of local sets { reg y xvars } Ideally I would like to add (or remove) sets as a please so I wouldn't like to have to keep updating the line *** everytime I do so... * * 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: RE: macro of macros?***From:*Nick Cox <n.j.cox@durham.ac.uk>

**References**:**st: macro of macros?***From:*Maria Ana Vitorino <vitorino@wharton.upenn.edu>

**st: RE: macro of macros?***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: basic question on nl** - Next by Date:
**RE: st: RE: macro of macros?** - Previous by thread:
**st: RE: macro of macros?** - Next by thread:
**RE: st: RE: macro of macros?** - Index(es):