Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: suppress error messages


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: suppress error messages
Date   Tue, 8 May 2007 17:04:23 +0100

In the same spirit, there is no reason to 
exclude inside the loop (possibly many times)
when you can exclude outside the loop (just once). 

I won't try to modify Lukas' original example code, 
which is schematic. 

But suppose you want to do something for each 
distinct value of -group-, except that you 
also need at least 13 valid observations on 
some <varlist> to play some game. 

egen any_missing = rowmiss(<varlist>) 
bysort group any_missing : gen byte OK = (_N > 12) & (anymissing == 0) 
egen newgroup = group(group) if OK 
su newgroup, meanonly

forval i = 1/`r(max)' { 
	... if newgroup == `i' 
	...
} 

Nick 
n.j.cox@durham.ac.uk 

Friedrich Huebler
 
> Lukas,
> 
> See -help capture-. You can also add an -if- statement at the
> beginning of the loop that checks if the current model can be
> estimated.
> 
> forvalues i = 1(1)5000 {
> 
>   * Move to next regression if condition is true
>   if [condition, e.g. sample size too small] {
>     continue
>   }
> 
>   [other commands]
> 
> }

Lukas Mohler <Lukas.Mohler@unibas.ch> wrote:
 
> > I'm running several thousand regressions within a forvalues loop.
> > It goes like
> > this:
> > 
> > forvalues 1(1)5000{
> > 
> > ivreg2 ..... if selection==x_1, gmm robust
> > 
> > x_1=x_1+1
> > 
> > estout .....
> > 
> > }
> > 
> > For some values of selection I do not have enough observations to
> > estimate the
> > model. Also, other problems could arise with the data.
> > 
> > This is why I'd like to suppress all possible error messages and
> > continue to loop through my regressions.
 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index