Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: How can I prevent -simulate- from stopping after non-convergence?


From   Jonathan Beck <[email protected]>
To   [email protected]
Subject   Re: st: How can I prevent -simulate- from stopping after non-convergence?
Date   Fri, 15 Jul 2005 15:21:33 +0200

-capture- seems to work. Thanks, Jamie!

Jamie Griffin wrote:
You could use a -capture- loop within your program simPTM1. You could
also use the iterate() option of nl to limit the number of iterations,
if the default of 16000 iterations takes too long.

program simPTM1, eclass
   drop _all
   set more off
   set obs 20
   gen time=_n-1
   /* set parameters to be estimated */
   gen m=1000
   gen type1Sh=.4
   gen q=.5
   gen p=.1
   /* generate dependent variable according to nonlinear model */
   gen
CumSales=m*(1-type1Sh*(exp(-p*time)-(exp(-q*time)*exp(q/p*(1-exp(-p*time)))))-(exp(-q*time)*exp(q/p*(1-exp(-p*time)))))
   gen Sales=CumSales[_n]-CumSales[_n-1]
   replace Sales=CumSales if time==1
   /* generate shock and dependent variable which enters estimation*/
   gen shock1=1+0.1*invnorm(uniform())
   gen RealSales=Sales*shock1
   /* estimate model*/

capture{
   nl PTM1SalR RealSales
/* or e.g.
 nl PTM1SalR RealSales,iterate(200)
*/
}
if e(converge)==1{
   scalar define bM=_b[EM]
   scalar define bP=_b[EP]
   scalar define bQ=_b[EQ]
   scalar define bTH=_b[ETH]
   scalar define rmse=e(rmse)
   scalar define rsq=e(r2)
   scalar define iter=e(ic)
   scalar define Dconv=e(converge)
}
else if e(converge)==0{
/* return something else */
}

end
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index