Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

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

From   Cam Gillies <>
To   <>
Subject   st: Forcing -post- to post in a -foreach- loop when values are missing
Date   Mon, 07 Oct 2013 22:57:16 -0600

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:

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