Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Maarten Buis <maartenlbuis@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: RE: RE: looping / refering to multiple variables |
Date | Thu, 6 Oct 2011 11:56:40 +0200 |
2011/10/6 Nick Cox <n.j.cox@durham.ac.uk>: > gen P_nt = 0 > foreach i of global code { > replace P_nt = P_nt + cond(missing(l_avgp`i'), 0, l_avgp`i') * /// > cond(missing(exp_share`i'), 0, exp_share`i') > } It is probably safer to start with -gen double P_nt = 0-, since this is an intermediate computation and you could easily end up adding numbers of very different sizes, which can lead to precision problems. See, e.g. page 557 of Gould (2006) William Gould (2006) Mata matters: Precision. The Stata Journal, 6(4): 550-560. <http://www.stata-journal.com/article.html?article=pr0025> 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/