24
Stata Technical Bulletin
STB-8
where svar state variable name
avar auxiliary variable name
rvar rate variable name
evar exogenous variable name
pname parameter name
f (p) function of parameters or other parameters, already declared
in the model code list
# numeric constant
dt time step for the equation integration; it is inserted only to
identify a state equation but, really, any character set differing by
‘+’ or ‘*’ is allowed.
exp any algebraic expression containing #, pname, evar, avar, and svar.
In the expression, all the Stata functions can be used. For example,
it is possible to use the random generator function uniform()
label a descriptor of the statement (optional)
10) Special functions: simula recognizes some special functions that, indicated in the rate equations, perform some specific
tasks. These can be indicated only in the rate equations: moreover, each rate equation allows only one function. The syntax
of the functions is
R rvar=fcn expp, arg, arg,...]
where fcn is one of the special functions, exp is an algebraic expression and arg are the arguments needed by the function
itself. The available functions are, right now:
IDL information delay function. The syntax is “R rvar=IDL Xxpp d dly] ”, where dly is the delay time. The effect on rvar is
rvart = exp(t — dly) if t > dly and rvart = 0 otherwise.
MDL material delay function; this function has the same effect of a further level inserted in the flux, but not available to the user.
The syntax is “R rvar=MDL Xxxp d dly] ”, where dly is the delay time. The effect on rvar is rvart = rvart + exp(t — dly)
if t > dly and rvart = 0 otherwise. dly is expressed in time units. It must be a parameter or an auxiliary variable
name (not a constant or expression).
SWTC switch to rate on/off. The syntax is “R rvαz=SWTC[xxp,cvαr,von,vojf]”; sets the rate to zero if a control variable
cvar is below a low threshold value von or reaches an upper threshold voff. The results are rvar = 0 if cvar < von ;
rvar = exp if cvar > von and cvar < voff; and rvar = 0 if cvar ≥ voff. SWTC can be used to perform the tasks:
Represent a state variable with a physical limit and with the inflow rate independent from the level: von is set to 0
and voff to the maximum level capacity; cvar is the level itself.
Represent a process starting and/or stopping at some defined times: the control variable is _time; von and voff are the
starting and ending times.
Give a pulse of material at a specific time only (von = voff).
Simulate processes conditionally associated to other variables.
11) Simulation set-up: Time step, time span and time of start are defined by the command and not in the program.
Example of model coding
The .dct file containing a Volterra example model (without delay):
dictionary ■(
* file "volmodi.det"
* example model for "simula" STATA command (4/11/91)
* This is a kind of a VOLTERRA model - without delay
* Ref. J. Maynard Smith, 1974. Models in ecology. Cambridge University Press.
str70 _model "Model statements"
1
"* Prey Predator Volterra model "* STATE equations ----------- "S X=X+dt*(Bx-Dx) "S Y=Y+dt*(-Dy+By) |
- without delay |
" " " " | ||
Prey population (n) |
(n) | |||
"* |
RATE equations ------------ |
" | ||
"R |
Bx=Kbx*(Cc-X) |
Birth rate of prey |
(n∕year) |
" |
"R |
Dx=Kmx*X*Y |
Death rate of prey |
(n∕year) |
" |
"R |
Dy=Kmy*Y |
Death rate of predator (n∕year) |
" | |
"R |
By=Kby*Y*(X-Y) |
Birth rate of predator (n∕year) |
" |