Bookmark and Share

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: RE: RE: looping / refering to multiple variables


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: RE: RE: looping / refering to multiple variables
Date   Thu, 6 Oct 2011 11:22:14 +0100

I naturally agree in general. In this case the numbers all seem likely to be moderate. 

Nick 
[email protected] 

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Maarten Buis
Sent: 06 October 2011 10:57
To: [email protected]
Subject: Re: st: RE: RE: looping / refering to multiple variables

2011/10/6 Nick Cox <[email protected]>:
> 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/

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index