Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: RE: RE: looping / refering to multiple variables


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
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 
n.j.cox@durham.ac.uk 

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Maarten Buis
Sent: 06 October 2011 10:57
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: RE: RE: looping / refering to multiple variables

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/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index