Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Problem with temporary variable and macro suffix |
Date | Thu, 29 Aug 2013 17:29:00 +0100 |
Works for me (in Stata 10.1) Not quite documented, but temporary variables (used to) have names beginning with __ and followed by 6 characters assigned by Stata, so that you can (could) add suffixes in practice, although somewhere Stata says that you shouldn't assume that you can do that. That aside, this is idiomatic foreach a in element1 element2 element3 { tempvar this gen `this' = . local all `all' `this' } followed typically by loops over `all'. Nick njcoxstata@gmail.com On 29 August 2013 17:21, Thomas Lux <tholux2000@yahoo.de> wrote: > I have a little problem with temporary variables in my program. > > I want to create temporary variables with some foreach-elements as a suffix. > I did: > > foreach a in element1 element2 element3 { > tempvar new`a' > gen `new`a'' = . > } > > But this does not work. > I there any other way to do it? > > > Best, > Thomas > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/