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: creating/manipulating matrices with nested loop
From
Sergiy Radyakin <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: creating/manipulating matrices with nested loop
Date
Wed, 31 Jul 2013 17:34:31 -0400
One way to approach this kind of problems is to "unwind the loop". It
is typically used for performance optimizations, but can be used for
designing the looping program too if turned backwards.
Consider the following example. You seek something like:
for i=1 to 5
print i
next i
instead you first write
print 1
print 2
print 3
print 4
print 5
and make sure you are getting the desired result (variable Var3 is all
populated with desired values)
Then you look at what changes and what can be looped. Define the
iteration blocks and parametrize them with the loop index. So start
with 2 countries and 2 years and write down everything without any
loops. Use Ctrl+C/Ctrl+V if necessary.
As for the specifics of your task, if you have M countries, (and
suppose only 1 year), you will have M(M-1) (M times M-1) results that
you would want to put to Var3, but you will only have M values there.
So how do you want the results to be stored?