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]
Re: st: looping over several macros
From
Maarten buis <[email protected]>
To
[email protected]
Subject
Re: st: looping over several macros
Date
Tue, 15 Feb 2011 16:28:47 +0000 (GMT)
--- On Tue, 15/2/11, John Holmes wrote:
> I want to perform a transformation on the variable
> 'drating' based on the values of three local macros
<snip>
> On the first loop, I want to use the first values
> in all of the macros `change', `1994' and
>`1994_shift', on the second loop I want to use
> the second values in all of the macros and so on.
Is this what you are looking for:
*------------ begin example ----------------
local foo "a b"
local bar "1 2"
forvalues i = 1/2 {
local part_foo : word `i' of `foo'
local part_bar : word `i' of `bar'
di "`part_foo' `part_bar'"
}
*-------------- end example -----------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )
As a general programming strategy such paralel
lists are not very robust. It is very easy for a
user to make a mistake when specifying such list.
If you are just doing this for a one off .do file
then this is less of a concern (but double check
the content of your macros...).
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/