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 at the end of May, 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: forcing loops through errors


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: forcing loops through errors
Date   Wed, 27 Jul 2011 09:24:17 +0100

Kyle is pointing in the right direction. Kyle's mailer, no doubt, is
adding iniitial capitals to the lines of code in its ignorance.

See also -statsby-!

forval year = 2000/11 {
      foreach varname of varlist V0_Sev EQ_Sev ET_Sev DR_Sev WF_Sev FL_Sev {
            capture noisily reg killed `varname' if startyear2==`year'
            capture noisily reg totaffected `varname' if startyear2==`year'
            capture noisily reg estdamageusmillion `varname' if
startyear2==`year'
      }
}

forval y = 0/9 {
      foreach varname of varlist V0_Sev EQ_Sev ET_Sev DR_Sev WF_Sev FL_Sev {
            capture noisily reg killed `varname'  quint`y' if startyear2==200`y'
            capture noisily reg totaffected `varname' quint`y' if
startyear2==200`y'
            capture noisily reg estdamageusmillion quint`y' `varname'
if startyear2==200`y'
      }
}



On Wed, Jul 27, 2011 at 7:34 AM, Kyle Peyton <kyle.peyton@unimelb.edu.au> wrote:
> Hi Linh,
>
> Generally if you include "capture" then Stata will continue through despite the error. If you want it to print then you can tell Stata to capture noisily.
>
> Try:
>
> Foreach varname of varlist V0_Sev EQ_Sev ET_Sev DR_Sev WF_Sev FL_Sev {
> Capture noisily reg killed `varname' if startyear2==`year'
> Capture noisily reg totaffected `varname' if startyear2==`year'
> Capture noisily reg estdamageusmillion `varname' if startyear2==`year'
> }
>
> Hopefully this helps!
>
> -Kyle
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Linh Vuong
> Sent: Wednesday, 27 July 2011 4:15 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: forcing loops through errors
>
> Stata/IC 11.2 for Mac (64-bit Intel)
> Born 30 Mar 2011
>
> Hello Statalist!
>
> I'm trying to write a loop that runs through 6 variables: VO_Sev
> EQ_Sev ET_Sev DR_Sev WF_Sev FL_Sev, for 2000-2011.  This is what I
> tried:
>
> forvalues year=2000/2011 {
> foreach varname of varlist VO_Sev EQ_Sev ET_Sev DR_Sev WF_Sev FL_Sev {
> reg killed `varname' if startyear2==`year'
> reg totaffected `varname' if startyear2==`year'
> reg estdamageusmillion `varname' if startyear2==`year'
> }
> }
>
> The first problem I encounter is an error message that says "No
> observations", which is true for some of these regressions.  However,
> I'd like Stata to continue with the loop and do the next regression.
> How can I make Stata continue the loop even though it's finding an
> error?
>
> The second thing I'd like it to do is to add a variable in the
> regression that corresponds to the year.  The variables are quint0
> quint1 quint2 quint3 quint4 quint5 quint6 quint7 quint8 quint9, where
> the last digit corresponds to the year.  For example, quint0
> corresponds to 2000 and quint9 corresponds to 2009.  So I think I want
> something like:
>
> reg killed `varname' quint0 if startyear2==2000
> Any idea on how to write this into a loop?
>

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