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

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

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

Dear Listeners,

using Stata 8.2 (just updated) on Win XP, I attempt to

. simulate "simPTM1" bM=_b[M], reps(20)

The program simPTM1 contains an -nl- estimation and I get the following error whenever the estimation lacks convergence:

convergence not achieved

command -> simPTM1
an error occurred when command was executed on original dataset
please rerun and specify the trace option to see a trace of the commands

I would rather like that -simulate- posts a missing value for bM in that
round and continues with the next round of replication. Actually, that
is what Jeff Pitblado promised in a previous Statalist response:

Any hints?

The complete do-file is appended below.
(Any advise on the -nl- program is also appreciated.)

Many thanks

----begin do-file
version 8.2
set mem 100m
set matsize 800
set more off

program drop _all

program nlPTM1SalR
version 8.2
if "`1'" == "?" {
global S_1 "NLS estimation of PTM1 for period sales /*
*/ (constrained parameters)"
global S_1 "EM ETH EP EQ"
local exp "[`e(wtype)' `e(wexp)']"
global EM=6.8
global ETH=-.4
global EP=-1.7
global EQ=-3

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 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*/
nl PTM1SalR RealSales
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)

set seed 8

simulate "simPTM1" bM=_b[EM] bTH=_b[ETH] bP=_b[EP] bQ=_b[EQ] /*
*/ rmse=e(rmse) rsq=e(r2) iter=e(ic) Dconv=e(converge), reps(20)
summarize, detail
----end do-file

* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index