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]

st: RE: Forcing -post- to post in a -foreach- loop when values are missing


From   philippe van kerm <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Forcing -post- to post in a -foreach- loop when values are missing
Date   Tue, 8 Oct 2013 16:17:09 +0000

Can't you just catch the error?

foreach yvar of local yvars {
   cap  xtnbreg ...
   if ( _rc == 0 ) {
    post ERstats ...
   }
   else {
    * either do nothing or post missing values:  post ERstats (.) (.) ...  
   }		
}

Philippe

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Cam Gillies
> Sent: Tuesday, October 08, 2013 5:59 AM
> To: [email protected]
> Subject: st: Forcing -post- to post in a -foreach- loop when values are
> missing
> 
> Hi All,
> 
> I am using a -foreach- loop to analyze a large number of dependent
> variables
> with -xtnbreg-.  I am posting the results to a file, including the
> random
> effects.  Unfortunately, if the models do not solve the loop stops
> because
> there is no random effect to post to the file.  Is there a way to force
> -post- to post a missing value and carry on? .do code below minus the
> long
> list of variables.
> 
> Thanks very much,
> Cam Gillies
> 
> 
> postutil clear
> postfile ERstats str32 yvar timecoef timepvalue beccoef becp
> bectimecoef
> bectimecoefp treatcoef treatp ///
>     treattimecoef treattimep cons  resite resitesd replot replotse
> error
> using understorey, replace
> local yvars  acer acergla ...
> 
> foreach yvar of local yvars {
> cap  xtnbreg `yvar' timetrre0 bec0 becbytime  treat2 treatbytime if
> hillsites==1 , i(plotid) iter(50)
> post ERstats ("`yvar'") (_b[timetrre0])
> (2*(1-normal(abs(_b[timetrre0]/_se[timetrre0])))) (_b[bec0])
> (2*(1-normal(abs(_b[bec0]/_se[bec0])))) ///
>     (_b[becbytime]) (2*(1-normal(abs(_b[becbytime]/_se[becbytime]))))
> (_b[treat2]) (2*(1-normal(abs(_b[treat2]/_se[treat2])))) ///
>     (_b[treatbytime]) (2*(1-
> normal(abs(_b[treatbytime]/_se[treatbytime]))))
> ///
>     (_b[_cons])    (exp(_b[ln_r:_cons]))
> (_se[ln_r:_cons]*exp(_b[ln_r:_cons])) ///
>     (exp(_b[ln_s:_cons])) (_se[ln_s:_cons]*exp(_b[ln_s:_cons])) (_rc)
> }
> postclose ERstats
> 
> use understorey, clear
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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