Stata Technical Bulletin
23
Step 2: Model coding
The model equations have to be written in a form understandable by the simula command. simula uses two kinds of
files: the model file and the exogenous variable file. The models must be saved in the a string variable named .model in the
model file. There are six kinds of statements recognized by simula: state equations (denoted by S), auxiliary equations (denoted
by A), rate equations (R), exogenous variable declarations (E), initial value assignments to the state variables (I), and parameter
value assignments (P).
The above symbols ( S, A, R, E, I, and P), placed as the first character of each line identifies the statement type. simula
parses the statements in a way requiring the following rules:
1. Line structure: each statement is composed of three parts:
a. a statement identifier (the capital letters S, A, R, E, I, or P);
b. the statement itself (equation, declaration, assignment); blanks inside are not allowed;
c. a statement label, which is optional and must be separated by a blank, at least, from the statement.
2. Comment lines: Any character different from S, A, R, E, I, and P in the statement identifier position, denotes a comment
line.
3. Line order: The model list can contain the statements in any order. The only exceptions are
a. when an auxiliary variable (e.g., aux2) depends on another auxiliary variable (e.g., auxl); in this case, the equation
for auxl must precede the aux2 equation.
b. initial values declaration must follow the related state equation.
4. All the statement kinds allow only one expression/declaration/assignment per line. For example, it’s not possible to write
the lines: “E rain temp”, “I X=IOO Y=50”, “P Kl=5 K2=7; they should be rewritten as “E rain”, “E temp”, “I X=100”,
etc.
5. Constant values: The S, A, R, I and P statements allow constant values. Arguments for the special functions are to be
parameters or auxiliary variable (ex: the delay time) and are not constant.
6. Special functions: Right now simula has three special functions: IDL (information delay), MDL (material delay), and SWTC
(switching a rate on/off). Functions can only be specified in the rate equations; arguments must be parameters or auxiliary
variables.
7. Blank lines: Between two statements it is possible to insert up to, but not more than, one blank line. This insertion could
be useful to make clear the reading of the model.
8. Parameters and initial values: It is not necessary to declare all the parameter and initial values in the .model variable, but
this is a good practice. Whether specified or not, it is possible to assign those values as an option in the simula command.
(Of course, all parameter and initial values need to be declared eventually so, if they are not declared in the model file,
they must be declared when the simula command is given.)
9. Statement syntax: The syntax for each type of statement is
S svar1=svar1+dt*(rvar1 ± rvar2 ± ...) label
a avar=exp label
R rvai—exp label
E evar label
I svar=# label
I svar=f(p^) label
P pname=# label
P pname=f(p^) it label