Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
NEXT?
3. Special Operators
a. DEL
b. SUM
c. PRODUCT
d. ::
E. FUNCTIONS
1. BuiltIn
a. algebra and trigonometry
b. array creation and manipulation
c. character string manipulation
d. matrix algebra
e. missing values
f. output
g. random numbers
h. probability distributions
i. summary statistics
j. programming
k. modelling
l. filesystem (troll databases)
m. external file input/output
n. system interface
o. miscellaneous
p. timeseries and dates
2. UserDefined
F. EXPRESSIONS
G. MODELS
1. Model Files
2. Symbol Table
3. Equations
a. equation numbers
b. equation labels
c. identities that define DEFINITIONtype symbols
H. CALCULATIONS
1. DO Commands
2. Expression Statements
I. TASKS
J. COMMANDS
1. HighLevel Commands
2. LowLevel Commands
3. Utility Commands
K. PROGRAMS
1. Macros
a. userwritten macros
b. macros included with troll
2. UserDefined Functions
L. OPTIONS
1. Bounds
2. System Options
a. log file (LOGFILE and LOG)
b. monthly/quarterly date format (QMPER)
c. see output or not (SCREEN)
d. macro debugging (TRECHO)
e. file locking (LOCKING)
3. Output Options
a. margins
b. paging
c. numbers
d. miscellaneous
4. Convergence/Optimization Options
a. iteration limit (STOP)
b. convergence criterion (CONCR)
c. other general convergence options
d. simulation options
e. other optimization and related options
5. Other Options
a. active date range (DRANGE)
b. active model (USEMOD)
c. regression options (REGOPT)
d. nonlinear least squares options (NLSOPT)
M. COMMENTS
1. Command and Program Comments
2. Equation Comments
3. Model Comments
4. Symbol Comments
5. Data Comments
IV. USING TROLL
A. TROLL LEVEL vs. TASK LEVEL
B. CONSOLE vs. GUI (PC ONLY)
C. INTERACTIVE vs. BATCH
D. OPERATIONS ON DATES
E. ABOUT NA
V. TROLL SYNTAX
A. THE STRUCTURE OF TROLL STATEMENTS
B. THE SEQUENCE OF TROLL STATEMENTS
C. PECULIARITIES OF TROLL SYNTAX
1. Abbreviated Function Names
2. Use of Underscore
VI. EXPLANATIONS OF OTHER
A. MODELLING LANGUAGE
B. PROGRAMMING LANGUAGE
C. ARCHIVE
D. TPL
E. SIDE EFFECTS
ACCESS
options
f. opening multiple databases in one command
g. access conflicts
B. SEARCH LIST: DEFAULT LOCATIONS FOR INFORMATION
1. Working Without a SEARCH List
2. What the SEARCH List Is
3. Changing the SEARCH List
a. the SEARCH command: adding to the SEARCH list
b. to write or not to write
c. changing the SEARCH order
d. removing items from the SEARCH list
e. permanent ("file") and temporary ("memory") storage
f. searching multilevel archives
g. specifying multiple SEARCH rules at once
4. Be Careful!
II. HOST CONSIDERATIONS
A. UNIX SYSTEMS vs. PCs
1. UNIX Operating Software vs. Windows Operating Software
2. BigEndian Hardware vs. LittleEndian Hardware
B. UNIX SYSTEMS vs. UNIX SYSTEMS, PCs vs. PCs
C. LOCAL vs. NETWORK
III. ENTERING DATA
A. THE &DEDIT MACRO
B. THE COMBINE FUNCTION
IV. IMPORTING DATA
A. DATA FORMATS THAT TROLL USES DIRECTLY
1. FAME
2. AREMOS TSD
3. TSP LOAD
B. TEXT DATA
1. Using Troll's FORMDATA Text Format
a. NEWFORMAT
b. OLDFORMAT
2. Reading Columns of Data
3. Reading Arbitrary Data Formats
a. reading a file all at once
b. reading linebyline and letterbyletter
C. SPREADSHEET DATA
1. Time Series: the &WKS2TS Macro
2. Generic Matrices: the WKS2MAT Function
3. "Save As Text"
4. Other Options?
5. What About UNIX?
D. ARBITRARY BINARY DATA
V. USING TROLL DATA FILES
A. DATA FILE FORMATS
1. FORMDATA
2. TROLLDB
3. TESTBIN1
4. Special Formats
B. MOVING TROLL DATA BETWEEN PLATFORMS
VI. EXPORTING
DATA
VII. OTHER DATA ISSUES
A. CAPITALIZATION: WHEN IT MATTERS AND WHEN IT DOESN'T
COMMANDS
III. THE TROLL MODELLING LANGUAGE
IV. BUILTIN
FUNCTIONS
a. SYMTAB
b. LKSYM
c. LKXREF
d. LKORD
C. USING AND REUSING MODELS
1. Storing Models As Models
a. storing with FILEMOD
b. retrieving with USEMOD
c. editing with MODEDIT
2. Storing Models As Source Code
a. converting with SOURCEMOD
b. recreating with INPUT
c. editing with a text editor
D. CHANGING MODELS
1. Changing Symbols
a. CHANGESYM: changing symboltypes
b. RENAMESYM: changing symbolnames
c. DELSYM: deleting symbols
d. ADDSYM: adding symbols
2. Changing Equations
a. CHANGEQ: editing an equation
b. REPEQ: replacing equations
c. DELEQ: removing equations
d. ADDEQ: adding equations
3. Changing Analysis
a. RENORM:
E. USING DATA WITH MODELS
1. Data that TROLL Uses
2. Data that TROLL Ignores
F. WORKING WITH MULTIPLE MODELS
LEAST SQUARES
A. DIRECTINPUT OPTION
B. MODELINPUT OPTION
III. ADVANCED SINGLEEQUATION
A. DISTRIBUTED LAGS
B. SERIAL CORRELATION
C. TWOSTAGE LEAST SQUARES
D. NONLINEAR LEAST SQUARES
IV. MULTIPLE
TECHNIQUES
EQUATION TECHNIQUES
III. SIMULATION
A. MODEL
B. DATA
REQUIREMENTS
JACOBIAN
V. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND
IMPOSSIBLE VALUES)
A. SYMPTOMS
B. NEW STARTING VALUES
C. DAMPING ITERATIONS
D. EXPLICIT CONSTRAINTS WITHIN EQUATIONS
E. USING CONSTRAIN TO PREVENT ILLEGAL ITERATIONS
F. NEW MODEL
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
I. PORTABLE TROLL
Portable TROLL is an interactive computer software package designed for econometric modelling and other applications of
statistical analysis and mathematical simulation. Because of its emphasis on time series, TROLL is particularly wellsuited to
the study of processes that take place in calendar time. What sets it apart from other econometric and statistical packages is its
unparalleled ability to simulate quickly the dynamic behavior of large, complex, nonlinear systems involving forwardlooking
behavior. TROLL's salient features include an algebraic modelling language for flexible and precise specification of model
structure; a programming language for automation of complex tasks; a database engine for efficient storage and retrieval of time
series data; two hundred algebraic, statistical, and trigonometric functions for transformation and manipulation of data; and over
a hundred readytouse commands for statistical data analysis and model simulation. TROLL is designed both to interact easily
with users and to operate on prewritten command files without user attention. Both nontechnical users and experienced
programmers have a place in the world of Portable TROLL.
Although TROLL now comes on a compact disc and downloads over highspeed internet connections, its history goes back to
the days of punch cards and paper tape. During the 1960's, Massachusetts Institute of Technology (MIT) economist Edwin Kuh
spearheaded a successful effort to develop a "Timeshared Reactive OnLine Laboratory"  a system of computer software that
would let economists develop and test mathematical models without having to concern themselves with all the programming
details. The first "TROLL" (now called "Mainframe TROLL" to distinguish it from today's portable version) was released in
1971.
Since then TROLL has remained a critical tool for largescale econometric modelling because its development process has
responded directly to the needs and interests of people in the field. In addition to satisfying the requirements of practicing
econometric modellers, Mainframe TROLL was a testing ground for the introduction of new algorithms and techniques such as
KuhNeeseHollinger structural sensitivity analysis. In 1987, MIT licensed to Intex Solutions, Inc. the exclusive right to
develop and market TROLL. In 1991, with the support from the Bank of Canada, the Federal Reserve Board of Governors, the
International Monetary Fund, the Bank of Norway, and the Commission of the European Community, Intex began the creation
of Portable TROLL. Portable TROLL now offers the major capabilities of Mainframe TROLL while eliminating restrictions on
size of models and portability across platforms.
The designers of Portable TROLL had four objectives in mind: power, portability, extensibility, and compatibility with the
existing mainframe product. All four of these objectives are relevant to today's TROLL user. Power  Portable TROLL's
unlimited capacity, unmatched performance, and everimproving analytic capability  probably represents the primary reason
that users choose TROLL. Portability means that TROLL source code written for one platform will run on any platform. Thus
PC users and UNIX Workstation users can share TROLL programs without difficulty. Since Portable TROLL itself is written in
platformindependent code, users need not fear obsolescence: any future platform that supports the standard "C" programming
language will support TROLL.
Extensibility allows users to tailor TROLL to their own needs, and since users often make their extensions available to one
another, TROLL's capabilities promise to grow in ways that can immediately reflect the needs of users. Finally, backward
compatibility, in addition to the obvious advantage for former Mainframe TROLL users, provides new users with access to
applications developed over TROLL's history by such organizations as the International Monetary Fund.
Broadly, Portable TROLL's capabilities can be divided into "analysis" and "management." "Analysis"  calculation, estimation,
and simulation  produces tangible results, but "management"  data processing, model specification, and system maintenance
 provides the underpinnings for those results. Although TROLL's analytical capabilities are its most prized features, an
understanding of TROLL's management capabilities is more fundamental to its successful use.
The text of the User's Guide appears in this ordinary "paragraph" style (usually proportional type), except for specific
words and phrases that are set differently, according to the rules described below.
Code examples that represent TROLL sessions,
host sessions, or files of code or data (in text format)
are set in this "preformatted" (usually fixed font) style.
Parts that represent user input
are highlighted using this "strong emphasis"
(usually bold) style.
The following conventions apply within the body text of the Guide:
References to TROLL FUNCTIONS appear in THIS KIND OF TYPE (italic, fixed font, uppercase).
References to TROLL MACROS appear in THIS KIND OF TYPE (fixed font, uppercase).
Other TROLL KEYWORDS (including COMMAND names) appear in THIS KIND OF TYPE (fixed font, uppercase). (The
text normally applies this KEYWORD style when a TROLL KEYWORD is used in THE SAME SENSE in which it would be
used as a KEYWORD in TROLL, but not when used in a different sense.)
"Quoted code fragments" and other direct references to code within the text appear in this kind of type
(bold, fixed font, mixed case).
The following conventions apply to syntax specifications:
This represents a string to be replaced by user input. (italic).
[This represents optional input] (in square brackets).
this represents optional letters within a troll keyword (lowercase).
The first thing to know about TROLL commands is that each command should end with a semicolon. For example, type
"do;" at the command prompt. TROLL should respond with another command prompt, indicating that it has understood
and processed your request and is ready for the next command. In this case, you have told TROLL to "do" nothing, and
it has graciously obliged.
Now try typing "do" without the semicolon. The result should look something like this:
TROLL Command: do
Equation or ';':
This time you have told TROLL to "do" something, but it doesn't know what, so instead of processing your command, it
asks for more information. If you type a semicolon now, TROLL will respond with another command prompt,
indicating that it has succeeded in doing nothing:
Equation or ';': ;
TROLL Command:
Alternatively, you could ask TROLL to do something  in particular, to evaluate an expression. For example, when
TROLL asks for "Equation or ';'", try typing "x=5;". TROLL will respond with another command prompt, as
follows:
TROLL Command: do
Equation or ';': x=5;
TROLL Command:
In this case, TROLL has evaluated the expression "5" and assigned the value of that expression to the variable "x". You
can verify this with another DO command using the PRTDATA function, as follows:
TROLL Command: do
Equation or ';': prtdata(x);
X:
Numeric scalar:
TROLL Command:
The command "do prtdata(x);" asks TROLL to evaluate the expression "prtdata(x)." When TROLL evaluates the
PRTDATA function, it prints the value of the argument (in this case, x) on the computer screen (normally).
The PRTDATA function can be abbreviated as "PRT.", as in the following:.
TROLL Command: do prt.(x);
X:
Numeric scalar:
TROLL Command:
In TROLL (as in ordinary English) the dot is sometimes used to represent an abbreviation.
DB Type
MEMDB
DISK
R/W?
R/W
R/W
Filetype
DATA
ALL
Basic?
Fixed
Fixed
ID
(none)
(none)
TROLLSYS
DISK
ALL
Fixed
y:\troll
TROLL Command:
The LKACCESS command gives fundamental information about a TROLL session, and it also demonstrates a major
feature of TROLL: TROLL can access multiple databases at once. For example, you could have a variable called X in
the "SAVE" database and a variable called Y in the "." (dot) database, and you could add the two with a statement like,
"do z=x+y;" without telling TROLL which database contains which variable. (You would have to tell TROLL where to
search for variables.)
LKACCESS reports the databases that are directly available to the TROLL session right now. The first column,
"Alias," gives the name used for the database within the TROLL session. The last column, "ID," gives the more
general name for the database. The other columns give information about the characteristics of the database and its
relationship to the TROLL session. The third column, for instance, tells whether this TROLL session has read ("R") or
write ("W") access to the database. The fourth column tells the "Filetype" of the database, which determines the kind of
information (programs, models, data, etc.) it can contain.
The second column gives the "database type", which determines the format and other characteristics of the database. In
this example, only the types MEMDB and DISK appear. A MEMDB is a temporary database that resides temporarily in the
computer's memory and will disappear at the end of the TROLL session. A DISK database normally corresponds to a
"directory" (or "folder") in the host computer file system, and its contents will normally remain until deleted explicitly.
TROLL also offers several other database types (mostly "permanent" databases that correspond to "files" in the host
system). The specific types available will depend on your installation. You can display the available database types with
the command LKDBTYPE, as follows:
TROLL Command: lkdbtype;
Available Database Types:
DISK
TROLLDB
MEMDB
FORMDATA
FORMOLD
TESTBIN1
TSD
and FORMDATA are among the most commonly used database types. Both FORMDATA and TROLLDB databases
normally correspond to host system files. TROLLDB databases use a binary (computerreadable numeric) format that
enables TROLL to access them efficiently; FORMDATA databases use an ASCII (text) format that enables human beings to
read them.
TROLLDB
Other look commands that you can use generally in TROLL include LKOUTOPT, which shows output options in effect
(see Reference Manual entry); LKCONOPT, which shows convergence criteria and other convergencerelated options (see
Reference Manual entry); LKSTATUS, which shows information about the model and timeseries context (see Reference
Manual entry); LKSYSOPT, which shows the system options (such as log files) that are in effect (see Reference Manual
entry); LKSEARCH, which shows the order of database use (explained in the following section).
There are also many look commands that apply in specific contexts, such as modelling (LKORD, LKSYM, LKXREF, see
Chapter 6), seasonal adjustment (LKSEASOPT), estimation (LKBOUNDS, LKDLAG, LKPREG, LKREGOPT, LKNLSOPT, LKFILMLAG,
LKITERANGE, LKOUTLVL, see Chapter 7), and simulation (LKDATES, LKDROP, LKITERS, LKLIST, LKSIMALG, LKSIMPER, LKVAL,
see Chapter 8).
Besides knowing how to look for information from TROLL, it's important to know how TROLL looks for information
in databases. The following section discusses this topic.
session. TROLL's SEARCH list tells it where to look for variables, and in what order to look in different databases. (The
choice and order of databases may differ depending on whether TROLL is reading or writing data.)
The SEARCH list is related to the ACCESS list described in the previous section. Only ACCESSed databases can be on the
SEARCH list. An ACCESSed database may or may not be on the SEARCH list. Until an ACCESSed database appears on the
SEARCH list, TROLL will ignore it unless you refer to it explicitly.
You can view the current SEARCH list with the LKSEARCH command, as in this example:
TROLL Command: lksearch;
Current SEARCH list:
Name
SAVE
.
TROLLSYS
W?
W
W
Filetype
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
The "Name" column lists the databases, in SEARCH order, by their aliases. The "W?" column specifies whether a database is
for writing ("W") or only for reading (" ") information. Note that a database can be "ACCESSed" with write
access but still appear on the SEARCH list without a "W": TROLL will not write to such a database unless the SEARCH list
changes (or unless the database is referenced explicitly). The "Filetype" tells what type of information TROLL will seek
in the database. For example, a "DATA" file will be SEARCHed only for data, not for programs or models. The "Basic?"
column refers the status of a file's presence on the SEARCH list. ("BASIC" files are protected from being removed without
an explicit command.)
SEARCHed
The SEARCH list is a critical element in TROLL's architecture. It allows TROLL to avoid ambiguity in names, and it
enables TROLL to use resources efficiently, since TROLL can stop searching as soon as it finds a name in one of the
databases on the list. For information that is conveniently available in databases near the top of the list, TROLL can
avoid a potentially costly search among less easily accessible databases. The ability to make a database readSEARCHable
but not writeSEARCHable prevents fundamental data from being overwritten.
The SEARCH list also creates potential pitfalls for users. If you have variables (or programs or models) with the same
name in more than one database, you have to be careful to avoid using the wrong one. If two variables with the same
name refer to the same information but reside in different databases, you have to be careful to update both when the
information changes. If you intend to update information from within a TROLL session, you have to make sure the
database containing that information is writeSEARCHable.
DB Type
MEMDB
DISK
DISK
FORMDATA
R/W?
R/W
R/W
R
R
Filetype
DATA
ALL
ALL
DATA
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
y:\troll
c:\usanipa.frm
Although the database is now available, TROLL will ignore it until it appears on the SEARCH list. To put it on the SEARCH
list, you could use the following SEARCH command:
TROLL Command: search nipa;
W?
W
W
Filetype
DATA
NONDATA
NONDATA
DATA
Basic?
BASIC
BASIC
BASIC
As per its default, SEARCH has put the new database at the bottom of the SEARCH list. Thus a variable in the "NIPA"
database will only be used if a variable of the same name does not appear in the "SAVE" database. Suppose, alternatively,
that you're not sure what's in the "SAVE" database, and you want to make sure that TROLL uses the data from the "NIPA"
database. You could do that as follows:
TROLL Command:
TROLL Command:
TROLL Command:
Current SEARCH
delsearch nipa;
search first nipa;
lksearch;
list:
Name
NIPA
SAVE
.
TROLLSYS
W?
W
W
Filetype
DATA
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
The initial DELSEARCH command removes "NIPA" from the SEARCH list. The subsequent SEARCH command puts "NIPA"
back on the SEARCH list, this time at the top.
Finally, "delaccess
all"
removes all "nonBASIC" databases from both the SEARCH list and the ACCESS list:
DB Type
MEMDB
DISK
DISK
R/W?
R/W
R/W
R
Filetype
DATA
ALL
ALL
W?
W
Filetype
DATA
Basic?
BASIC
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
y:\troll
.
TROLLSYS
NONDATA
NONDATA
BASIC
BASIC
There is much more you can do with ACCESS and SEARCH than what we have seen so far. A deeper discussion
appears at the beginning of the chapter 3 on "Using and Managing Information." Managing data, strictly speaking, is
only one of several uses for TROLL's database access methods; ACCESS and SEARCH are also important in managing
models and programs. You will see references to these commands throughout this Guide.
CONS
NOB = 27
NOVAR = 2 NCOEF = 2
RANGE: 1969A to 1995A
RSQ =
0.9964
F(1/25) =
6919.221076
SER =
38.738866
DW(0) =
1.19302
MAX:HAT =
0.151311
DFFITS =
0.459821
COEF
GDP
CONST
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
0.996256
0
37517.492707
10.012457
2.214826
ESTIMATE
STER
TSTAT
0.743172
425.007001
0.008934
37.695226
83.181855
11.274823
PROB>T
0
0
OLS Command:
If you've done this sort of thing before, this result should look reasonably familiar. At the top, it identifies the procedure
as "Ordinary Least Squares" and the Lefthandside variable as "CONS." It then presents various regression statistics,
and finally it shows the coefficient estimates, along with their standard errors, Tstatistics, and probability levels. In this
case the probability levels are too small to express in the available decimal places for this format, so they are reported as
zero. (In other words, for practical purposes, these results could not have appeared by chance if the true coefficients
were zero.)
You may notice the absence of a "TROLL Command" prompt after the OLS results. Instead, there is a new prompt, "OLS
When you typed the command beginning with "ols cons..," TROLL launched a new "task" called "OLS." That
task will remain in control until you end it. While the OLS task is in control, you have available various commands that
apply specifically to that task. One example is regression diagnostics, requested by the command "PRTDIAG". Let's
request a set of studentized residuals for the above regression:
Command."
0.875778
0.7522
0.28213
0.278093
1.519414
1.040353
1.444587
0.612251
0.542679
1.832535
2.214826
0.425991
0.296821
1982A
1983A
1984A
1985A
1986A
1987A
1988A
1989A
1990A
1991A
1992A
1993A
1994A
1995A
1.731931
2.183125
0.257016
0.667252
1.058604
0.853092
0.605524
0.633409
0.329186
0.075551
0.196292
0.145207
0.781143
0.685686
OLS Command:
Those residuals look reasonable. Let's get out of the OLS task now:
OLS Command: quit;
TROLL Command:
Just to see how the task level differs from TROLL level, try typing "prtdiag
rstudent"
again.
Oops! TROLL has never heard of "PRTDIAG." At the TROLL level, regression diagnostics don't exist. TROLL wouldn't
even know which regression you were talking about. Of course, there are ways to save various regression information
before leaving the OLS task, but once you leave OLS, you must access that information through TROLL's "highlevel"
access methods, not through regressionspecific commands.
As always, there are exceptions. Some of the information that you gave the OLS task actually becomes a global setting
of the TROLL environment, and thus it is still available, even without being saved explicitly. In particular, the time
range ("BOUNDS") of the regression, which you set when you started OLS, remains valid. You can examine the currently
active time range by typing "lkbounds":
TROLL Command: lkbounds;
***** Regression Bounds *****
Time bounds with 27 observations in 1 range:
1: 1969A to 1995A
A. BUILTIN FUNCTIONS
TROLL has approximately 200 builtin functions to perform jobs relating to a wide range of activities, including data
generation, trigonometry, matrix algebra, input/output, probability distributions, statistical analysis, model manipulation,
missing values, dating of time series, and programming...to name a few. Here are some examples:
1. Output
If you read the section in this chapter on "Entering Troll Commands", you have already seen an output function
in action: "PRTDATA", or "PRT.", as it is affectionately known. For a user's guide, this kind of output is critical,
because it puts data where users can see it. You will see plenty of examples of PRTDATA (or "PRT.") throughout
this book. For now, some brief examples of what PRTDATA does: it simply displays the values of its arguments on
the computer screen, as follows:
TROLL Command: do prtdata(5);
5:
Numeric scalar:
10
10
2*3:
Numeric scalar:
Naturally, PRT. can do more than just print scalars. (The following example assumes that the nipa database, with
the variable gdp, is still on your SEARCH list.)
TROLL Command: do prt.(gdp);
GDP:
GDP = GDP
Numeric scalar timeseries Time dimension: Periodicity 1,
1969A
1973A
1977A
1981A
1985A
1989A
1993A
Time
:
:
:
:
:
:
:
dimension >
2914.78093
3316.13414
3584.68329
3925.14073
4427.40332
5034.52514
5305.36592
1969A to 1995A
2915.69401
3295.33595
3757.35818
3840.98742
4560.65358
5099.61333
5490.10025
(27 observations)
2998.88658
3268.55204
3852.01535
3995.87775
4692.32470
5049.97731
5601.5644
3152.28521
3429.96575
3831.26806
4268.50453
4870.55919
5187.46398
The rest of the examples in this section will make liberal use of "PRT.", usually with one or more functions
nested as its argument (or arguments), in order to demonstrate the effects of those functions.
Another very useful output function is PRTMAT, which displays matrix data in rows and columns. We'll use it in
the section on matrix functions. For now, note that a scalar is the same as a 1by1 matrix:
TROLL Command: do prtmat( 5 ) ;
Row
1
Column 1
5
2. Arithmetic
Anything a typical handheld calculator can do, TROLL can do better (or at least equally well):
TROLL Command: do prt.(sqrt(1000));
SQRT(1000):
Numeric scalar:
31.622777
1.570796
Any of these functions could also take a matrix or timeseries as the argument, and TROLL would apply the
function separately to each element of the matrix or timeseries. For example, you might want to transform GDP
into something less scalesensitive, such as its natural logarithm:
TROLL Command: do prt.(log(gdp));
LOG(GDP):
Numeric scalar timeseries Time dimension: Periodicity 1,
1969A
1973A
1977A
1981A
1985A
1989A
1993A
1969A to 1995A
7.97786
8.10026
8.23147
8.25348
8.42522
8.53692
8.61070
(27 observations)
8.00599
8.09210
8.25635
8.29301
8.45368
8.52713
8.63080
8.05588
8.14030
8.25095
8.35901
8.49096
8.554
3. Statistics
Many TROLL functions apply to a whole matrix or timeseries, rather than to individual elements. TROLL has
plenty of statistical functions that fit that description:
TROLL Command: do prt.(median(gdp));
MEDIAN(GDP):
Numeric scalar:
3925.140736
[1]:
Note that RANGE, like many functions, returns a vector  in this case the minimum and maximum values of the
time series. If you are a beginning user, this may be the first time you have seen the phrase "space dimension"
in a TROLL output. In TROLL, vectors and matrices have "space dimensions," whereas time series have "time
dimensions," and a time series of vectors or matrices will have both space and time dimensions.
Some statistical functions in TROLL do more than just return values, for example:
TROLL Command: do prt.(stats(gdp));
GDP:
NVals:
Min:
27
Mean:
2914.780935 Max:
Standard Deviation:
4135.815598
5601.5644
850.353715
STATS(GDP):
Numeric array 2 space dimensions: 1 by 5
[1,1]:
[1,5]:
2914.780935
5601.5644
The STATS function begins its work by printing out a set of summary statistics. It then places those summary
statistics in an array to return to the calling program. In this case, "PRT." was the calling program, so PRT. takes
that array and displays it on the screen. This array is actually a row vector  or a matrix with a single row and
multiple columns. By convention, the row number of a matrix is specified before the column number. Since the
matrix output by STATS has one row and five columns, TROLL reports it to have "2 space dimensions," of
which the first is "1."
You might also be interested in the relationship between two time series:
TROLL Command: do prt.(correl(gdp,cons));
CORREL(GDP,CONS):
Numeric array 2 space dimensions: 2 by 2
Space dimension number 2 >
1
0.998198
0.998198
1
[1,1]:
[2,1]:
And if the time series aren't yet in the form you want them, you can convert them on the fly:
TROLL Command: do prt.(covar(log(gdp),log(cons)));
COVAR(LOG(GDP),LOG(CONS)):
Numeric array 2 space dimensions: 2 by 2
Space dimension number 2 >
0.04296
0.050339
0.050339
0.05927
[1,1]:
[2,1]:
4. Matrices
You've seen several simple examples of TROLL matrices. Now let's look at some of the things TROLL can do
with them. Suppose you want your statistics as a column vector instead of a row vector. Just transpose them:
TROLL Command: do statvec=transp(stats(gdp));
GDP:
NVals:
Min:
27
Mean:
2914.780935 Max:
Standard Deviation:
4135.815598
5601.5644
850.353715
STATVEC = TRANSP(STATS(GDP))
Numeric array 1 space dimension: 5
[1]:
[5]:
2914.780935
5601.5644
The 1x5 matrix (row vector) produced by the STATS function is now a 5x1 matrix (column vector), which  in
TROLL's world  is equivalent to an ordinary onedimensional array. The "twodimensional" array is now a
"onedimensional" array. Where did the other dimension go? In a sense, it still exists, but TROLL no longer
cares about it. Every TROLL matrix contains an infinite number of "trailing dimensions"  space dimensions of
size 1 that are ignored unless they are needed.
Consider the following:
TROLL Command: do prt.(transp(statvec));
TRANSP(STATVEC):
Numeric array 2 space dimensions: 1 by 5
[1,1]:
[1,5]:
2914.780935
5601.5644
The second dimension has appeared again. To perform transposition, TROLL needs two dimensions, and it calls
the "trailing" second dimension out of hiding. TROLL also has a function to give the size of a specified
dimension, as follows:
TROLL Command: do prt.(dimsize(statvec,1));
DIMSIZE(STATVEC,1):
Numeric scalar:
As you can see, statvec does have a second dimension  of size 1: one column, if you like. By the way,
statvec also has a third dimension:
TROLL Command: do prt.(dimsize(statvec,3));
DIMSIZE(STATVEC,3):
Numeric scalar:
Even if you never need to use anything beyond the 999,999th dimension, it's nice to know the rest are there
waiting.
On the other hand, you may want to know how many "active" (nontrailing) dimensions a matrix has. Use the
NDIMS function:
TROLL Command: do prt.(ndims(statvec));
NDIMS(STATVEC):
Numeric scalar:
Note that any array with 2 or fewer active dimensions (and no time dimension) can be considered a matrix:
TROLL Command: do prtmat( statvec ) ;
Row
1
2
3
4
5
Column 1
27
4135.815598
2914.780935
5601.5644
850.353715
TROLL can do quite a lot with arrays and matrices, so just a few exotic examples here. Maybe you want to
reverse the order of an array and paste it against itself lengthwise to make a twodimensional matrix. You can do
that with the TROLL functions REVERSE and PARTCOMB (combine partitions):
TROLL Command: do sillymat=partcomb(1,2,statvec,reverse(statvec));
TROLL Command: do prtmat(sillymat);
Row
1
2
3
4
5
Column 1
Column 2
27
4135.815598
2914.780935
5601.5644
850.353715
850.353715
5601.5644
2914.780935
4135.815598
27
Column 1
Column 2
27
4135.815598
2914.780935
850.353715
850.353715
5601.5644
2914.780935
27
Column 1
Column 2
27
4135.815598
2914.780935
0
850.353715
850.353715
5601.5644
2914.780935
0
27
And of course TROLL can do ordinary matrix algebra. TROLL takes advantage of the associative property of
matrix multiplication, so that you can multiply an arbitrarily long series of matrices (provided they are
conformable):
TROLL Command: do x=transp(statvec);
TROLL Command: do prt.(matmult(x,sillymat,1/range(gdp)));
MATMULT(X,SILLYMAT,1/RANGE(GDP)):
Numeric scalar:
29592.974078
5. Calculus
Yes, TROLL does derivatives:
TROLL Command: do deriv(2*x,x);
DERIV(2*X,X) = 2
...and crossderivatives:
TROLL Command: do deriv(5*x**2*y,x,y);
DERIV(5*X**2*Y,X,Y) = 5*2*X
If you'd rather know the values of the derivative at specific points, TROLL can do that too:
TROLL Command: do prt.(deriv("eval",log(cons/gdp),gdp));
DERIV(LOG(CONS/GDP),GDP) = 1/GDP
DERIV("eval",LOG(CONS/GDP),GDP):
Numeric scalar timeseries Time dimension: Periodicity 1,
1969A
1973A
1977A
1981A
1985A
1989A
1993A
1969A to 1995A
0.000333
0.000306
0.00026
0.00025
0.000213
0.000198
0.000179
(27 observations)
0.000317
0.000292
0.000261
0.000234
0.000205
0.000193
6. Character Strings
To see how TROLL can handle character strings, let's redo the last example in two parts. First, take a symbolic
derivative:
TROLL Command: do symderiv=deriv("noprint",log(cons/gdp),gdp);
TROLL Command: do prt.(symderiv);
SYMDERIV:
String scalar:
"1/GDP"
0.000343
0.000303
0.000266
0.00026
0.000219
0.000196
0.000182
1969A to 1995A
0.000333
0.000306
0.00026
0.00025
0.000213
0.000198
0.000179
(27 observations)
0.000317
0.000292
0.000261
0.000234
0.000205
0.000193
The argument to the EVALSTR function is a string containing (usually) an arithmetic expression. EVALSTR
evaluates that expression and returns the value. In this case the argument contains the names of time series, so
EVALSTR performs its evaluation for each observation in those time series.
There are plenty of things you can do with strings besides evaluating them. For example, suppose you're
interested in disposable income ("YD") instead of gross domestic product ("GDP"). Using the CHANGESTR function,
you can perform a string replacement in the (previously formed) SYMDERIV expression:
TROLL Command: do prt.(changestr(symderiv,"GDP","YD"));
CHANGESTR(SYMDERIV,"GDP","YD"):
String scalar: "1/YD"
[1]:
Once you have an array of strings, you can join the elements together, and even place a specified separator
between them, using JOINSTR:
TROLL Command: do prt.(joinstr(couple," "));
JOINSTR(COUPLE," "):
String scalar: "HUSBAND AND WIFE"
What TROLL hath joined, TROLL can also put asunder, using the TOKENIZE function, which separates a string
into individual syntactical elements:
TROLL Command: do prt.(tokenize(joinstr(couple," ")));
TOKENIZE(JOINSTR(COUPLE," ")):
String array 1 space dimension: 3
[1]:
You can replace characters; you can change case; you can repeat a string an arbitrary number of times; and so
on; as in the following command:
TROLL Command: do prt.(repstr(upper(changestr("go? ","?","!")),3));
REPSTR(UPPER(CHANGESTR("go? ","?","!")),3):
String scalar: "GO! GO! GO! "
7. Time Series
Finally, to close the "Builtin Functions" section, a few examples of time series functions. First the most
obvious:
TROLL Command: do prt.(startdate(cons),enddate(cons));
STARTDATE(CONS):
Date scalar: 1969A
ENDDATE(CONS):
Date scalar: 1995A
And you can put the original series back together (and eliminate the redundancy) with the OVERLAY function:
TROLL Command: do prt.(overlay(conpre80,conpos73));
OVERLAY(CONPRE80,CONPOS73):
Numeric scalar timeseries Time dimension: Periodicity 1,
1969A
1973A
1977A
1981A
1985A
1989A
1993A
Time
:
:
:
:
:
:
:
dimension >
1709.07626
1984.02251
2218.27090
2480.56499
2890.91522
3292.67174
3523.20597
1969A to 1995A
1769.52642
1985.22548
2300.84373
2492.85495
3004.32887
3352.46735
3626.66046
(27 observations)
1814.21353
2056.88249
2359.29939
2622.18767
3094.54980
3330.85618
3713.14739
1907.20040
2147.30268
2438.70940
2757.17897
3217.63234
3422.79566
TROLL has a number of functions to deal with missing values. The following sequence creates a series with
some missing values, tests for the presence of missing values, trims off the missing values, and shows the effect
on the number of observations (NOB):
TROLL Command: do gdp65t87=subrange(gdp,1965a,1987a);
TROLL Command: do prt.(gdp65t87);
GDP65T87:
GDP65T87 = SUBRANGE(GDP,1965A,1987A)
Numeric scalar timeseries Time dimension: Periodicity 1,
1965A:
1969A:
1973A:
1977A:
1981A:
1985A:
NA
2915.694014
3295.33595
3757.358183
3840.987421
4560.653581
NA
2998.886588
3268.552041
3852.01535
3995.877758
4692.324707
NA
3152.285212
3429.965759
3831.268062
4268.504531
NOB(GDP65T87):
Numeric scalar:
23
TRUE
19
Another way to deal with missing values is to interpolate or extrapolate. In the following example, TROLL
extrapolates backward from the growth rate at the beginning of the series:
TROLL Command: do prt.(nagrow(gdp65t87));
NAGROW(GDP65T87):
GDP65T87 = SUBRANGE(GDP,1965A,1987A)
Numeric scalar timeseries Time dimension: Periodicity 1,
1965A
1969A
1973A
1977A
1981A
1985A
Time
:
:
:
:
:
:
dimension >
2911.13147
2914.78093
3316.13414
3584.68329
3925.14073
4427.40332
1965A to 1987A
2912.04341
2915.69401
3295.33595
3757.35818
3840.98742
4560.65358
(23 observations)
2912.95563
2998.88658
3268.55204
3852.01535
3995.87775
4692.32470
2913.86814
3152.28521
3429.96575
3831.26806
4268.50453
...and change periodicities (in this case, using a cubic spline to interpolate):
TROLL Command: do prt.(spatq(conpre80));
SPATQ(CONPRE80):
Numeric scalar timeseries Time dimension: Periodicity 4, 1969Q1 to 1979Q4
1969Q1
1970Q1
1971Q1
1972Q1
1973Q1
1974Q1
1975Q1
1976Q1
1977Q1
1978Q1
1979Q1
422.97969
441.41970
450.79621
473.61967
496.32261
494.44863
511.20140
534.68601
551.92722
572.97416
589.32151
(44 observations)
431.55843
442.70223
455.32745
480.02605
498.00507
495.94214
517.20616
539.56292
556.67513
577.89455
591.33485
440.13718
444.62603
460.84179
486.38689
497.37109
499.65760
523.24460
543.84224
561.95613
582.36810
592.34153
[1]:
[5]:
[9]:
5
9
6
10
68
140
212
86
158
[1]:
[5]:
[9]:
produces a column vector, but you might have wanted a time series. No problem! TROLL allows you to reshape
data arbitrarily along any number of time or space dimensions. To get a linear time trend, you can reshape a column
vector produced by SEQ into a scalar time series:
SEQ
1980A
1984A
1988A
:
:
:
1980A to 1989A
2
6
10
(10 observations)
3
7
4
8
1980A:
1984A:
1988A:
1992A:
1996A:
15.004996
10.038678
16.229819
17.276124
17.015074
14.99509
10.095796
16.234907
17.274481
17.012808
14.98514
10.151937
Using the COMBINE function (abbreviated "C."), you can put together specific pieces of data:
TROLL Command: do fibb=combine(1,2,3,5,8,13);
TROLL Command: do prt.(fibb);
FIBB:
FIBB = COMBINE(1,2,3,5,8,13)
Numeric array 1 space dimension: 6
[1]:
[5]:
3
0
5
0
[1]:
[5]:
[9]:
It's also easy to create a timeseries using COMBINE with RESHAPE or with CRSERIES:
2000M01:
2000M05:
22
2000M01:
2000M05:
22
[1]:
[5]:
[9]:
0.541802
0.899749
0.215298
0.550727
Column 1
Column 2
Column 3
Column 4
0
0
0
0
0
0
0
0
Column 1
Column 2
Column 3
5
5
5
5
5
5
5
5
5
Column 1
5
5
5
NA
Column 2
5
5
5
NA
Column 3
4.4
4.4
4.4
NA
Column 4
5
5
5
NA
TROLL will also expand dimensions when appropriate (see "Mixing Data Shapes" in Chapter Five) so that it can mix
arrays of different shapes in elementbyelement operations:
TROLL Command: do prtmat( seq(2) + 10*transp( seq(3) ) ) ;
Row
1
2
Column 1
11
12
Column 2
21
22
Column 3
31
32
Finally, let's clean up any junk that has been left around:
TROLL Command: delaccess all ;
TROLL Command: delsave all ;
C. MODEL CREATION
This section will go through the steps of setting up and saving a model. This example is a model of fiscal policy in
which tax rates adjust gradually to move the stock of outstanding government bonds toward a target level. (Everything
is expressed per unit of effective labor.) The wrinkle will be that personal consumption depends on perceived human
wealth, which depends in turn on the anticipated tax rate. For now, we'll just set up the model without estimating or
simulating it.
First, we declare the current model to be the one we are about to create:
TROLL Command: usemod tax1;
New model: TAX1
Next, we start the modelediting task ("MODEDIT"), so we can put something in the model:
TROLL Command: modedit;
The first necessary element in a model is the set of symbols it uses. In TROLL, there are several types of symbols,
categorized according to the type of variables they represent. In this model, we use ENDOGENOUS, EXOGENOUS, and
COEFFICIENT symbols. We begin by adding symbols for some ENDOGENOUS variables, government debt (b), consumption
(c), the capital stock (k), the interest rate (r), output (y), tax revenue (t), and the tax rate:
MODEDIT Command: addsym endogenous b
trate;
Now some EXOGENOUS variables, government spending (g), the debt target (bt), capital's share of output (capsh), the rate
of technical progress (pi), the labor force growth rate (n), and the capital asset risk premium (prem):
MODEDIT Command: addsym exogenous g
bt capsh pi n prem;
Now the meat of the model, the equations. We will use upper case letters for equation labels, just to make the equations
a little clearer. When you add an equation in TROLL, you must specify a position relative to the existing equations.
Since there are no existing equations yet, the position is irrelevant, but we specify "bottom" and then continue adding
equations to the bottom. The first equation is the production function:
MODEDIT Command: addeq bottom OUTPUT:
y = a*(k**capsh);
Now we add a few identity equations. (Note that multiple equations can be added in a single ADDEQ statement.)
MODEDIT Command: addeq bottom
The next equation is the most critical one. It describes how the tax rate adjusts to move the debt toward its target level:
MODEDIT Command: addeq bottom TAXADJ:
Equation: tratetrate(1) =
Continue eq: tradj * ( ( (bbt)  (b(1)bt(1)) ) / y );
To close the model, we add a consumption block. First we'll need a few more symbols, the rate of time preference
(theta), the death rate (lambda), and the stock of human wealth (h):
MODEDIT Command: addsym exogenous theta lambda, endogenous h;
Consumption depends on wealth, which includes physical capital, government bonds, and human wealth:
MODEDIT Command: addeq bottom CONS:
c = (theta+lambda)*(k+b+h);
Finally, an equation describing the growth of human wealth. Rational consumption and investment behavior requires
that the return on human wealth be the same as the return on physical capital. That condition determines a unique
growth path for human wealth, which depends on the growth path for taxes. The explicit derivation of this equation is
well beyond the scope of this Guide, but notice that the equation involves forwardlooking expectations:
MODEDIT Command: addeq bottom WHUM: h(+1)h =
Continue eq: (r+lambdapi)*h  (y  r*k  t);
That completes the model. Here's what it looks like all together:
MODEDIT Command: print;
Symbols:
ENDOGENOUS :
B C H K
EXOGENOUS :
BT CAPSH
TRATE
LAMBDA
PI
PREM
THETA
COEFFICIENT :
A TRADJ
Equations:
1:
2:
3:
4:
5:
6:
7:
8:
OUTPUT
IRATE
TAXREV
GDPIDEN
BUDGIDEN
TAXADJ
CONS
WHUM
Y = A*K**CAPSH
R = A*CAPSH*K**(CAPSH1)+PREM
T = TRATE*Y
KK(1)+(PI+N)*K(1) = YCG
BB(1) = (R(PI+N))*B(1)+GT
TRATETRATE(1) = TRADJ*(BBT(B(1)BT(1)))/Y
C = (THETA+LAMBDA)*(K+B+H)
H(+1)H = (R+LAMBDAPI)*H(YR*KT)
You'll recall from the beginning of this section that we named the model TAX1. Accordingly, a file called TAX1.MOD
will now appear in the first nondatawritable disk database on the SEARCH list. We can use that file tomorrow, next
month, or next year, whenever we decide to work with this model again. For now, though, let's just look at some simple
examples of what the TROLL simulator can do.
D. SIMULATION
1. Simplest Example: Linear Equations
In order to simulate, we need a model. We'll start over and enter a very simple, twoequation model.
TROLL Command: usemod ;
New model: (nameless)
TROLL Command: addsym endogenous x y ;
(TROLL automatically enters the modelediting task, since the ADDSYM command unambiguously belongs to
MODEDIT.)
MODEDIT Command: addeq top x+2*y = 10, xy = 1 ;
Here we have two simultaneous equations. What the simulator does, in essence, is to solve simultaneous
equations. TROLL requires starting values to begin its simulation. In this case the starting values will be
irrelevant, so let's just choose something easy:
MODEDIT Command: do x=1, y=1 ;
Okay, now solve the equations. (Here we tell TROLL to leave the MODEDIT task and enter the SIMULATE task.)
MODEDIT Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from NA to NA.
SIMULATE Command: list iter all ;
SIMULATE Command: simstart 1a; dosim 1;
Date: Block: Iter: What:
Value:
1A
1
0 Y
1
X
1
1 Y
3
X
4
[Rel. Change:]
[+1.00000e+000]
[+1.50000e+000]
SIN(X) = COS(X)
MODEDIT Command: do x = 0 ;
MODEDIT Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from NA to NA.
SIMULATE Command: list iterations all ;
SIMULATE Command: simstart 1a ; dosim 1 ;
Date: Block: Iter: What:
Value:
1A
1
0 X
0
1 X
1
2 X
0.782042
3 X
0.785398
4 X
0.785398
[Rel. Change:]
[+1.00000e+000]
[1.22308e001]
[+1.88339e003]
[7.05851e009]
Equations:
1:
X = X(1)+X(2)
MODEDIT Command: do x = 1 ;
MODEDIT Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from NA to NA.
SIMULATE Command: list solutions all ;
This simulation begins in the year 3 and ends in the year 10:
SIMULATE Command: simstart 3a ; dotil 10a ;
Date:
What:
Value:
3A
Solution: X
2
4A
Solution: X
3
5A
Solution: X
5
6A
Solution: X
8
7A
Solution: X
13
8A
Solution: X
21
9A
Solution: X
34
10A
Solution: X
55
SIMULATE Command: quit ;
X = X(+1)+X(+2)
The only difference between this and the previous example is that the minussigns in the subscripts have become
plussigns. In words, the model says, "This year's X is whatever will be the sum of next year's X and the
following year's X." To solve the model, we can use TROLL's stackedtime simulator, which simulates by
solving multiple periods simultaneously (i.e., "stacking" multiple periods in one set of simultaneous equations).
First, we initialize the data:
MODEDIT Command: do x=1;
Now we enter the simulation task. Since this is a forwardlooking simulation, we have to specify the algorithm
(in this case, "stack") used to solve it. Also, the "STACK" algorithm requires a parameter: the number of periods
to solve simultaneously. To keep it simple, we choose 8, the number of periods over which we are going to
simulate (as in the previous example):
MODEDIT Command: simulate stack 8;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Constructing stackedtime incidence matrix and code.
Simulations can start from NA to NA.
Date:
3A
Solution:
What:
X [3A]
[4A]
[5A]
[6A]
[7A]
[8A]
[9A]
[10A]
Value:
55
34
21
13
8
5
3
2
Without the government or foreign trade, the national income identity is simple:
MODEDIT Command: addeq bottom y=c+i;
Finally, there is consumer behavior. The agents in this model consume a constant fraction (80 percent, for this
example) of their "permanent" income. A new ENDOGENOUS variable, YPERM, represents consumers' estimates of
their permanent income:
MODEDIT Command: addsym endogenous yperm;
MODEDIT Command: addeq bottom c=.8*yperm;
Consumers estimate their permanent income primarily from their current income, but they also have some
information about next year. Their estimated permanent income is a weighted average of this year's income and
next year's income:
MODEDIT Command: addeq bottom yperm = .8*y + .2*y(+1);
Y = C+I
C = 0.8*YPERM
YPERM = 0.8*Y+0.2*Y(+1)
We need some starting data to begin the simulation. The following statements generate exponential growth for
income and consumption over 21 years:
MODEDIT Command: do y=exp(1+reshape(seq(21),1a)/10);
MODEDIT Command: do prt.(y);
Y:
Y = EXP(1+RESHAPE(SEQ(21),1A)/10)
Numeric scalar timeseries Time dimension: Periodicity 1,
Time dimension >
1A
:
3.00416
5A
:
4.48168
9A
:
6.68589
13A
:
9.97418
17A
:
14.87973
21A
:
22.19795
MODEDIT Command: do c=.8*y;
MODEDIT Command: do yperm=y;
1A to 21A
3.32011
4.95303
7.38905
11.02317
16.44464
(21 observations)
3.66929
5.47394
8.16617
12.18249
18.17414
4.0552
6.04964
9.02501
13.46373
20.08553
For this example, generate some pseudorandom data for (exogenous) investment. (The "seed" arguments to
ensure that the data will be replicable.)
RANDNORM
1A
5A
9A
13A
17A
21A
1A to 21A
0.35667
0.532089
0.793784
1.184186
1.766598
(21 observations)
0.394181
0.588049
0.877267
1.308728
1.952393
E. ADVANCED ESTIMATION
0.435638
0.649895
0.969529
1.446368
2.157728
You've already seen an example of OLS estimation in TROLL, but TROLL's estimation capabilities go far beyond that.
In this section, we'll look at some very simple examples of simultaneous equation estimation in TROLL. These
examples use a "minimalist multiplieraccelerator model" of the US economy, in which consumption and investment are
simultaneously determined, and other elements of demand are taken as exogenous. Although a more realistic model of
investment could take advantage of TROLL's ability to estimate large, nonlinear models with rich intertemporal
specifications, this whirlwind tour will limit itself to the simplest possibility  a linear twoequation model with no lags
or leads.
The data used here come from the same nipa database used earlier, which was ACCESSed as follows:
TROLL Command: access nipa type formdata id c:\usanipa.frm;
TROLL Command: search first nipa;
The variable that drives the model is "exogenous demand," that is, demand not for personal consumption or private
investment. In principle, that demand would include government demand and "net export" demand. Without attempting
to disaggregate (or to define a "net export"), we'll just subtract investment and consumption from gross domestic
product and use what's left over:
TROLL Command: do exdemand=gdpinvestcons;
Before doing any simultaneous equation estimation, we have to specify a model. Although we don't intend to do a
simulation, the format of the model, and the process for entering it, is exactly the same as for a simulation model. First,
clear the model space:
TROLL Command: usemod;
New model: (nameless)
The first equation represents the "multiplier" relationship, which is derived from the consumption function. In its
reduced form, the equation gives consumption as a function of "other demand," which includes both exogenous demand
and (endogenous) investment:
MODEDIT Command: addeq bottom cons=a0+a1*(exdemand+invest);
The second equation represents the "accelerator" relationship, to which an analogous logic applies:
MODEDIT Command: addeq bottom invest=b0+b1*(exdemand+cons);
MODEDIT Command: print;
Symbols:
ENDOGENOUS :
CONS INVEST
EXOGENOUS :
EXDEMAND
COEFFICIENT :
A0 A1 B0 B1
Equations:
1:
2:
CONS = A0+A1*(EXDEMAND+INVEST)
INVEST = B0+B1*(EXDEMAND+CONS)
Now we specify some options  the estimation period (required) and the maximum number of iterations (optional, but
the default won't be enough):
First we estimate by ordinary least squares, which ignores the simultaneity but provides a starting point for the more
advanced methods. The OLSMOD command causes TROLL to leave the MODEDIT task and perform regressions on the
equations in the completed model:
MODEDIT Command: olsmod all;
ORDINARY LEAST SQUARES
1 :
CONS = A0+A1*(EXDEMAND+INVEST)
NOB = 27
NOVAR = 2 NCOEF = 2
RANGE: 1969A to 1995A
RSQ =
0.947023
F(1/25) =
446.903387
SER =
148.604555
DW(0) =
1.128891
MAX:HAT =
0.163032
DFFITS =
0.471296
COEF
A0
A1
ESTIMATE
1484.786935
2.779316
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.944904
0
552082.842861
13.746273
2.244192
TSTAT
197.604798
0.131471
PROB>T
7.513921
21.14009
0
0
INVEST = B0+B1*(EXDEMAND+CONS)
NOB = 27
NOVAR = 2 NCOEF = 2
RANGE: 1969A to 1995A
RSQ =
0.672506
F(1/25) =
51.337314
SER =
69.11211
DW(0) =
1.136274
MAX:HAT =
0.138467
DFFITS =
0.591527
COEF
B0
B1
ESTIMATE
217.329789
0.129394
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
64.053175
0.018059
0.659406
0
119412.093844
9.52663
1.837855
TSTAT
3.392959
7.165006
PROB>T
0.002307
0
Having completed the OLS estimations, we save the coefficients to use as starting values for the simultaneous equation
estimation:
OLSMOD Command: savecoef;
Now we enter TROLL's simultaneousequation estimator, known as GREMLIN. GREMLIN is a package containing
several alternative tasks for estimating systems of equations. Here we'll start with the FIML task, which begins by setting
up the model for estimation by "fullinformation maximum likelihood":
OLSMOD Command: fiml;
...ANALYSING MODEL
...GENERATING CODE
uses an iterative process to maximize the likelihood function. Numerous options are available for such things as
the starting values, the optimization algorithm, and the convergence criteria. Here we'll just accept the defaults (except
for the "maximum iterations" option, which we have already set, and the starting coefficient estimates, which will be
taken from the saved OLS results). FIML proceeds with the estimation:
FIML
NOVAR: 4
NEQ: 2
Here are the coefficient estimates, which you can compare with the OLS estimates produced earlier:
VALUE
A0
A1
B0
B1
STD ERR
1658.948879
2.896423
286.031144
0.109593
210.525413
0.140306
66.267269
0.018721
CRSQ
0.945342
0.656757
SSR
0.943155
0.643027
569604.260898
125154.572678
SER
150.944263
70.754384
Another GREMLIN task is "threestage least squares," which is invoked by the THREESLS command:
FIML Command: threesls;
...ANALYSING MODEL
...GENERATING CODE
THREESLS Command: outlvl int 1;
THREESLS Command: estimate;
2 Stage estimation begins...
MODEL: CURRENT NOB: 27 NOVAR: 4
RANGE: 1969A to 1995A
NEQ: 2
FEVALMAX: 500
That's the first half of the procedure, and these are the preliminary results:
VALUE
A0
A1
B0
B1
STD ERR
1658.948879
2.896423
286.031144
0.109593
1.449408
0.000966
0.973607
0.000275
0.945342
0.656757
CRSQ
0.943155
0.643027
SSR
569604.260883
125154.572648
NEQ: 2
DavidonFletcherPowell
SER
150.944263
70.754384
RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
Convergence OBTAINED in 4 iterations, 8 FCN evaluations, FCN=3.5032956e016
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: DavidonFletcherPowell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 4 Fevals: 8 Final FCN: 3.5032956e016
FEVALMAX: 500
The final coefficient estimates are very similar to the FIML results:
VALUE
A0
A1
B0
B1
1658.948879
2.896423
286.031144
0.109593
STD ERR
210.520997
0.140302
66.286481
0.018728
CRSQ
0.945342
0.656757
0.943155
0.643027
SSR
569604.260883
125154.572648
SER
150.944263
70.754384
Another method available in GREMLIN is Zellner's "Seemingly Unrelated Regressions", invoked with the ZELLNER
command. The technique isn't really appropriate for this example, since the equations have variables in common.
Nonetheless, just to demonstrate:
THREESLS Command: zellner;
...ANALYSING MODEL
...GENERATING CODE
ZELLNER Command: outlvl int 1;
ZELLNER Command: estimate;
2 Stage estimation begins...
Seemingly unrelated equations (ZELLNER) case
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: DavidonFletcherPowell
RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX:1000
Convergence OBTAINED in 5 iterations, 10 FCN evaluations, FCN= 671494.936704
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: DavidonFletcherPowell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 5 Fevals: 10 Final FCN:
671494.936704 LOGLIKE:
VALUE
A0
A1
B0
B1
1484.786935
2.779316
217.329789
0.129394
FEVALMAX:1000
317.453518
STD ERR
1.329736
0.000885
0.926801
0.000261
0.947023
0.672506
CRSQ
0.944904
0.659406
SSR
552082.842861
119412.093844
SER
148.604555
69.11211
FEVALMAX:1000
316.981119
VALUE
A0
A1
B0
B1
STD ERR
1537.085898
2.814482
184.572979
0.138835
187.189308
0.124499
60.698883
0.017101
CRSQ
0.946871
0.668926
SSR
0.944746
0.655683
SER
553662.812995
120717.579224
148.817044
69.488871
That completes the estimation phase of the tour. Before we go on, another cleanup:
ZELLNER Command: quit ;
TROLL Command: delaccess all ;
TROLL Command: delsave all ;
F. TROLL PROGRAMMING
Among TROLL's most valuable features are its extensibility and its potential for automation. TROLL can do a lot by
itself, but it may not always know how to do exactly what you want. Because of TROLL's programming facilities, this
situation need not limit you: you can teach TROLL to do what you want. Even if TROLL already knows how to do
what you want, you may find yourself repeatedly going through the same sequence of steps, perhaps with slight
variations. Here also TROLL's programming facilities can help.
Another advantage provided by TROLL programming is the ability to share techniques conveniently among users. In
many cases, you may find that someone has already written a TROLL program to do what you want. In some cases, you
may want to share a methodology that you have used, but you may prefer not to spend time explaining how to do it. If
you have implemented your methodology as a TROLL program, then it can be ready for immediate reuse.
TROLL programs come in two varieties, "macros" and "userdefined functions." Macros might also be called "userdefined commands," since they work very much like TROLL commands. In fact, several macros are already included in
TROLL as commands. Userdefined functions, as the name implies, work like TROLL functions.
1. Macros
When you are entering TROLL commands, you can recognize a macro by the ampersand (&) at the beginning of
the name. Aside from the ampersand, you won't see much difference between macros and ordinary commands.
One macro included with troll is &PRTDATA, which will normally display a dataset on your terminal screen. For
example, first suppose you ACCESS the usanipa.frm file and place its alias on the SEARCH list:
TROLL Command: access nipa type formdata id c:\usanipa.frm;
TROLL Command: search nipa;
1969A
1973A
1977A
1981A
1985A
1989A
1993A
Time
:
:
:
:
:
:
:
dimension >
1709.07626
1984.02251
2218.27090
2480.56499
2890.91522
3292.67174
3523.20597
1969A to 1995A
1769.52642
1985.22548
2300.84373
2492.85495
3004.32887
3352.46735
3626.66046
(27 observations)
1814.21353
2056.88249
2359.29939
2622.18767
3094.54980
3330.85618
3713.14739
1907.20040
2147.30268
2438.70940
2757.17897
3217.63234
3422.79566
So far, the macro may not seem to have much advantage over the DFLIST function (called in a statement like "do
However, &PRTDATA can do a lot more than DFLIST can do. For example, if you want to
look at all variables containing the letter N, you can use the asterisk as a "wild card character" to represent any
letter or (possibly null) sequence of letters:
prt.(dflist(cons));".
1969A
1973A
1977A
1981A
1985A
1989A
1993A
Time
:
:
:
:
:
:
:
dimension >
1709.07626
1984.02251
2218.27090
2480.56499
2890.91522
3292.67174
3523.20597
1969A to 1995A
1769.52642
1985.22548
2300.84373
2492.85495
3004.32887
3352.46735
3626.66046
(27 observations)
1814.21353
2056.88249
2359.29939
2622.18767
3094.54980
3330.85618
3713.14739
1907.20040
2147.30268
2438.70940
2757.17897
3217.63234
3422.79566
NIPA_INVEST:
INVEST = INVEST
Numeric scalar timeseries Time dimension: Periodicity 1,
1969A
1973A
1977A
1981A
1985A
1989A
1993A
1969A to 1995A
470.10831
589.55518
721.36608
538.26011
738.41929
738.66821
886.85884
(27 observations)
519.07654
467.24260
722.12479
586.72186
747.17498
668.10227
913.19376
576.17583
564.48194
577.76256
757.62755
751.06644
715.59117
can do various other things too, and it's too complex to examine in detail here. To get an idea of how
macros work, consider a very simple macro designed to list the names of the variables in a FORMDATA file on the
host system. The text of that macro is in a file called fmls.src, which reads as follows:
&PRTDATA
// FMLS:
// Usage:
//
&FMLS file
where the file is named file.frm
addfun main;
procedure main()
begin;
get formdb;
formname = formdb  ".frm";
>>access ff type formdata id &formname;
>>search ff;
>>do prt.(dflist("ff"));
>>delaccess ff;
end;
The lines beginning with "//" are not used by TROLL; they're just comments to explain the file's purpose to
someone who might be reading it. The lines from "addfun..." to "begin" are just there to tell TROLL that this is
a macro. The important part starts with the "get formdb" line. We will examine those lines in detail presently,
but first let's look at this macro in action. Before you can use it, you need to convert it from text into a form that
TROLL understands. Assuming you have the fmls.src file in an ACCESSed disk directory whose alias appears on
your SEARCH list (typically the "." directory), the following command makes the macro available to your TROLL
session:
TROLL Command: compile fmls;
TROLL Compiler: Rel. 1.0
END OF COMPILATION
ERRORS:
0
WARNINGS: 0
Now, if you have usanipa.frm in a SEARCHable disk directory, you can do the following:
TROLL Command: &fmls usanipa;
DFLIST("ff"):
String array 1 space dimension: 3
[1]:
That statement tells the macro to obtain an input from the user. Typically, the user will pass the input to the
macro by typing it after the macro name. In the example above, the input is "usanipa". The next statement in the
macro appends the ".frm" extension on to the end of the argument and stores the result in a variable called
"formname" (of which the contents will be called "&formname"):
formname = formdb  ".frm";
In the example above, the result is "usanipa.frm". The next four statements, which begin with ">>" tell the
macro to pass commands to TROLL as if they had been typed on the TROLL command line:
>>access ff type formdata id &formname;
Before passing the command to TROLL, the macro substitutes the value of "formname" for "&formname". In the
example, the value of "formname" is "usanipa.frm", so TROLL receives the following command from the
macro:
access ff type formdata id usanipa.frm;
That command gives TROLL access to "usanipa.frm", using the alias "ff". The macro then passes the
subsequent commands to TROLL (with no substitution required, except stripping off the ">>"), just as if they
had been entered by a user:
search ff;
do prt.(dflist("ff"));
delaccess ff;
Thus TROLL prints out the contents of "ff" and then removes it from the ACCESS list.
2. UserDefined Functions
Userdefined functions work exactly like builtin functions, except that a userdefined function needs the suffix
"'F" so that TROLL will recognize it has a function. Consider a userdefined function called "distance" that
calculates the distance from the origin of a point in twodimensional space. The function takes two arguments,
which represent the X and Y coordinates of the point. Thus, you could compute the distance from the origin to
the point (5,3) by typing "distance'f(5,3);" at the TROLL prompt. The text file distance.src implements the
DISTANCE function as follows:
addfun main;
procedure main(x,y)
{
return( sqrt(x**2+y**2));
}
main"
line for now. Before explaining the rest, let's look at the
function in action. You COMPILE a function in exactly the same way as a macro:
TROLL Command: compile distance;
TROLL Compiler: Rel. 1.0
END OF COMPILATION
ERRORS:
0
WARNINGS: 0
TROLL Command: do prt.(distance'f(5,3));
DISTANCE(5,3):
Numeric scalar:
5.830952
Voil.
Back to the text of the function. The "procedure" line first indicates that this function is the "main" function in
this file. (In this case it also happens to be the only one.) The main function, once compiled, will be available
directly to TROLL. Other functions in the file (if any existed) would be available only within the file itself.
The "procedure" line also indicates the arguments to the function, which it calls "x" and "y". The names "x" and
"y" are arbitrary. They are replaced by the values of the actual arguments when the function is used.
The braces ("{" and "}") around the rest of the function simply tell where it begins and ends. In this case, the
function contains only one statement, a "return" statement, which tells the function to return a value. The value
to return is the square root of the sums of the squares of the two arguments. ("**" represents exponentiation).
When called with the arguments 5 and 3, the function returns the square root of 5squared plus 3squared, or
5.830952. This value is then passed to the "PRT." function, which displays it on the computer screen.
Functions, of course, can do much more than computing and returning values. Functions (and macros) can
include programming logic, using constructions like "IF..THEN..ELSE" to execute statements conditionally, and
"WHILE" or "FOR" to repeat statements in a loop. If necessary, functions and macros can operate directly on
external variables; they can test for TROLL error conditions; they can retrieve, store, or display data. In general,
TROLL functions and macros can do most of the things that a program in a typical procedural programming
language like FORTRAN or C can do.
G. CONCLUSION
This completes the whirlwind tour of Portable TROLL. Hopefully the tour has taught you something about what
Portable TROLL can do and how to use it. Hopefully you've gotten a little more comfortable using TROLL. Don't
worry if there were things you didn't understand or if the tour didn't seem to cover what you need to know. This is only
Chapter 1. The rest of this book will contain more complete explanations and comprehensive coverage.
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
C. KEYWORDS
D. OPERATORS
1. Binary Operators
a. arithmetic
b. relational
c. boolean
d. string
2. Unary Operators
a. arithmetic
b. boolean
3. Special Operators
a. DEL
b. SUM
c. PRODUCT
d. ::
E. FUNCTIONS
1. BuiltIn
a. algebra and trigonometry
b. array creation and manipulation
c. character string manipulation
d. matrix algebra
e. missing values
f. output
g. random numbers
h. probability distributions
i. summary statistics
j. programming
k. modelling
l. filesystem (troll databases)
m. external file input/output
n. system interface
o. miscellaneous
p. timeseries and dates
2. UserDefined
F. EXPRESSIONS
G. MODELS
1. Model Files
2. Symbol Table
3. Equations
a. equation numbers
b. equation labels
c. identities that define DEFINITIONtype symbols
H. CALCULATIONS
1. DO Commands
2. Expression Statements
I. TASKS
J. COMMANDS
1. HighLevel Commands
2. LowLevel Commands
3. Utility Commands
K. PROGRAMS
1. Macros
a. userwritten macros
b. macros included with troll
2. UserDefined Functions
L. OPTIONS
1. Bounds
2. System Options
a. log file (LOGFILE and LOG)
b. monthly/quarterly date format (QMPER)
c. see output or not (SCREEN)
d. macro debugging (TRECHO)
e. file locking (LOCKING)
3. Output Options
a. margins
b. paging
c. numbers
d. miscellaneous
4. Convergence/Optimization Options
a. iteration limit (STOP)
b. convergence criterion (CONCR)
c. other general convergence options
d. simulation options
e. other optimization and related options
5. Other Options
a. active date range (DRANGE)
b. active model (USEMOD)
c. regression options (REGOPT)
d. nonlinear least squares options (NLSOPT)
M. COMMENTS
1. Command and Program Comments
2. Equation Comments
3. Model Comments
4. Symbol Comments
5. Data Comments
V. TROLL SYNTAX
A. THE STRUCTURE OF TROLL STATEMENTS
B. THE SEQUENCE OF TROLL STATEMENTS
C. PECULIARITIES OF TROLL SYNTAX
1. Abbreviated Function Names
2. Use of Underscore
experienced TROLL user but still don't feel completely comfortable, this chapter may help you by providing a
conceptual structure and filling in any gaps in your understanding.
B. STRUCTURE
Section II presents some basic distinctions to keep in mind while studying TROLL. The purpose is not so much to make
you aware of those distinctions as to bring them to your attention. For example, even most beginning TROLL users may
already have a clear idea of the difference between data and models, at least in the abstract. In practice, numerous errors
can be avoided by understanding the relevance of that distinction in TROLL and by reminding oneself of the distinction
while using TROLL.
Section III provides a sort of inventory of TROLL concepts, or the various objects that can constitute a TROLL session.
You might think of this section as a list of available ingredients for cooking or materials for building.
Section IV describes the actions you can take with those ingredients or materials. If the previous section discusses
"flour, sugar, eggs,...," then this section is concerned with how to "sift, beat, combine,...."
Section V discusses the specifically "linguistic" features of TROLL  the rules for how to put TROLL statements
together.
Finally, section VI "cleans up the leftovers" by defining important terms not defined earlier in the chapter.
A function is more subtle: it says, "Compute this, and then use the result." TROLL has to know how to use the result as
soon as the result is computed; TROLL will not "await further instructions." Normally you do not type a function
directly in response to a prompt, since TROLL would not know how to use the result. Thus, even though SQRT is a
To some extent the command/function distinction is an artificial one. TROLL must know how to "use" a function result,
but the use may be simply to throw the result away. Although a function always "computes" something, the thing it
computes may not matter. For example, if you type " do prtdata(x); ", you probably don't care what TROLL does
with the computed result of the PRTDATA function. In the process of executing the PRTDATA function, TROLL displays the
value of X, which is probably why you used the PRTDATA function. However, since PRTDATA is a function and not a
command, you could not simply type " prtdata(x); " You must respect the formal distinction between a command and
a function even when the substantive distinction is absent.
Usually (not quite always  see the section on special operators below), you can tell that something is a function by the
parenthesis that immediately follows the function name. In the statement " do prtdata(x); ", for example, the
command name "do" is not followed by a parenthesis, whereas the function name "prtdata" is followed by a parenthesis.
1. Use of Symbols
in data manipulation and analysis
The Reference Manual definition applies most literally to symbols as used in data manipulation and
analysis. Here symbols can be used to represent concrete TROLL data objects (e.g., the symbol "gdp"
used to represent a time series of annual observations of gross domestic product), or they can be used to
represent functions (e.g., the symbol LOG in the expression "log(gdp)").
in models
The word "symbol" has a special meaning in the context of a TROLL model. A "symbol" in a model can
represent a "model variable" ("abstract data object"), or it can represent a function. Unlike a "data
symbol," a "model symbol" must be one of seven specific "symboltypes" (see below).
2. Symbolnames
Which of these statements is true: "Symbols have names," or "Symbols are names."? In TROLL, it depends on
your point of view. When you are thinking about a variable, you can identify the name of that variable as a
symbol for it. When you are thinking about the symbol itself  the rules about how to use it and such  it may
be more convenient to dissociate the (more abstract) symbol from its (concrete) "name". Thus we have the
concept of a "symbolname"  a sequence of characters which may include letters, digits, periods, or
underscores, and which normally begins with a letter.
Here's a couple of points to note about symbolnames in TROLL. First, TROLL does not distinguish between
lowercase and uppercase letters in symbolnames: all are converted to uppercase. Second, the underscore in a
symbolname often separates the name of an "archive" (e.g. "US" in "US_M2") from the name of a member (e.g.
"M2") of that archive. (See this chapter's section on "Archives").
3. Symboltypes
Normally, Symboltypes exist only in models. Symbols that apply only to data or functions do not have
symboltypes. A "symbol" representing a "model variable" must have a symboltype, whether that symboltype is
declared explicitly or allowed to default. Outside of models, only a function symbol needs a symboltype; that
symboltype is always FUNCTION; and usually it is implicit. Symboltypes for "data symbols" have no real meaning
outside the context of a model.
The "type" classification divides symbols into seven categories according to their relationship to the model:
EXOGENOUS
a symbol for a timeseries whose values are determined outside the model. This is the default symboltype.
The values corresponding to exogenous symbols are an input to the estimation or simulation process, and
are not altered by the process.
ENDOGENOUS
a symbol for a timeseries whose values are determined within the model. Endogenous symbols must
correspond to some data values, but the simulation process supplies new values. Estimation does not
supply new values, but simultaneous equation estimation treats endogenous symbols differently from
exogenous ones.
COEFFICIENT
a symbol for a constant (i.e., not a timeseries) whose value is estimated by estimation tasks. Coefficient
values must be determined before running a simulation.
PARAMETER
a symbol for a constant whose value is to be supplied by the user. Parameter values must be determined
before running either estimation or simulation.
FUNCTION
the name of a function, which may be either a builtin TROLL function or a userwritten function.
TROLL will automatically recognize the names of builtin functions as this type.
DEFINITION
a symbol for a timeseries whose values are identically equal to the value of an expression containing
other symbols. Values for DEFINITION symbols are not taken directly from available data but computed
from the values of the variables in the expression. Unlike other timeseries symbols in a model,
DEFINITION symbols do not correspond directly to any concrete data, even if a data variable with the
same name exists.
POLICY
technically equivalent to an EXOGENOUS symbol. POLICY symbols are typically used for variables that will
be "shocked" to examine the effects of alternative policies.
B. DATA
Every TROLL user is ultimately concerned with using data, whether it be actual historical data or merely artificial data
for use in simulation. TROLL provides a rich set of possibilities for data objects, which are classified primarily
according to "type" and "shape."
1. Data Types
"Data type" refers to the nature of an individual data element. For example, a constant number, a time series of
numbers, and an array of numbers all have the same "data type," but a character string has a different type from
a number. Five basic data types are available:
numeric
numbers of any kind (except for dates), such as 0, 1, 3.14, 9837264.274, or 25.
string
text or character string, such as "This string." (In Mainframe TROLL, these were called "labels.")
date
dates with a specified frequency, such as the year 1990 ("1990A"), the first quarter of 1933 ("1933Q1"), or
August of 2030 ("2030M08"). A date identifies an element of a timeseries.
boolean
TRUE or FALSE
NA
a "pseudotype" indicating that the type of the data is not currently known.
The formats used to display values of different data types are described in the section called "literals" below.
possibilities for spatial arrays, which can be described in terms of several characteristics:
i. size
For each space dimension of a spatial array, there is a size, which identifies the number of
elements along that dimension. Thus, for a 3x5 matrix, the size of its first dimension is 3, and the
size of its second dimension is 5.
ii. active dimensions
A space dimension with a size greater than one is called an active dimension. (Note that the
definition of "spatial array" given above does not require it to have any active dimensions.) An
ordinary vector, for example  such as the row vector [1,3,5,7]  has one active dimension.
iii. trailing dimensions
In TROLL, every spatial array has an infinite number of dimensions. Some dimensions may be
active, but after the last active dimension, TROLL provides an infinite number of dimensions of
size one. These additional dimensions are called trailing dimensions. Trailing dimensions are
always present, but generally they can be ignored if they are not needed.
iv. leading dimensions
Every dimension up to and including the last active dimension is a leading dimension. A column
vector has one leading dimension (the active dimension). A row vector has two leading
dimensions (but only one active dimension). Leading dimensions are precisely those dimensions
that are not trailing dimensions. You might think of leading dimensions as "ordinary" dimensions
 dimensions that would exist in a framework that didn't include TROLL's concept of "trailing
dimensions."
v. special kinds of spatial arrays
There are special names for certain kinds of spatial arrays. Some of these you might not think of
as "arrays," but in TROLL, they are arrays.
scalars
Most of the time, you can ignore the complexity and simply think that, for example, "a
scalar number is just a plain old number"
"vectors"
matrices
A matrix is "a twodimensional array." Normally, this means an array with two active
dimensions. Occasionally, the word "matrix" can be used to refer to any array with no
more than two active dimensions. (For example, in some algebraic contexts, it may not be
possible to say whether a certain "matrix" is degenerate in one or both dimensions. From
TROLL's point of view, there is nothing special about a "matrix" or a "vector;" TROLL
knows them only as arrays that happen to have certain kinds of shapes. The terms
"matrix" and "vector" are used for convenience, and should be avoided when they are
ambiguous.
e. timeseries of spatial arrays
As you might have surmised, an array can have both a time dimension and one or more active space
dimensions. You can consider such an array either as a "timeseries of spatial arrays" or as a "spatial array
of timeseries." You could extract each time observation from such an array, and each of these extracted
observations would be a spatial array without a time dimension. Or you could extract the data from each
spatial position in such an array, and each of these extracted data objects would be a time series without
active space dimensions.
f. constants
In TROLL, the word "constant" usually refers to any data object without a time dimension (or any
symbol that would correspond to such an object).
g. literals
A literal is a simple data object that is specified by it value rather than by a symbol. A literal can be any
of the basic datatypes. Since the value of a literal is specified, it cannot be changed. (Literals are called
"constants" in some programming languages, to distinguish them from variables whose values can be
changed. As defined above for TROLL's purposes, however, a "constant" is something that could be
changed by a program or by a user, as long as it continues to have no time dimension.) The formats for
specifying literals are as follows:
i. numbers
A number literal can be an integer (e.g., 256), a decimal (e.g., 3.1416), or an "Eformat"
number. An Eformat number consists of a decimal or integer followed by an exponent, which
represents a power of 10. The exponent consists of the letter "E" or "D" followed by an integer.
For example, the literal 12345d6 means 12345 times 10 to the 6 power. The literal .012345 is
equivalent.
ii. strings
A string literal is a string of characters enclosed in doublequotes ("). The string may be empty
("") or may contain any sequence of printable characters other than doublequote, ampersand (&)
or backslash (\); a doublequote would terminate the string, ampersand is used to run macros,
and backslash is used as a continuation or escape character. You can enter a long string on
several lines by terminating all but the last line with a single backslash. If you break a string on
two lines without that continuation character, TROLL puts a newline character in the string. To
include special characters in a string, use an "escape sequence" starting with a backslash. The
following escape sequences are available:
\"
doublequote
\+
ampersand
\\
backslash
\n
newline (linefeed)
\t
horizontal tab
\b
backspace
\f
formfeed
\r
carriagereturn
\v
vertical tab
\a
alarm or bell
\e
escape character
Examples of string literals:
"Private Sector"
"Tuesday, August 6, 1991"
"\\troll\\data\\*.dat"
"The answer is:\n \"TRUE\""
"This string is really \
one long line."
"This string is
two lines."
iii. dates
Although dates are considered a single data type, that type can be subtyped according to
periodicity. TROLL allows several predefined periodicities, as well as various types of
userdefinable periodicities:
annual
The usual format is yyyyA, where yyyy is the year. For example, 1990A refers to the year
1990. The equivalent format yyyyA1, which technically means "year 1 of the year yyyy,"
can also be used: for example, 1990A1 refers to the year 1990 (which happens to be the
first  and only  year in 1990).
quarterly
The usual format is yyyyQf, where yyyy is the year and f is the quarter. For example,
1990Q2 refers to the second quarter of 1990.
monthly
The usual format is yyyyMff, where yyyy is the year and ff is the month. For example,
1990M10 refers to October of 1990.
weekly (ISO 8601)
The usual format is yyyyWff, where yyyy is the year and ff is the week. For example,
1990W50 refers to 50th week of 1990.
daily
The usual format is yyyyMmmDdd, where yyyy is the year, mm is the month, and dd is
the date of the month. For example, 1990M07D14 refers to 14th of July 1990.
businessdaily
The usual format is yyyyMmmBdd, with essentially the same meaning as with "daily"
dates, but arithmetic operations skip weekends.
hourly
The usual format is yyyyMmmDddHhh (starting with the "daily" date), where hh is the
hour of the day. For example 1990M07D14H22 refers to 10 PM on the 14th of July 1990.
(Note that hours, minutes, and seconds are counted starting from zero, whereas days,
months, quarters, and years are counted starting from one.)
minutely
The usual format is yyyyMmmDddHhhMmm, starting with the "hourly" date and adding
mm minutes, so that 1990M07D14H22M11 refers to 10:11 PM on the 14th of July 1990.
secondly
The usual format is yyyyMmmDddHhhMmmSss, starting with the "minutely" date and
adding ss seconds, for example 1990M07D14H22M11S59.
case (ticks)
an arbitrary userdefined periodicity. The format is ttttT, where tttt is the number of ticks
(or periods).
userdefined by dividing periods
starts with one of the above periodicities and adds PppFff, where pp is the number of
subperiods per period, and ff is the sequence number of the current subperiod within the
period. For example, 1990M03P02F01 belongs to a userdefined "semimonthly"
periodicity and refers to the first half of March, 1990
userdefined by multiplying periods
starts with one of the above periodicities (not the last) and adds Xxx, where xx is the
number of periods per superperiod. For example 1990W10X02 and 1990W11X02 both
belong to a userdefined "biweekly" periodicity, and both refer to the fifth twoweek
period in 1990, (since, in integer arithmetic, 10/2 = 11/2 = 5).
iv. booleans
TRUE
A lag or lead is specified by placing an expression in parentheses ("()") following a symbol. A negative
value represents a lag and indicates a value of a timeseries in an earlier period. A positive value
represents a lead and indicates a value of a timeseries in a later period. For example, if gdp is an annual
variable, the following expression represents the difference between next year's GDP and last year's
GDP:
gdp(1)  gdp(1)
b. subscripts
Subscripts are enclosed in square brackets ("[]") following a symbol and its lag (if any). When more
than one subscript is used, the subscripts are separated by commas. A subscript (or subscripts) may be
used either to select an individual element from an array or to extract a subarray from an array. The
meaning of a particular subscript list will depend on the shape of the array to which it is applied, since
the individual subscripts in the list will be applied to the dimensions of the array in order.
Subscripts may be:
positive integers or vectors of positive integers, indicating the indices to use and in what order
(as in "matvals[1,3]");
a boolean vector whose length equals the size of the dimension  indices corresponding to TRUE
will be selected, as in "vecvals[vecvals>5]", which selects elements of vecvals that are greater
than five.;
NA or not supplied, representing the entire original dimension (so that "folks[NA]" is equivalent
to just plain "folks", both representing the entire array folks);
or
dates, to select particular observations from a time dimension (as in "gdp[1997a]").
C. KEYWORDS
A TROLL user communicates with the computer largely by using keywords  words that have special meaning in the
TROLL environment. The most common examples of TROLL keywords are command names such as DO and SEARCH.
Another common type of keyword is a function name such as SEQ or LOG. Depending on the context, it may or may not
be permissible to use a keyword for something other than its standard keyword use. For example, the following is
allowed (not recommended!) even though it uses the keyword SEARCH to name a user's variable:
TROLL Command: do search=2;
TROLL Command:
However, the following use of a function name keyword produces an error message:
TROLL Command: do prtdata=2;
ERROR 1001
Parser error.
Parenthesis is missing after function name PRTDATA:
PRTDATA = 2;

Generally, TROLL tolerates the use of keywords as ordinary names in any context where the keyword could not be
given its keyword interpretation. However, to avoid confusion, it is generally better to use keywords only as keywords.
Another common type of keyword is a command option specifier, such as the words "TYPE" and "ID" in the statement
"access nipa type formdata id c:\usanipa.frm;". (See the example and syntax in Chapter 1, under "SETTING THE
DATABASE ENVIRONMENT".) In the following statement, the second occurrence of "type" and the first occurrence of "id" are
keywords, but the other occurrences are names:
TROLL Command: access type type trolldb id id mode w;
TROLL Command:
This statement causes TROLL to access a database called "id" using the alias "type". (It also shows how using
D. OPERATORS
An "operator" (for example, the plus sign "+") specifies an operation (such as addition) to be performed on one or more
entities (called "operands"). The typical example of a plus sign used to add two numbers (as in "1 + 2") is a "binary
arithmetic operator": "binary" because it takes two operands and "arithmetic" because it specifies an arithmetic
operation. It also takes the typical form of a mathematical sign ("+"). As noted earlier, some TROLL operators can also
take the form of keywords.
Broadly, TROLL operators can be classified as "binary," "unary," and "special," as follows:
1. Binary Operators
As the name implies, a binary operator takes two operands. It is normally placed between its two operands, as in
the classic "1 + 2" example. In TROLL, all binary operators are "fundamentally scalar" in the sense that they
operate on scalar operands and generate scalar results. Although binary operators are fundamentally scalar, they
may be used with nonscalar operands. The operands must be conformed in such a way that the operator can
apply to pairs of scalar elements. As a very simple example, suppose A and B are two column vectors of size 3.
Then "A + B" means that the two should be added elementbyelement, as in ordinary vector addition.
More generally, conformation of operands in TROLL does not always behave the same way as the common
mathematical use of the same operator with the same operands. For example, consider our 3element column
vectors A and B again, but now let's multiply them: "A * B". (The asterisk "*" is TROLL's multiplication
operator.) In linear algebra, that operation would be illegal: only a row vector can be premultiplied by a column
vector. In TROLL, the conformation is elementbyelement, so "A * B" is perfectly legal, and TROLL multiplies
each element of A by the corresponding element of B. Now consider a 3element row vector C. In linear
algebra, "C * B" would be a scalar; in TROLL, "C * B" is a 3by3 matrix. It is produced by multiplying each
element of C by all elements of B.
In some cases, an expression may produce the same shape result in both TROLL and Linear Algebra, but the
results themselves may be different. For example, consider two square matrices X and Y. In TROLL, as in
algebra, the expression "X * Y" produces a square matrix with the same shape as X and Y. However, TROLL
simply multiplies each element in X by the corresponding element in Y, instead of multiplying rows by columns.
In general, the rules for conformation of operands in TROLL (unlike linear algebra) do not depend on the
particular binary operator involved. The rules are as follows:
Time dimensions must have identical periodicities. The output array will use the intersection of the date
ranges of the input arrays. Thus, for example, adding a quarterly series with an annual series is illegal,
whereas adding an annual series ending in 1955 with one starting in 1960 is legal but produces an empty
result.
Active space dimensions must have the same size. Thus, for example, you cannot add a 3element row
vector with a 4element row vector. However, you can add a 3element row vector with a 4element
column vector, because each active dimension in one vector corresponds to an inactive dimension in the
other. The result will be a 4by3 matrix, as defined in the next rule.
If a time dimension is lacking or a space dimension has size 1, then the values will be replicated along
that dimension, if necessary, to match the other arrays. For example, if X is an array, then the expression
"1 + X" adds 1 to each element of X, regardless of the shape and size of X.
The following types of binary operators exist in TROLL:
a. arithmetic
Arithmetic operators operate on and return numbers or dates. Binary arithmetic operators have provided
most of the examples so far. TROLL has five binary arithmetic operators: + (addition),  (subtraction), *
(multiplication), / (division), and ** (exponentiation). TROLL performs exponentiation first, then
multiplication and division, and then addition and subtraction.
b. relational
Relational operators generally perform comparisons. They operate on various datatypes and return TRUE
or FALSE. TROLL has six relational operators: == (equal  note that two equalsigns are required), <>
(not equal), > (greater than), >= (greater than or equal), < (less than), <= (less than or equal). If A and B
are two arrays with the same size and shape, then the expression "A <= B" represents another array, also
with the same size and shape, containing TRUE and/or FALSE values. The TRUE or FALSE value of a given
element depends on the whether the corresponding element of A is less than or equal to the
corresponding element of B. Thus, if A is {1, 2, 3, 4} and B is {2, 2, 3, 3}, then "A <= B" is {TRUE, TRUE,
TRUE, FALSE}.
c. boolean
Binary Boolean operators connect Boolean expressions (expressions that can be TRUE or FALSE) to
produce compound Boolean expressions. TROLL has two binary Boolean operators, OR (inclusive OR)
and AND. Normally, these operators behave the same way they do in ordinary English. The only
difference is that "OR" has two possible meanings (inclusive: "either or both" and exclusive: "either but
not both") in English, whereas it has only one meaning (inclusive: "either or both") in TROLL. Taking A
and B from the previous example, the expression "A <= B OR B > 2" has the value {TRUE, TRUE,
TRUE, TRUE}.
TROLL evaluates arithmetic, relational, and Boolean operators separately in succession, so it will
process each half of "A <= B OR B > 2" before applying the OR operator. Within the Boolean category,
the AND operator precedes the OR operator. To control evaluation, you can use parentheses to group parts
of an expression. The expression "1==2 AND 2==3 OR 4==4" is TRUE, because 4 does equal 4, and the
other clauses (connected by AND and evaluated first) are optional. The expression "1==2 AND (2==3 OR
4==4)", identical except for the parentheses, is FALSE because it requires the false clause "1==2".
d. string
String operators are those which operate on and return character strings such as "This string". TROLL
has only one string operator,  (concatenation), which returns a string containing its operands strung
together. For example, TROLL evaluates "This string"  " and "  "that string" as "This
string and that string"
2. Unary Operators
Unary operators apply to single operands. Troll has three unary operators (all of which normally precede their
operands):
a. arithmetic
+(positive,
or "unary plus", which normally has no effect on its operand),  (negative, or "unary minus",
which returns the inverse of its operand), and
b. boolean
NOT.
TROLL applies unary operators before other operators, so "2**2" is positive. That concludes the section on
operators...NOT!
3. Special Operators
"Not!" because TROLL also has "Special Operators"  peculiar, sometimes confusing entities, but very useful
tools for anyone working with time series.
a. DEL
TROLL uses DEL in the sense of "DELTA," not in the sense of "delete." DEL is essentially a substitute for
the Greek letter (capital) delta, which unfortunately cannot be reproduced reliably in the standard
character set used by TROLL. The simplest use of DEL is illustrated as follows:
TROLL Command: do diff = del(data);
This statement sets DIFF equal to the first difference of the time series DATA. In this context, DEL may
look like a function, but it is actually an operator. A more complex use of DEL shows how it differs from
a function:
TROLL Command: do anndiff = del(12: monthly);
This statement calculates the 12period difference of a series called MONTHLY. You might think of the
number before the colon as a subscript on the Greek delta. Using a similar format, DEL can calculate any
nperiod difference, including the difference of a more complicated expression, or where the value of "n"
is not known beforehand, as in:
TROLL Command: do voldif = del(i1: anndiff/monthly(i));
For a given value of I, this statement calculates the I1 period difference of the ratio between ANNDIFF
and the value of MONTHLY lagged by I periods.
b. SUM
Just as the DEL character operator substitutes for the Greek (capital) delta, the SUM operator substitutes for
the Greek (capital) sigma. Its usage is demonstrated by the following statement, which calculates a
partial sum of a geometric series:
TROLL Command: do geosum=sum(i=1 to 20: .5**i);
c. PRODUCT
As a substitute for the Greek (capital) pi, the PRODUCT operator is analogous to the SUM operator in most
respects:
TROLL Command: do nfactorial = product(i=1 to n: i);
d. ::
Finally, the :: ("range" or "doublecolon") operator produces an array of numbers or dates containing the
sequence ranging between its operands:
TROLL Command: do prt.(1::4);
1::4:
Numeric array 1 space dimension: 4
[1]:
[1]:
1994A
E. FUNCTIONS
Ladies and Gentlemen, we have reached our cruising altitude. Please note that the "FASTEN SEAT BELT" sign has
been turned off. We will be flying over the Sea of Functions for several hours, so please make yourselves comfortable.
Functions behave very much like operators. While an "operator" performs an "operation" on its "operands", a "function"
performs a "procedure" on its "arguments." One way a "procedure" differs from on "operation" is that a "procedure"
often has "side effects." Both an operator and a function ordinarily return a single result, but a function can do more.
The PRTDATA function (commonly known as "PRT."), with which you are undoubtedly familiar by now, is an example.
Like an operator, PRTDATA does return a value, but usually we ignore the return value. Typically we focus on the "side
effect" of PRTDATA: before returning the value, PRTDATA displays the value on the screen along with descriptive
information. The following passage shows both PRTDATA's return value and its side effect:
TROLL Command: do x=prtdata(2);
2:
Numeric scalar:
In the first command, we ask TROLL to compute the value prtdata(2) (which happens to be 2) and to put that value in
the variable x. In the course of computing the value, PRTDATA displays the name, type, and value of its argument. In the
second command, we ask TROLL to compute the value prtdata(x) and then throw that value away. We wouldn't ask an
operator to compute a value and then throw it away: "do x+2;" is a perfectly acceptable TROLL command, but it's not
useful. Since PRTDATA is a function, it can be useful despite an unused return value.
Because functions can have "side effects," the "arguments" to a function differ in one important respect from the
"operands" of an operator: operands can only represent objects to be used by the operator, but arguments can represent
objects to be changed by a function. (Note that the arguments themselves cannot be changed! TROLL passes arguments
by value.) Typical examples of arguments that represent changing objects are database names (strings that represent
databases) and variable names (strings that represent variables). The following passage demonstrates by using the
DFDELETE function to delete a variable from the default SAVE database.
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
do
do
do
do
var=1;
varname="VAR";
basename="SAVE";
prt.(varname, basename);
VARNAME:
String scalar:
"VAR"
BASENAME:
String scalar:
"SAVE"
"VAR"
BASENAME:
String scalar:
"SAVE"
First, this passage creates a numeric variable called VAR and two string variables called VARNAME (to contain the
name of the numeric variable) and BASENAME (to contain the name of the database in which VAR is stored). Then the
passage uses the DFDELETE function to delete VAR from the SAVE database. As you can see, the arguments to DFDELETE
remain unchanged (in the default SAVE database). However, the variable VAR  the object to which those arguments
refer  is gone. No operator could have done that!
A more obvious way in which functions differ from operators is in the syntax. Operators can take several forms (usually
"special characters" or "mathematical signs"). Functions have one distinct form: a function name, followed by a set of
parentheses containing a list of arguments separated by commas. (The arguments themselves can take many forms.)
Finally, functions differ from operators in that operators must be part of TROLL itself, whereas functions can be defined
by the user. Creating such userdefined functions is a fairly advanced task, but fortunately for the beginner, there are
plenty of useful functions built in to TROLL.
1. BuiltIn
Indeed, TROLL has so many builtin functions that even a sophisticated user can feel overwhelmed. It is
convenient to divide TROLL's builtin functions into categories according to their typical uses. (In the following
classification, some functions fall into more than one category.)
a. algebra and trigonometry
Algebraic and trigonometric functions extend the mathematical capabilities of TROLL's operators. The
following are available:
standard trigonometric functions:
SIN
COS
TAN
COTAN
standard rounding
ROUNDUP
absolute value
MODULO
remainder
advanced arithmetic functions
EXP
LOG
(natural)
LOG10
SQRT
difference an array
b. array creation and manipulation
Array processing is one of TROLL's particular strengths.
putting arrays together
COMBINE or C.
concatenates values into a vector or timeseries
SEQ
EXPAND
combines arrays
PARTCOMB
combines matrices
TSCOMB
combines timeseries
taking arrays apart
VALUES
sorts vectors
or REV.
reverses the order of values in a vector
REVERSE
TRANSP
NOR.
ALLSAME
IDENTICAL
extracts substrings
SPLITSTR
locates substrings
changing strings
LOWER
converts to lowercase
UPPER
converts to uppercase
CHANGESTR
converts datatypes
STR2SRC
MATMULT
matrix multiplication
DIAGONAL
decompositions
CHOLESKY
Cholesky decomposition
MINFIT
LU decomposition
SCHUR
Schur decomposition
GENSCHUR
Kronecker product
EIGEN
Kalman filter
e. missing values
In the real world of data analysis, the data usually contain gaps, for one reason or another. And
macroeconomic simulations often look into the future, where real data obviously aren't available yet.
TROLL has several functions that deal directly with the missing value problem. Most of the function
names begin with the letters "NA", which are the code for a missing value in TROLL.
Finding Missing and NonMissing Values
BOUNDS
calculates possible regression bounds  common date ranges that contain no missing
values in any of several timeseries; can also set and retrieve the current global bounds
NAMASK
results by default, but you may want to customize the presentation or request information that isn't
available directly from a TROLL task. That's when screen/console output functions become useful.
You've already seen how useful PRTDATA can be when you want to know about a data object. Other
screen/console output functions allow you to print information in alternative formats.
You might also want to save the information on your computer so you can look at it later. Or you might
want to share it with other applications that don't interact directly with TROLL, or with other people that
don't have TROLL. For these uses, there are file output functions. (There are also some standard TROLL
macros that simplify the use of output functions, as you will see later.)
Occasionally you may also want to do "internal output," that is, to write information from a TROLL data
object into an "outputlike" format but keep the result in TROLL's internal data space. This could be
useful, for example, if you are putting together a formatted page but can't be sure of the format until
you've computed the values. You can write a program that will write the results internally and then
manipulate them into an appropriate format before writing the final output. Or you may want to sort a set
of numerical data based on its text appearance rather than its numerical values.
With the exception of internal output, most output functions are useful primarily for their "side effects"
rather than their return values. They deliver the important results to the screen or to a file rather than to
TROLL. Therefore, the return values, which are internal TROLL objects, are less consequential. For this
reason, you might regard a typical output function as a "command in function's clothing."
screen/console output
PRINT
writes a matrix with row and column labels to an external text file
internal output
SPRINTF
distribution functions.
discrete distributions (cumulative)
PBIN
binomial distribution
PHYPG
hypergeometric distribution
PPOIS
Poisson distribution
continuous distributions
PCHI
chisquare distribution
PFISH
F distribution
PNORM
normal distribution
PSTUD
Student's tdistribution
inverse distribution function
INORM
(sum)
or VAR.
VARIANCE
SDEV
standard deviation
STATS
generates a matrix containing covariances and correlations for a set of vectors or series
extrema
MAX
j. programming
The functions listed below are primarily for use in TROLL programs (macros and userdefined
functions). If you're not planning to write programs (or to read programs written by others), then you
probably won't need to know about them. But you should be aware that they exist and may be working
behind the scenes. If you are planning to write TROLL programs, these functions provide a good starting
point: you will certainly use some of them.
input
NUMARGS
EQEVAL
There will be times, of course, when you will want to work with files used by the host operating system
rather than TROLL files. If you want to transfer information to another program, for example, or create
an easily humanreadable data file using a format different from TROLL's standard output format, then
you may want to work with host system files. TROLL provides numerous functions for this purpose.
file system information
HFDIRSEP
current date and time or the number of seconds since starting TROLL
GETENV
minimizes a function
getting TROLL information
LKSTATUS
calculates possible regression bounds  common date ranges that contain no missing
values in any of several timeseries; can also retrieve the current global bounds
GROW
returns dates with the specified periodicity type, year and fraction
date conversion
DATE2FRAC
DATE2WDAY
moving average
KALMANF
Kalman filter
KFOPT
2. UserDefined
TROLL also allows users to define their own functions. Some installations have libraries of userdefined
functions that are available to all local users. Userdefined functions are defined in certain TROLL programs,
which are a later topic. The syntax for calling userdefined functions is like the syntax for builtin functions,
except that userdefined functions must be declared as such. The easiest way to declare a userdefined function
is to affix the suffix 'F to the name of the function, as in "myresult = domything'f(mydata, myparameter)". As
long as it is properly declared, a userdefined function can be used anywhere that a builtin function might be
used.
F. EXPRESSIONS
Data symbols, literals, operators, and function symbols come together to form expressions. Expressions can be joined
together (using operators and functions symbols) to form larger expressions. The simplest expression consists of a
single literal, such as 1.0. Another simple form of expression is a single data symbol, such as GDP. The next level of
complexity comes when you add an operator, either a binary operator joining two expressions, as in the expression
GDP1.0, or a unary operator modifying an expression, as in GDP. You can also use a special operator to form a new
expression, as in DEL(1: GDP). Another way to use an expression within an expression is by using an expression as an
argument to a function, as in the expression LOG(GDP).
These two methods for forming expressions out of simpler expressions (using operators and using functions) allow
arbitrary levels of complexity in the expressions you can synthesize. Starting with the simple expression GDP, for
example, you can form LOG(GDP) and then apply the special operator DEL to produce the expression DEL(LOG(GDP)).
Then combine this expression with the simple expression 1.0 using the binary operator minus to produce the expression
DEL(LOG(GDP))1.0. This whole expression can be placed in parentheses and connected with the simple expression 100
using the multiplication operator to produce the expression 100*(DEL(LOG(GDP))1.0), which represents the percent
compound rate of change in GDP over one period. You could follow a similar process using the simple expression CONS to
produce the expression 100*(DEL(LOG(CONS))1.0). And then connect the two: 100*(DEL(LOG(CONS))1.0) >
100*(DEL(LOG(GDP))1.0). This expression will have the value TRUE or FALSE, depending on whether CONS is growing
faster than GDP. You could convert the result from a boolean value to a string by applying the CONVERT function to
produce the expression CONVERT(100*(DEL(LOG(CONS))1.0)>100*(DEL(LOG(GDP))1.0)). Then take the simple
expressions "It is " (a string literal) and " that consumption is growing faster than GDP." (another string literal)
and use the string concatenation operator to produce an even larger expression: "It is "  CONVERT(100*
(DEL(LOG(CONS))1.0)>100*(DEL(LOG(GDP))1.0))  " that consumption is growing faster than GDP." You
could apply the PRTDATA function to this expression to produce a still larger one, and you could then apply the DO
command to that larger expression to produce a command, as in this example:
:
:
:
:
:
:
:
:
:
"It
"It
"It
"It
"It
"It
"It
"It
"It
is
is
is
is
is
is
is
is
is
In this example, by design, either "It is TRUE ... " or "It is FALSE ... " in any given year. With less complete data, you
might find some years where "It is NA that consumption is growing faster than GDP."
You can also use lags, leads, and subscripts in expressions. Each lag, lead, or subscript is itself an expression, so this is
another method for combining simpler expressions into more complex ones. For example, the expression 2*I1 can be
used as a lag, a lead, or a subscript (depending on the type and value of I), as in the expression X[2*I1]*GDP(2*I1). In
the first half of that larger expression, the expression 2*I1 is used as a subscript to select a particular row or element of
X. In the second half, the expression 2*I1 is used as a lag or lead (depending on its sign) to offset the elements of GDP
by 2*I1 periods.
G. MODELS
Models are the backbone of TROLL. Simply stated, a model is a set of equations used to express relationships among
objects. Those objects are represented by symbols. Some may be relatively concrete objects for which explicit empirical
data are available  US GDP, for example; others may be abstract objects that cannot be measured directly  marginal
utility, for example. The relationships described by a model may be specified precisely, as in X=2*Y, or they may be
described abstractly, as in X=C*Y, where C is a parameter that can be estimated. They may represent known relationships
 relationships that are true by definition (such as SAVINGS = INCOME  CONSUMPTION) or wellestablished in empirical
work (such as Okun's law)  or they may represent hypothesized relationships. In the latter case, the precision with
which the model could be estimated might provide an indication of how reasonable the hypothesized relationships are.
Even if a model contains hypothesized relationships and cannot be estimated from empirical data, the model may be
useful to answer the "What if" question via simulation.
1. Model Files
In TROLL, a model is represented by a "model file" consisting of a symbol table and a numbered list of
equations, along with possible comments and sometimes simulation information indicating how TROLL has
analyzed the model. Specifically, a model file has the following structure:
first, an optional comment describing the entire model
then, a symbol table containing the symbolname and symboltype, along with an optional comment, for
each symbol in the model
then, a numbered list of equations, each of which may also have a label and/or a comment
finally, code possibly added by a simulation or related task
2. Symbol Table
The symbol table has an entry for each symbol in the model. (Being "in the model" usually means that a symbol
occurs in one of the model's equations.) Each entry contains a symbolname, a symboltype, and possibly a
comment. Normally this information is declared by the user or by a program using the MODEDIT task. Users can
declare symbol table information explicitly with the ADDSYM and CHANGESYM statements, or they can declare
symbol table information "on the fly" by using symboltype suffixes when declaring equations. A symboltype
suffix consists of an apostrophe followed by an abbreviated symboltype identifier, of which there are seven  X
(exogenous), N (endogenous), D (definition), C (coefficient), P (parameter), POL (policy), or F (function). Finally,
TROLL will create symbol table information by default when a symbolname appears in an equation without
being declared; such a symbol will be assigned the type EXOGENOUS. The following sequence of statements
produces a model with a symbol table in which x and y are EXOGENOUS, b1 and B2 are COEFFICIENTS, and Z is
ENDOGENOUS:
TROLL Command: usemod; // declare a new model
New model: (nameless)
TROLL Command: modedit; // begin creating model
MODEDIT Command: addsym endogenous z; // add Z explicitly to the symbol table
MODEDIT Command: addeq bottom b1'c*y; // declare B1 implicitly; let Y default
MODEDIT Command: addeq bottom b2'c*x; // declare B2 implicitly; let X default
MODEDIT Command: print sym all; // display symbol table information
Symbols:
ENDOGENOUS :
Z
EXOGENOUS :
X Y
COEFFICIENT :
B1 B2
3. Equations
A model, as stated earlier, is a set of equations. The symbol table, comments, and other elements of the model
file may help TROLL or the user to understand those equations, but it is the equations themselves that are the
primary content of the model. In general, an equation consists of two expressions separated by an equal sign. In
TROLL, an equation must also have a number, which identifies it, and may also have a label as an alternative
means of identification, as well as a comment to help users understand it. Normally, a user or program adds
equations to a model and modifies those equations using TROLL's MODEDIT task.
a. equation numbers
An equation number provides unique identification for a given equation within a model. The equation
numbers for a given model must form a sequence of integers starting with one. Normally, when a user or
program adds an equation to a model, TROLL automatically assigns to that equation the next equation
number following the specified position. For example, "ADDEQ 3 Y=1;" specifies that the equation "Y=1"
is to be added after equation 3. TROLL will therefore assign the number 4 to the new equation. If an
equation with the number 4 already exists, it will be renumbered as 5, and any equations appearing
thereafter will similarly have their numbers incremented. The keyword BOTTOM can be used to specify
"the last equation number in the existing model," and the keyword TOP can be used as a synonym for 0 or
"before the first equation in the existing model."
b. equation labels
A label is an alternative way to identify an equation uniquely within a model. Labels that exist must be
unique within a model, but it is never necessary for an equation to have a label, even if other equations
have labels. If an equation does have a label, TROLL will understand the label to mean essentially the
same thing as the equation's number (in most contexts). A user can specify a label by placing the label,
followed by a colon, just before the equation being added. The following example begins with the model
set up by the previous example:
MODEDIT Command: print eq all;
Equations:
1:
2:
B1*Y
B2*X
MODEDIT Command: addeq bottom neweq: y=b1*x; // new equation labelled "NEWEQ"
MODEDIT Command: print eq all; // display equations including new equation
Equations:
1:
2:
3: NEWEQ
B1*Y
B2*X
Y = B1*X
1:
2: NEWEQ
B2*X
Y = B1*X
B2*X
H. CALCULATIONS
Expressions are used for two primary purposes in TROLL. First, they are used in model equations to indicate the
mathematical structure of the model. Second they are used in data calculations to generate new data from existing data.
This latter use takes two forms:
1. DO Commands
From the TROLL command prompt, calculations are performed via DO commands. A DO command instructs
TROLL to perform a calculation on existing data and to store the result under the specified symbolname
(variable name). Where to store the result depends on the particular DO command used:
DO
store the result in the first datawritable database on the current SEARCH list
DOCORE
store the result in the "CORE" database (sort of a temporary "scratchpad" which is deleted as soon as you
exit the current DO task or enter another task)
DOSAVE
store the result in the "SAVE" database, which exists for the remainder of the TROLL session
DOFILE
store the result in the first datawritable permanent database on the current SEARCH list
The storage locations for DO or DOFILE can be overridden by using a multilevel variable name (a name containing
one or more underscores), which instructs TROLL to prefer a database whose alias is the first level of that
variable name. If such a database exists, and, in the case of DOFILE, if it is a permanent database, then TROLL
will use that one rather than the first one on the SEARCH list. For example, if a datawritable database exists with
the alias MYBASE, then the following statement will cause X to be stored in that database with the value 2: DO
MYBASE_X = 2;. However, if no such database exists (on the ACCESS list), that statement will cause a variable
called MYBASE_X to be stored in the first datawritable database on the SEARCH list.
Generally, if an object already exists with the specified name in the appropriate database, a DO statement will
cause TROLL to replace that object. To avoid replacing important data objects, it is often useful to keep a
nonwritable copy of a database as a backup.
2. Expression Statements
The other way to perform calculations in TROLL is with an expression statement (also called an "assignment
statement"). An expression statement occurs within a TROLL program; it cannot be entered interactively. The
format of an expression statement is essentially a DO statement without the "DO". In a TROLL program, the
statement "X=2**N;" would cause TROLL to calculate the value 2**N and then store it in the program variable X.
I. TASKS
Most of TROLL's substantive capabilities are divided into a set of broad areas called tasks. Often, when you instruct
TROLL to take a certain action, you also cause it to enter the task in which that action is defined. For example, if you
type "addeq bottom x=2;" at the TROLL prompt, TROLL will immediately enter the modelediting, or MODEDIT task.
When TROLL enters a task, that task takes over control from TROLL and becomes the new environment. The prompt
displayed during an interactive TROLL session shows the current task. Thus, in the example just described the prompt
changes to indicate that TROLL has entered the modelediting task:
TROLL Command: addeq bottom x=2;
MODEDIT Command:
modelediting task
Estimation
Linear SingleEquation Estimation
ordinary leastsquares
OLS
simulation task
Usually you can enter a task by typing the name of the task, or often by typing a command that TROLL recognizes as
part of that particular task. For example, you can enter the MODEDIT task by typing MODEDIT. You can also enter the
MODEDIT task by issuing the ADDEQ command, since TROLL recognizes ADDEQ as belonging exclusively to MODEDIT.
In the case of SIMULATE, the simulation task, you can also enter by typing FORECAST. FORECAST is not part of SIMULATE;
rather, it is a command to enter the same task in a different mode: the SIMULATE command starts the simulation task in
fullmodel simultaneous mode; the FORECAST command starts the simulation task in singleequation mode.
In general, you can exit from a task by typing QUIT, which will return you to the "TROLL
MODEDIT Command: quit ;
J. COMMANDS
Command:"
prompt.
An interactive TROLL user communicates with TROLL by issuing commands and reading responses. A TROLL
command is a statement, normally terminated by a semicolon, that instructs TROLL to take a certain action. Unlike a
function or an expression, a command is "entire of itselfe": TROLL will respond directly to a properly formed
command without any accompanying information. By contrast, TROLL cannot interpret a function or an expression
except in the context of a command or a model equation.
There are three types of commands in TROLL:
1. HighLevel Commands
A highlevel command is a command directed at TROLL itself rather than at a particular task. Often, highlevel
commands are used to start TROLL tasks. For example, the highlevel command OLS starts the OLS task, and
the highlevel command MODEDIT starts the MODEDIT task. A high level command can also be used to control the
TROLL session. For example, the highlevel command TREXIT ends a TROLL session, and the highlevel
command USEMOD sets the working model file for a TROLL session.
Normally, you type a highlevel command at the "TROLL Command:" prompt. Often, you can also type a
highlevel command at a task prompt such as "MODEDIT Command:". When you do that, TROLL leaves the task in
order to execute the highlevel command. What happens next depends on the particular highlevel command. If
the command is one that starts a new task, then you will see the task prompt for that new task. Otherwise, you
will see the TROLL command prompt. Consider the following session:
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
COEF
ESTIMATE
X
CONST
1.147431
4.090767
RES
1A
2A
3A
4A
5A
6A
7A
2.125237
1.047411
0.928842
0.959146
0.191067
1.588623
3.66308
ERROR 101
Not a command:
PRTRESULT
TROLL Command: ols y x, 1a to 7a;
COEF
X
CONST
ESTIMATE
1.147431
4.090767
When we issue the USEMOD command from with the OLS task, that task closes and we are left at the TROLL
command prompt. USEMOD does not invoke a new task. Later, when we issue the MODEDIT command from within
OLS, that task closes again, but this time we enter the MODEDIT task. Unlike USEMOD, MODEDIT is a command that
invokes a new task.
2. LowLevel Commands
A lowlevel command is a command directed at a specific TROLL task. Normally, you type a lowlevel
command at the prompt for the specific task to which it belongs. In the previous example, PRTRESULT is a
lowlevel command belonging to the OLS task. Outside the OLS task, PRTRESULT is unrecognized and produces an
error.
Sometimes you can type a lowlevel command at the prompt for a different task. Such cases occur when
TROLL can figure out what task to invoke and TROLL has enough information to invoke that task. Consider the
following:
MODEDIT Command: ols y x ;
COEF
X
CONST
ESTIMATE
1.147431
4.090767
Equations:
1:
Y = C*X
MODEDIT Command:
At the
OLS prompt, we issue a lowlevel command foreign to the OLS task. The OLS task cannot process the
command directly. In this case, however, TROLL can figure out what to do. To process the ADDEQ
command, TROLL must first enter the MODEDIT task. To enter the MODEDIT task, TROLL must first exit the OLS
task. Automatically, in this case, TROLL exits the OLS task and enters the MODEDIT task, where it can now
process the ADDEQ command successfully.
ADDEQ
3. Utility Commands
A utility command is a command that can work either inside or outside a TROLL task. If you type a utility
command at a task prompt, TROLL executes the command without leaving the task. If you type a utility
command at the TROLL prompt, TROLL executes the command without entering a task. In other words, a utility
command runs without moving the user to a new command environment. The following passage shows the use
of the utility command LKSEARCH:
MODEDIT Command: ols y x ;
COEF
X
CONST
ESTIMATE
1.147431
4.090767
W?
W
W
Filetype
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
W?
W
W
Filetype
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
W?
W
W
Filetype
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
Each time we type "LKSEARCH", TROLL does the same thing: it displays the SEARCH list and repeats the prompt
from which we issued the command.
Most of the commands used in the examples in this book thus far have used utility commands. Among them are
and LKACCESS. Most such "everyday, garden variety" commands are utility commands, but
many "exotic", special purpose commands are also utility commands. For example, NLSOPT, which specifies
options for nonlinear singleequation regression, is a utility command. To specify NLS options, we need not
enter the NLS task, so why introduce the complexity of changing tasks?
DO, SEARCH, ACCESS,
K. PROGRAMS
Traditionally, "program" refers to a set of instructions telling a computer what to do. But that's only part of the
definition. A program is not a mere sequential list of instructions to be executed as if they had been typed by a user.
(Such a list might be called a "batch" or a "script"; TROLL users would call it an "input file.") In addition to listing
instructions, a "program" usually enables the computer to make decisions about which instructions to execute. Also, a
"program" usually allows the user to supply specific parameters to govern a particular "run" of the program.
In TROLL, a program usually has these characteristics, too. Specifically, a TROLL "program" is distinguished from an
"input file" by its use of the "TROLL Programming Language" (or "TPL") rather than TROLL commands. TPL
includes "control structures" (such as FOR loops and IFTHENELSE constructions) and userinput statements (such as
GET). TPL uses a different syntax than TROLL commands, although the two have much in common. TPL "expression
statements" are like DO commands without the "DO", and "queueinput" statements allow some TROLL programs to issue
TROLL commands.
There are two kinds of TROLL programs: macros and functions. To the user, macros are just like TROLL commands,
except that a macro begins with an ampersand (&); and TPL Functions are just like builtin functions, except that a TPL
function ends with an apostropheF ('F). To the programmer, macros and functions are two types of programs that have
different ways of passing information and different sets of programming statements available. For example, macros can
use "queueinput" statements to issue TROLL commands, but functions cannot.
1. Macros
A macro is a program that combines a set of TROLL commands and programming statements into a single
command. To someone using a macro, the macro appears as a single command that begins with an ampersand
(&). Writing a macro is more difficult than using one, but writing a macro is usually worth the effort. A macro
eliminates the drudgery and potential for error inherent in repetitive sequences of commands.
a. userwritten macros
In this context, "userwritten" means "written by programmers who use TROLL" (not necessarily by
"users" in the sense of "people who use macros"). The ability of "userprogrammers" to write macros is
fundamental to TROLL's concept of extensibility. TROLL offers users the tools to do what they need to
do, and macros are one way of using those tools.
b. macros included with troll
TROLL ships with several macros already included. &PRTDSET is one example. These macros are just like
ordinary TROLL commands, except that they begin with an ampersand, and they happen to be
implemented as TPL programs rather than C programs.
2. UserDefined Functions
Again, in this context, "userdefined" means "defined by programmers who use TROLL" (not necessarily by
"users" in the sense of "people who use functions"). A userdefined function is a function designed to
supplement the set of functions built in to TROLL. A userdefined function behaves like a builtin function.
Unlike a builtin function, a userdefined function has to be declared explicitly, usually by adding apostropheF
to the end of its name.
Functions operate at a higher level of abstraction than macros: a function processes a set of arguments specified
in a function call. A function cannot issue TROLL commands; it can only process its own arguments and return
a value.
L. OPTIONS
TROLL allows the user to set a number of options that control various aspects of the way TROLL and its various tasks
behave.
1. Bounds
The BOUNDS option (e.g., "bounds 1970a to 2000a;") determines the range of dates used by regression tasks to
estimate regressions on time series. You can't run a regression unless you set BOUNDS. You can set BOUNDS
implicitly while running a regression (e.g., "ols x y, 1970a to 2000a;"). If you set the BOUNDS in that way, the
setting you choose replaces the global setting. The LKBOUNDS command lets you see the current BOUNDS setting.
2. System Options
System options are general options that usually don't require setting by the user. They are sometimes useful for
debugging purposes and for special situations. System options are set with the SYSOPT command and can be
viewed with the LKSYSOPT command.
a. log file (LOGFILE and LOG)
"sysopt logfile filename;" controls the identity of the TROLL log file, by default "troll.log".
"sysopt nolog;" (or "sysopt log off;") eliminates the log entirely.
b. monthly/quarterly date format (QMPER)
The QMPER option controls the interpretation of monthly (e.g., "2000m12") and quarterly (e.g., "2000q4")
dates either as "(12 or 4) periods per year" (OLD) or as distinct (not derived from annual) periodicities
(NEW). With sysopt qmper new, TROLL also writes periodsperyear dates explicitly using "PxxFxx"
format rather than the "Qx" or "Mxx" format. A third option, QMPER CONVERT causes TROLL to use the
NEW interpretation and also to convert any 4or12 periodsperyear data read from external databases to
use explicitly monthly or quarterly NEW dates. As of TROLL 1.093, the default is OLD, but future versions
may use CONVERT as the default.
c. see output or not (SCREEN)
SYSOPT SCREEN
is ON by default, but you can turn it OFF when necessary to hide boring or confusing
output.
d. macro debugging (TRECHO)
(If you don't know anything about writing macros, don't even read this paragraph: you can ignore SYSOPT
TRECHO.) Normally, TROLL hides from the user any commands generated by "queueinput" statements
inside a macro. By typing "sysopt trecho on;" you can view those commands as part of the output.
This can be very useful for debugging.
e. file locking (LOCKING)
Normally, TROLL does not permit a session to ACCESS a database while another TROLL session is writeACCESSing it. (If the file is already readACCESSed by one session, the other also will not be able to writeACCESS it.) However, if both sessions have "sysopt nolocking;" (or "sysopt locking off;"), TROLL
will allow such simultaneous ACCESS.
3. Output Options
Output options control formatting for various commands. Set output options using the OUTOPT command (e.g.,
"outopt rmarg 10;"), and examine them using the LKOUTOPT command.
a. margins
There are LMARG, RMARG, TMARG, BMARG. (Guess what those mean.) By default LMARG is 1 (start at first
character of each line), RMARG is 80 (print each line until the 80th character), and TMARG and BMARG are
zero (no lines skipped at the top and bottom of the page).
b. paging
PAGELEN
NOWAIT)
(default 25) determines the number of lines per screen (for some commands). WAIT (default
determines whether to pause after each screen.
c. numbers
These options determine the way numbers are displayed by some commands, though it is not always
possible to display numbers according to all the option settings. NUMWIDTH is the width; SIGDIGIT, the
maximum number of significant digits; and DECIMALS, the number of decimal places to show. Negative
values of DECIMALS mean the same thing as the corresponding positive values, except that also instruct
TROLL not to print trailing zeros.
d. miscellaneous
LABWIDTH
4. Convergence/Optimization Options
These options control various aspects of various optimizations (including both optimizations that take place
during estimation tasks and optimizations that take place during simulation tasks). You can set these options
using the CONOPT (e.g., "conopt stop 50;") command and examine them using the LKCONOPT command.
a. iteration limit (STOP)
CONOPT STOP
is the limit on the number of iterations. The default is 10, but 10 is frequently not enough.
d. simulation options
DAMP, BIGRES, TINYRES, FGS, INEVERY, LASTDAMP, MAXRAT, SMTUNE, and SIMGUESS control various aspects of
simulation. See the TROLL Reference Manual CONOPT section for details.
5. Other Options
a. active date range (DRANGE)
The DRANGE command (e.g., "drange 1939a to 1945a;") limits the range of dates that TROLL will read.
Be careful when you rewrite a series that has been read while DRANGE is in effect.
b. active model (USEMOD)
The USEMOD command determines the current working model for editing, estimation, or simulation.
USEMOD without an argument sets the current working model to a new, empty one.
c. regression options (REGOPT)
REGOPT
determines what output regressions will produce. See the TROLL Reference Manual for details.
NLS
has its own set of convergence and optimization options. See the TROLL Reference Manual.
M. COMMENTS
Comments are pieces of text that are inserted by users but not used by TROLL. A comment helps to remind the user,
and to explain to other users, what something means.
2. Equation Comments
Equations can also have comments, which are added and modified using the EQCOM command.
3. Model Comments
Models can also have comments, which are added by the MODCOM command.
4. Symbol Comments
Symbols can also have comments, which are added by the SYMCOM command.
5. Data Comments
Data objects (arrays) can also have comments, which are added or deleted by the PUTCOM function. (The GETCOM
function retrieves data comments.)
A TROLL input file is simply a file containing a list of TROLL commands. When you run the input file, those
commands will be executed.
In general, there are two ways to run a TROLL input file. First, you can run it from inside a TROLL session by typing
INPUT followed by the name of the file, without the ".INP". For example, the following command runs a file called
dispcomm.inp:
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
input dispcomm
// This text is from inside the input file
// The following statements are executed from inside the input file:
lksearch;
W?
W
W
Filetype
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
10
The second way to run a TROLL input file is to use its name (without the ".INP") as a commandline argument when
you invoke TROLL from your host system. The following example was produced using a command prompt window in
Windows NT. Other environments will produce slightly different results.
c:\\troll>troll dispcomm
TROLL Release 1.036
Copyright (C) Intex Solutions, Inc. 19931997
Copyright (C) Massachusetts Institute of Technology 19781987
TROLL Command: // This text is from inside the input file
TROLL Command: // The following statements are executed from inside the input file:
TROLL Command: lksearch;
Current SEARCH list:
Name
SAVE
.
TROLLSYS
W?
W
W
Filetype
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
10
In Windows, there are two other ways to run a TROLL input file. If you have the GUI version, you can run an input file
by typing its name (without the ".INP") in the "Command Argument" space in the "TROLL Startup" dialog box that
appears when you invoke the GUI or press the "GO" button from within the GUI. In Windows 95/NT4 or later, if you
register TROLL input files as a file type and use TROLL as the program that performs the default action (usually
"open"), then you can run a TROLL input file by doubleclicking on its icon.
D. OPERATIONS ON DATES
The arithmetic operations that can be performed on dates are:
date + number
Integer part of number is interpreted as a numberofperiods and added to date; return value is a date.
date  number
The dates are subtracted, and the return value is a number, the number of periods from the right date to the left
date.
E. ABOUT NA
An NA represents a notavailable or notcomputable value. You can have NA values of any datatype. When TROLL
cannot determine what datatype an NA should be  for example, when it sees an NA literal  it uses the NA datatype.
When it is clear from the context what datatype an NA should be, TROLL converts it automatically. The following
expressions calculate different types of NAs:
NA
NAtype NA
0 + NA
Numeric NA
"string"NA
String NA
1995q4 + NA
Date NA
TRUE AND NA
Boolean NA
In most cases, the value of a calculation that involves an NA will be NA also. There are exceptions where it makes more
sense to return a nonNA value, as shown in the following table:
Expression
Value
NA AND FALSE
FALSE
FALSE AND NA
FALSE
NA OR TRUE
TRUE
TRUE OR NA
TRUE
NA == NA
TRUE
NA <> NA
FALSE
NA == x
x == NA
NA <> x
x <> NA
V. TROLL SYNTAX
A. THE STRUCTURE OF TROLL STATEMENTS
TROLL statements end with semicolons. In interactive TROLL, and in batch (input) files, the TROLL statements are
"commands". A command begins with a "command name" and may contain "command arguments" or "option
specifiers" thereafter. A command ends (of course) with a semicolon.
TROLL programs consist of "programming statements". One common type of "programming statement" is an
"expression statement", which consists of a name followed by an equal sign followed by an expression. Another type of
statement common in macro programs is the "queue input" statement. The queueinput statement consists of two
greaterthan signs (>>) followed by a TROLL command. When the queueinput statement is executed, it causes TROLL
to execute that command.
2. Use of Underscore
In TROLL, underscores are often used to express levels in a hierarchy (much the same way periods are used in
C programming language structures, Usenet newsgroup names, and various other hightech contexts, or the way
slashes and backslashes are used by various operating systems). To a TROLL user, a name like
US_BLS_EMPLOYMENT_DATA_RELEASE would typically imply much more structure than the mere phrase "US BLS
Employment Data Release."
B. PROGRAMMING LANGUAGE
The TROLL Programming Language extends the modelling language by adding programming statements.
Programming statements control the evaluation of expressions. They provide conditional execution (IFTHENELSE),
looping (GOTO, FOR, WHILE), input reading (GET), and program control (CALL, RETURN). The TROLL Programming
Language is described in the manual Portable TROLL Programming Language.
C. ARCHIVE
TROLL databases are sometimes divided into "archives." An archive is a set of (usually related) TROLL data objects
whose names begin with the same prefix, where an underscore is used to separate the prefix from the rest of the object's
name. For example, the variables US_GDP and US_CONS both belong to the US archive. Within that archive, those variables
go by the names GDP and CONS.
Databases can have multiple levels of archives. For example, there could be a data series called EU_UK_GDP. This series
would be a member of the EU archive, in which it would be known as UK_GDP. It would also be a member of the EU_UK
archive, in which it would be known as GDP.
Archives have certain special properties in TROLL. For one thing, an archive can be put on the SEARCH list, and then it
will behave like an ordinary database. The following example shows how.
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
W?
W
W
Filetype
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
// Put the BODY archive on the search list
W?
W
W
Filetype
DATA
NONDATA
NONDATA
DATA
Basic?
BASIC
BASIC
BASIC
"Pink"
"Pink"
Filetype
DATA
NONDATA
NONDATA
DATA
DATA
Basic?
BASIC
BASIC
BASIC
"Pink"
TROLL Command: // But since the FACE archive is not on the search list
TROLL Command: do prt.(nose_color); // TROLL cannot find NOSE_COLOR
ERROR 2222
Evaluating error.
Variable 'NOSE_COLOR' was not found on the current SEARCH list.
Another property of archives is that archives of type DISK will automatically correspond to host system directories. The
following example is from Windows NT, but similar results would appear on other operating systems.
TROLL Command: host "dir maindir"; // Notice that "maindir" is empty
Volume in drive C is NT FAT BOOT
Volume Serial Number is 3381C10D
Directory of C:\\maindir
01/28/98
01/28/98
04:14p
<DIR>
.
04:14p
<DIR>
..
2 File(s)
0 bytes
231,505,920 bytes free
TROLL Command: access arch mode w id maindir_archive; // Access an archive
TROLL Command: do arch_x=1; // Put something in it
TROLL Command: host "dir maindir"; // Look at "maindir" now
Volume in drive C is NT FAT BOOT
Volume Serial Number is 3381C10D
Directory of C:\\maindir
01/28/98
01/28/98
01/28/98
04:14p
<DIR>
.
04:14p
<DIR>
..
04:16p
<DIR>
archive
3 File(s)
0 bytes
231,473,152 bytes free
Because of the properties of archives, TROLL knew that the database maindir_archive should correspond to the host
system directory called maindir\archive. (On a UNIX system it would be called maindir/archive.) When asked to
write something to that database, TROLL had to create the corresponding host system directory.
D. TPL
TPL is the TROLL Programming Language, which is used to write TROLL programs.
E. SIDE EFFECTS
"Side effects" are effects that functions have. The "direct effect" of a function is to return a value (the "value of the
function"). All other effects are "side effects."
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
4. Be Careful!
C. SPREADSHEET DATA
1. Time Series: the &WKS2TS Macro
2. Generic Matrices: the WKS2MAT Function
3. "Save As Text"
4. Other Options?
5. What About UNIX?
D. ARBITRARY BINARY DATA
DB Type
MEMDB
DISK
DISK
R/W?
R/W
R/W
R
Filetype
DATA
ALL
ALL
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\code
(Your ACCESS list may look different, depending on how your site is set up.)
The first entry on the list, SAVE, is a TROLL database unknown to the host system. The word "MEMDB" under the
"DB Type" heading, means that SAVE is a database kept in the computer's memory (RAM) during the TROLL
session [1]. As such it is not part of the host computer's file system, which typically includes only files on disk
and other "nonvolatile" media. Since only this TROLL session knows about this SAVE database, this SAVE
database will become permanently inaccessible (will NOT be "saved"!) when the TROLL session ends. Such is
the character, in general, of MEMDB databases. The SAVE database in particular is created at the beginning of every
TROLL session and lasts until the end of the session. (If multiple TROLL sessions are running, as some TROLL
versions allow, then each session will have its own distinct SAVE database.)
The second entry on the list is identified by a simple dot. This dot refers to the TROLL's "working directory" in
the host file system. When you start TROLL from a host system command line, the "current" directory becomes
TROLL's working directory; when you start the Windows GUI version, you can specify the working directory.
The DB type "DISK" refers to a database that corresponds to a directory (or "folder") in the host file system. The
items in that database correspond to host system files.
The final entry on the list is the TROLLSYS database. This database is also type DISK. It corresponds to the host
system directory listed in the ID column. When you launch TROLL (start a TROLL session), it determines the
identity of the TROLLSYS databases. By default, the TROLLSYS database corresponds to the host system directory
where TROLL was installed. Before starting a TROLL session, you can change the location for TROLLSYS by
setting the host system's TROLLSYS environment variable.
In the Filetype column, TROLL indicates what type of information a database may contain. The SAVE database
is a "data base" in the strict sense, in that it will contain only "data". The other two databases have filetype ALL,
which means they can contain any kind of information, including models and programs. The TROLLSYS database,
for example, may be not just a "data base" but also a "model base" and a "program base".
Finally, look at the column headed " R/W?". That column tells whether this TROLL session has write access to
the given database. In this example TROLL has write access to both the SAVE and the [dot] databases but not to
the TROLLSYS database. The fact that TROLL has write access to a given database, however, does not mean that
TROLL will write to that database when asked to store information. TROLL's actual behavior will depend on
the SEARCH list.
DB Type
R/W?
Filetype
Basic?
ID
SAVE
.
TROLLSYS
TEMPDIR
MEMDB
DISK
DISK
DISK
R/W
R/W
R
R
DATA
ALL
ALL
ALL
Fixed
Fixed
Fixed
(none)
(none)
d:\troll\code
TEMPDIR
As with most databases of type DISK, TEMPDIR allows " ALL" filetypes. Because of this characteristic,
DISK databases are convenient for storing "nondata" information such as models and programs. They
can also store "data" in the strict sense, but each data object will be stored as a separate host system file.
With many data objects, this mode of storage becomes quite inefficient, so it is generally preferable to
use other database types to store data.
b. host files as DATA databases
To add a nonDISK database to the ACCESS list, you must specify the database TYPE. For persistent storage
and retrieval of data, you will typically want to use databases that correspond to host system files. (Such
databases cannot be used for models and programs, which must be stored individually within a host
system directory.)
Several varieties of "hostfile" databases exist. TROLLDB databases (typically identified on the host system
by the .TRL file extension) use a binary format designed for optimal performance. The TROLLDB format is
specific to TROLL and cannot be easily read by human beings. FORMDATA databases (typically identified
by the .FRM extension) use a text format, less efficient for TROLL's internal use but readable by human
beings and potentially by other computer programs. TESTBIN1 is a binary format designed to minimize
storage requirements. (Note that FORMDATA and TESTBIN1 formats are platformindependent, so that PC
and UNIX system users can share data. TROLLDB format is platformspecific.) Two other text formats are
available for sharing with specific other software: TSD for AREMOS, and TSPLOAD for TSP. FAME format,
a nontext format for use with FAME software, is also available with some versions of TROLL.
The TYPE option, which specifies the TYPE of an ACCESSed database, consists of the word TYPE followed
by the name of the TYPE, as in:
TROLL Command: access base1.frm type formdata;
TROLL Command: access base2.trl type trolldb;
TROLL Command: lkaccess;
Accessed Databases:
Alias
SAVE
.
TROLLSYS
TEMPDIR
BASE1.FRM
BASE2.TRL
DB Type
MEMDB
DISK
DISK
DISK
FORMDATA
TROLLDB
R/W?
R/W
R/W
R
R
R
R
Filetype
DATA
ALL
ALL
ALL
DATA
DATA
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\code
TEMPDIR
BASE1.FRM
BASE2.TRL
// c1 happens to be in base2.trl
36.541054
DB Type
MEMDB
DISK
DISK
DISK
FORMDATA
R/W?
R/W
R/W
R
R
R
Filetype
DATA
ALL
ALL
ALL
DATA
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\code
TEMPDIR
BASE1.FRM
BASE2.TRL TROLLDB
BASE3.FRM FORMDATA
R
R/W
DATA
DATA
BASE2.TRL
BASE3.FRM
However, W is not the only write mode option. There is also MODE C, which causes TROLL to create a
new database from scratch and erase any existing database with the same name. And there is MODE N,
which opens a "new" database for writing, but only if it does not already exist. And there is MODE O,
which opens an "old" database for writing, but only if it does already exist. (With disk databases, since
they are maintained by the host system rather than by TROLL, the modes are not meaningful to TROLL,
which treats those modes the same as the W mode.)
d. database names: IDs and aliases
A TROLL database has two names. It has an ID, the name which enables the ACCESS command to find it
initially. And it has an alias, the name which TROLL uses for it while it is on the ACCESS list. Typically a
database's ID is the host system's name for it. (For example, tempdir is a host system directory name, and
base1.frm is a host system file name.) By default, a database's ID is the same as its alias.
In the case of databases that correspond to host system files, it is usually more convenient to specify the
ID explicitly and to assign a different alias. That way the TROLL session can avoid the cumbersome host
system file name and use a simple name for the database. In the syntax of the ACCESS command, the alias
always comes first, and the ID (if it is different from the alias) is specified with the ID keyword later in
the command. The following command places the database base4.trl on the ACCESS list (for write
access), using the alias b4:
TROLL Command: access b4 type trolldb mode w id base4.trl;
TROLL Command: lkaccess;
Accessed Databases:
Alias
SAVE
.
TROLLSYS
TEMPDIR
BASE1.FRM
BASE2.TRL
BASE3.FRM
B4
DB Type
MEMDB
DISK
DISK
DISK
FORMDATA
TROLLDB
FORMDATA
TROLLDB
R/W?
R/W
R/W
R
R
R
R
R/W
R/W
Filetype
DATA
ALL
ALL
ALL
DATA
DATA
DATA
DATA
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\code
TEMPDIR
BASE1.FRM
BASE2.TRL
BASE3.FRM
base4.trl
(You may notice that the ID for B4 is in lowercase letters, while the others are in uppercase. TROLL
automatically converts aliases  but not IDs  to uppercase. When no ID is specified, the uppercase alias
is used as an ID. When the ID is explicit and lowercase, it remains lowercase.)
e. the DELACCESS command: letting go of databases and changing access options
DELACCESS terminates access to a database or databases. After the word DELACCESS, you type the aliases
of the databases you want to terminate (separated by spaces). You can also use the keyword ALL, which
tells TROLL to terminate access to all databases except those that are terminationprotected.
There are two possible levels of termination protection. "Fixed" databases such as the SAVE database
have complete terminationprotection: they cannot be DELACCESSed. "BASIC" databases  those created
using the BASIC keyword  have partial terminationprotection. A "BASIC" database can be DELACCESSed,
but only by specifying its alias explicitly in the DELACCESS command. "delaccess all;" has no effect on
basic or fixed databases. The following passage demonstrates this process:
TROLL Command: access b5 type trolldb mode w id base5.trl basic;
TROLL Command: delaccess tempdir;
TROLL Command: lkaccess;
Accessed Databases:
Alias
SAVE
.
TROLLSYS
BASE1.FRM
BASE2.TRL
BASE3.FRM
B4
DB Type
MEMDB
DISK
DISK
FORMDATA
TROLLDB
FORMDATA
TROLLDB
R/W?
R/W
R/W
R
R
R
R/W
R/W
Filetype
DATA
ALL
ALL
DATA
DATA
DATA
DATA
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\code
BASE1.FRM
BASE2.TRL
BASE3.FRM
base4.trl
B5
TROLLDB
R/W
DATA
BASIC
base5.trl
Filetype
DATA
ALL
ALL
DATA
Basic?
Fixed
Fixed
Fixed
BASIC
ID
(none)
(none)
d:\troll\code
base5.trl
Filetype
DATA
ALL
ALL
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\code
DB Type
MEMDB
DISK
DISK
TROLLDB
R/W?
R/W
R/W
R
R/W
DB Type
MEMDB
DISK
DISK
R/W?
R/W
R/W
R
DB Type
MEMDB
DISK
DISK
DISK
FORMDATA
TROLLDB
FORMDATA
TROLLDB
TROLLDB
R/W?
R/W
R/W
R
R
R
R
R/W
R/W
R/W
Filetype
DATA
ALL
ALL
ALL
DATA
DATA
DATA
DATA
DATA
Basic?
Fixed
Fixed
Fixed
BASIC
ID
(none)
(none)
d:\troll\code
TEMPDIR
BASE1.FRM
BASE2.TRL
BASE3.FRM
base4.trl
base5.trl
// Note:
Accessed Databases:
Alias
SAVE
.
TROLLSYS
DB Type
MEMDB
DISK
DISK
R/W?
R/W
R/W
R
Filetype
DATA
ALL
ALL
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\code
g. access conflicts
If you run multiple TROLL sessions at once (possible with the console version but not with the
standalone GUI), or if you share data with other TROLL users, you may encounter error messages with
the phrase "Permission denied". In some cases TROLL will say "Database not found." even when there
is a database in the specified location. If so, you may be experiencing an ACCESS conflict. By default
(which you can override with "sysopt nolocking;" if you control both of the corresponding TROLL
sessions) TROLL will not permit any ACCESS simultaneous with write ACCESS. In other words, if one
TROLL session ACCESSes a database, all other sessions will be denied write ACCESS to the same database;
and if one TROLL session writeACCESSes a database, all other TROLL sessions will be denied any
ACCESS.
NIPA_CONS
NOB = 27
NOVAR = 2 NCOEF = 2
RANGE: 1969A to 1995A
RSQ =
0.9964
F(1/25) =
6919.221076
SER =
38.738866
DW(0) =
1.19302
MAX:HAT =
0.151311
DFFITS =
0.459821
COEF
ESTIMATE
NIPA_GDP
0.743172
CONST
425.007001
OLS Command: quit ;
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
0.996256
0
37517.492707
10.012457
2.214826
STER
TSTAT
0.008934
37.695226
83.181855
11.274823
PROB>T
0
0
The underscore syntax does have the advantage of avoiding ambiguity: if you always specify the correct
database explicitly, you always know what database you are using; there's no chance of accidentally defaulting
to the wrong database. But the underscore syntax is also a pain in the neck. This becomes particularly apparent
when you try to use a multilevel archive, and you end up using names like
local_mainbase_econdata_nipa_us_quarterly_nsa_real_base1985_gdp.
W?
W
W
Filetype
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
This is the typical SEARCH list at the beginning of a TROLL session. The "Name" column shows the aliases of the
databases on the SEARCH list. The other columns show the particular characteristics of those databases. Databases
with a "W" in the "W?" column will be used to store as well as retrieve information. The "Filetype" column tells
what kind of information can be stored in or retrieved from each database. For example, if TROLL wants to
store a model, TROLL will use the first database on the SEARCH list that has a "W" in the "W?" column and an
entry in the "Filetype" column that is compatible with models. In this case, since models are not data, TROLL
will use the second database on the list to store a model.
Accessed Databases:
Alias
SAVE
.
TROLLSYS
NIPA
TEMPDIR
BASE1.FRM
BASE2.TRL
BASE3.FRM
B4
B5
DB Type
MEMDB
DISK
DISK
FORMDATA
DISK
FORMDATA
TROLLDB
FORMDATA
TROLLDB
TROLLDB
R/W?
R/W
R/W
R
R
R
R
R
R/W
R/W
R/W
Filetype
DATA
ALL
ALL
DATA
ALL
DATA
DATA
DATA
DATA
DATA
Basic?
Fixed
Fixed
Fixed
BASIC
ID
(none)
(none)
d:\troll\sys\current
c:\usanipa.frm
TEMPDIR
BASE1.FRM
BASE2.TRL
BASE3.FRM
base4.trl
base5.trl
W?
W
W
Filetype
DATA
DATA
NONDATA
NONDATA
Basic?
BASIC
BASIC
BASIC
With b4 at the top of the SEARCH list, TROLL will now look for data in b4 before it looks for data in SAVE.
If a data object by the same name exists in both SAVE and b4, TROLL will ignore the one in SAVE. Notice
also that the "W?" column for b4 is blank. This reflects the default "nonwritable" status of SEARCH list
items. TROLL will not store new information in b4, but it will retrieve old information from b4.
Sometimes this situation can produce strange results:
TROLL Command: do x = 2;
// Set the value of X to 2
TROLL Command: do prt.(x); // Print the value of X
X:
Numeric scalar:
Huh? We set the value of X to 2; then we printed the value of X, and it was 1, not 2. Does that make any
sense?
In this case it does. When we set X to 2, TROLL looked through the SEARCH list and found the first
writable database  the SAVE database  and saved the value of X in that database. When we printed the
value of X, TROLL looked through the SEARCH list again and found the first readable database  b4. As it
happens b4 also contains a variable called X, and the value of that variable is 1. So TROLL correctly
prints out the value 1 for X. Just to check:
TROLL Command: do prt.(save_x, b4_x);
SAVE_X:
Numeric scalar:
B4_X:
Numeric scalar:
In this example, we used the keyword FIRST to specify the top of the SEARCH list. You can also use the
keywords LAST, AFTER, and BEFORE to specify other positions on the SEARCH list. For example:
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
W?
W
W
Filetype
DATA
DATA
NONDATA
NONDATA
ALL
DATA
DATA
Basic?
BASIC
BASIC
BASIC
W?
W
W
W
Filetype
DATA
DATA
DATA
NONDATA
NONDATA
ALL
DATA
DATA
Basic?

BASIC
BASIC
BASIC
Moreover, if you refer to X (without an underscore) and there happens to be a variable called X in
base3.frm, then TROLL will use that value of X, whether or not any other X exists elsewhere on the
SEARCH list. Any writeSEARCHable database is also readSEARCHable.
You won't always have the opportunity to make a database writeSEARCHable. If TROLL does not have
write ACCESS to a database, then the database cannot be writeSEARCHable. TROLL will make it
readSEARCHable instead:
TROLL Command: search first base2.trl w;
WARNING 5010
Search error:
The database 'BASE2.TRL' is accessed ReadOnly;
'W' ignored.
(If you have an earlier version of TROLL, it may give an error message and refuse to put the database on
the SEARCH list at all. In any case, since we didn't intend it to be readSEARCHable, we'll delete it and leave
the SEARCH list as it was reported above.)
TROLL Command: delsearch base2.trl;
TROLL Command:
W?
W
W
Filetype
DATA
DATA
NONDATA
NONDATA
ALL
DATA
DATA
DATA
Basic?
BASIC
BASIC
BASIC
W?
W
W
Filetype
DATA
DATA
NONDATA
NONDATA
DATA
DATA
DATA
Basic?
BASIC
BASIC
BASIC
You can remove all nonBASIC entries from the SEARCH list in one fell swoop:
TROLL Command: delsearch all;
TROLL Command: lksearch;
Current SEARCH list:
Name
W?
Filetype
Basic?
SAVE
.
TROLLSYS
W
W
DATA
NONDATA
NONDATA
BASIC
BASIC
BASIC
If you want, you can remove everything from the SEARCH list, but each nonBASIC entry must be removed
explicitly.
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
delsearch save;
delsearch .;
delsearch trollsys;
lksearch;
W?

Filetype

Basic?

You need not settle for TROLL's initial idea of what should be BASIC.
TROLL Command: search basic first b4;
TROLL Command: lksearch;
Current SEARCH list:
Name
B4
W?

Filetype
DATA
Basic?
BASIC
W?

Filetype
DATA
Basic?
BASIC
W?
W
W
Command:
Command:
Command:
Command:
Filetype
DATA
DATA
DATA
BASIC
dosave insave=1;
dofile infile=1;
do indo=1;
do prt.(dflist("b5"));
DFLIST("b5"):
String scalar:
"INFILE"
Basic?
BASIC
INDO
INSAVE

Numeric scalar
Numeric scalar
Command:
Command:
Command:
Command:
Command:
W?
W
W
Filetype
DATA
DATA
DATA
Basic?
BASIC
BASIC
GDP:
GDP = GDP
Numeric scalar timeseries Time dimension: Periodicity 1,
1969A
1973A
1977A
1981A
1985A
1989A
1993A
Time
:
:
:
:
:
:
:
dimension >
2914.780935
3316.134145
3584.683297
3925.140736
4427.403328
5034.525148
5305.365921
1969A to 1995A
2915.694014
3295.33595
3757.358183
3840.987421
4560.653581
5099.613333
5490.100259
(27 observations)
2998.886588
3268.552041
3852.01535
3995.877758
4692.324707
5049.97731
5601.5644
3152.285212
3429.965759
3831.268062
4268.504531
4870.559191
5187.463988
W?
W
W
Filetype
DATA
DATA
DATA
DATA
DATA
Basic?
BASIC
BASIC
GDP = GDP
Numeric scalar timeseries Time dimension: Periodicity 1,
1969A
1973A
1977A
1981A
1985A
1989A
1993A
Time
:
:
:
:
:
:
:
dimension >
2914.780935
3316.134145
3584.683297
3925.140736
4427.403328
5034.525148
5305.365921
1969A to 1995A
2915.694014
3295.33595
3757.358183
3840.987421
4560.653581
5099.613333
5490.100259
(27 observations)
2998.886588
3268.552041
3852.01535
3995.877758
4692.324707
5049.97731
5601.5644
3152.285212
3429.965759
3831.268062
4268.504531
4870.559191
5187.463988
W?
W
W
W
Filetype
DATA
DATA
ALL
DATA
DATA
DATA
DATA
DATA
Basic?

BASIC
BASIC
4. Be Careful!
The SEARCH list can be very powerful and very convenient. It can also be very dangerous. The bridges of the
world are littered with the bones of billygoats who tried to use the SEARCH list without paying close attention.
Even within the world of UNIX systems or the world of PCs, there is considerable diversity. For example, on a PC,
some versions of Windows (usually Windows NT) can remember the commands you typed earlier in a TROLL console
session, and you can repeat those commands by using the uparrow key. Other versions of Windows do not have this
feature for the console version, although the TROLL GUI makes a similar feature available to all Windows users. With
UNIX also, you will find different features in different brands.
Once you enter &DEDIT, you have several commands available. If you're entering a new series, the most important
command will be DATA, which begins the process of entering the series:
DEDIT
Value
Value
Value
Value
Command: data
for 1960A or ';':
for 1961A or ';':
for 1962A or ';':
for 1963A or ';':
1
2
3
4
When you say "ADD 1963A", this means, "Start adding data after 1963," so the first date to add is 1964. You can add
several data points at once:
Value for 1966A or ';': 7 8 9 10;
DEDIT Command: print data;
1960A:
1
2
1964A:
5
6
3
7
4
8
1968A:
10
(That works in the DATA command also.) You can use the keywords "TOP" and "BOTTOM" to add data to the beginning
or the end of the series. If you add data at the beginning or in the middle, it "pushes forward" the existing data for later
dates. For example:
DEDIT Command: add top 11 12 13 14;
DEDIT Command: print data;
1960A:
1964A:
1968A:
1972A:
11
1
5
9
12
2
6
10
13
3
7
*
14
4
8
*
14
4
8
1
5
9
2
6
10
3
7
*
To replace data without shifting the rest of the series, use REPLACE:
DEDIT
Date:
Value
Value
Value
Value
DEDIT
Command: replace
1960a
for 1960A or ';': 0
for 1961A or ';': 2317
for 1962A or ';': 1
for 1963A or ';': ;
Command: print data;
1960A:
0.000000e+000
1964A:
4
1968A:
8
DEDIT Command: quit ;
2317
5
9
1
6
10
3
7
*
[1]:
[5]:
[9]:
[13]:
9.7
7
5.5
6.1
9.6
6.2
6.7
5.6
Once you have an array, you can reshape it to a time series by specifying the starting date:
TROLL Command: do unemp = reshape(unemp, 1980a1);
TROLL Command: do prt.(unemp);
UNEMP:
UNEMP = RESHAPE(UNEMP,1980A)
1980A
1984A
1988A
1992A
:
:
:
:
1980A to 1995A
7.6
7.2
5.3
6.8
(16 observations)
9.7
7
5.5
6.1
9.6
6.2
6.7
5.6
In general, the RESHAPE function takes a data object (normally an array) as its first argument, followed by arguments that
tell how to reshape that array. The simplest new shape to specify is a "flat" time series (a time series with no space
dimension). As above, to specify a flat time series, you simply give the starting date for the series).
What if you want a different shape? The following statements produce a 3x3 matrix:
TROLL Command: do assetcorr = combine(1,.2,.3,.2,1,0,.3,0,1);
TROLL Command: do assetcorr = reshape(assetcorr, 3, 3);
TROLL Command: do prt.(assetcorr);
ASSETCORR:
ASSETCORR = RESHAPE(ASSETCORR,3,3)
Numeric array 2 space dimensions: 3 by 3
Space dimension number 2 >
1
0.2
0.2
1
0.3
0
[1,1]:
[2,1]:
[3,1]:
0.3
0
1
Note that in TROLL, when you RESHAPE an array, each column is completed before the next begins. (This columnbycolumn convention contrasts with the rowbyrow convention that is used in some other software.) The following
example illustrates:
TROLL Command: do m = 1::9 ;
TROLL Command: do prt.( m ) ;
M:
M = 1::9
Numeric array 1 space dimension: 9
[1]:
[5]:
[9]:
3
7
4
8
[1,1]:
[2,1]:
[3,1]:
7
8
9
Of course you can COMBINE and RESHAPE in the same statement. You can also abbreviate COMBINE as "C.". The previous
examples can be rewritten:
TROLL Command: do unemp=reshape(c.(7.1,7.6,9.7,9.6,7.5,7.2,7.0,
Continue eq: 6.2,5.5,5.3,5.5,6.7,7.4,6.8,6.1,5.6));
TROLL Command: do assetcorr=reshape(c.(1,.2,.3,.2,1,0,.3,0,1),3,3);
If you like more exotic shapes, how about an 4element yearbyyear array with one element for each quarter. In the
following example, the user lists the quarterly observations in chronological order, and TROLL organizes them into an
array of four timeseries, representing first quarter, second quarter, third quarter, and fourth quarter. (Note that an array of
timeseries is the same as a timeseries of arrays. By default, PRTDATA prints the data as "an array of timeseries"  with the
time dimension subordinate to the space dimension. The same data object could be printed as "a timeseries of arrays" with all elements for a given year grouped together. In fact, when you RESHAPE something, it is treated as "a timeseries
of arrays", with each time period completed before the next one begins. The example will illustrate.)
1990A
1994A
1990A
1994A
1990A
1994A
1990A
1994A
[1]:
[1]:
[2]:
[2]:
[3]:
[3]:
[4]:
[4]:
1990A to 1995A
(6 observations)
8.9
47.4
29
62
37.6
77.1
42.7
73.2
What? You'd like a plain timeseries of quarterly data after all? OK:
TROLL Command: do(prt.(reshape(usanx,1990q1)));
RESHAPE(USANX,1990Q1):
Numeric scalar timeseries Time dimension: Periodicity 4,
1990Q1
1991Q1
1992Q1
1993Q1
1994Q1
1995Q1
:
:
:
:
:
:
1990Q1 to 1995Q4
60.3
12.3
29
62
97.4
122.4
(24 observations)
78.5
22
37.6
77.1
108.4
100.6
72
14.8
42.7
73.2
99.7
NA
2. AREMOS TSD
Use an ACCESS statement with the "type
tsd"
parameter.
3. TSP LOAD
TROLL can read and write data in the form of a LOAD statement for TSP. This feature cannot actually be used
to read TSP data directly, and it may not be advisable for reading from TSP programs. (TROLL will be
particular about the format of the LOAD statement.) However, it may be useful for sharing data, and in
particular for exporting from TROLL to TSP. Use an ACCESS statement with the "type tspload" parameter.
B. TEXT DATA
There are several ways to read text data in TROLL.
a. NEWFORMAT
A NEWFORMAT object has the following structure:
header lines (2)
dimension lines (0 or more, depending on number of space dimensions)
optional comment lines (0 or more)
data lines (0 or more)
Each header line consists of a series of fields separated by spaces. (The exact number of spaces does not
matter.) The first header line has two fields and looks like this:
NAME: OBJECT_NAME
(This is a valid header line, not just a description.) The initial field contains the keyword NAME, which
must be capitalized, followed by a colon. The final field contains the name of the object, which also
should always be capitalized. In this case the object is called "OBJECT_NAME".
The second header line looks like this:
SPECS:
NUM 1960A 2 24 4 0
Again, this is a valid header line. The numbers are examples. SPECS is a keyword, which again must be
capitalized. NUM is short for NUMERIC, which, until TROLL 1.2, was the only data type allowed.
Schematically, the format of the line is:
SPECS:
(This is NOT a valid header line, just a syntax description.) For the most part, the field names should be
selfexplanatory: the data type; the starting date (NA for a constant, including constant arrays); the
number of space dimensions (0 for scalars, including scalar time series); the number of values; the
number of observations (1 for constants, including constant arrays); and the number of lines of comment.
If "ndims" is not zero, the header lines are followed by lines giving the sizes of the dimensions.
Continuing the example above:
NAME: OBJECT_NAME
SPECS: NUM 1960A 2 24 4 0
3
2
The object represented in this example is a timeseries of 3by2 matrices. Note that 24 = 4 * 3 * 2:
"nvals" is determined by "nobs" and the sizes of the space dimensions.
The dimension lines, if any, are followed by the comment lines, of which there are none in the present
example ("clines" is 0) and then the data lines. The number of data lines, and the locations of the
linebreaks among the data, are arbitrary: TROLL will read the data in order, going through each
observation columnbycolumn and then proceeding to the next observation. So if we choose the
example thus:
NAME: OBJECT_NAME
SPECS: NUM 1960A 2 24 4 0
3
2
1 2 3 4 5 6 7 8 9 10 11 12 13
14 15 16
17 18
19
20 21 22 23 24
the data object will contain four observations, the first a matrix of 1 through 6, the second of 7 through
12, and so on. If we put this object in a host system file called "matts.frm", TROLL will read it as
follows:
TROLL Command: access matts type formdata id matts.frm ;
TROLL Command: do prt. ( dflist( "matts" ) ) ;
DFLIST("matts"):
String scalar:
"OBJECT_NAME"
1960A[1,1]:
1960A[2,1]:
1960A[3,1]:
1961A[1,1]:
1961A[2,1]:
1961A[3,1]:
1962A[1,1]:
1962A[2,1]:
1962A[3,1]:
1963A[1,1]:
1963A[2,1]:
1963A[3,1]:
b. OLDFORMAT
...and OLDFORMAT looks like this:
header lines (2)
optional comment lines (0 or more)
data lines (1 or more)
Each header line consists of a series of fields separated by spaces. (The exact number of spaces does not
matter.) The first header line has six fields and looks like this:
USER: [whatever] [whatever]
DATAFILE: [whatever]
OBJECT_NAME
(This is a valid header line, not just a description.) TROLL uses the "whatever" fields when it stores
data, but you can ignore their content. For TROLL to read the header correctly, those fields must exist as
separate fields, but they can contain anything you want (except spaces, of course). "USER:" and
"DATAFILE:" are keywords that TROLL requires, but they have little meaning for data import. The final
field is the name of the object, which should always be capitalized. In this case the object is called
"OBJECT_NAME".
The second header line looks like this:
PER: 4
YEAR: 1990
FRAC: 2
NOBS: 12
CLINES: 0
DLINES: ???
(Again, this is a valid header line. The numbers here are examples.) PER, YEAR, FRAC, NOBS, CLINES, and
DLINES are keywords. "PER" refers to periodicity, in this case 4 (quarterly). "YEAR" is the year when the
series begins, in this case 1990. "FRAC" is the fraction (period) in which the series begins, in this case
fraction 2 (the second quarter). "NOBS" is the number of observations, in this case 12. "CLINES" is the
number of comment lines: in this case, the zero indicates that the data will begin immediately on the next
line. Finally, "DLINES" can specify the number of data lines. Since TROLL knows the number of
observations, it does not need to know the number of data lines, and "???" is an acceptable (and
customary) value.
In summary, these two header lines refer to a quarterly data series called OBJECT_NAME with twelve
observations beginning in 1990Q2, and no comment will be attached. The data lines normally consist of
data elements (usually numbers) separated by spaces. It does not matter how many data elements appear
on each line; TROLL will just keep reading until it counts NOBS observations. The entire FORMDATA object
might look like this:
USER: [whatever] [whatever] DATAFILE: [whatever] OBJECT_NAME
PER: 4
YEAR: 1990
FRAC: 2
NOBS: 12
CLINES: 0
DLINES: ???
1.2 2.33476 0
234568700956
9 9 3 3.1416 1 .00001
1.2e4
2
If we place this object in a host system file called "object.frm", we can see how TROLL interprets it:
TROLL Command: access that type formdata id object.frm;
TROLL Command: do prt.(dflist("that"));
DFLIST("that"):
String scalar:
"OBJECT_NAME"
1990Q2 to 1993Q1
(12 observations)
0
3
12000
2.34568701e+011
3.1416
2
As another example, here's a neater looking FORMDATA database, including some comments:
USER: x x DATAFILE: x USANX
PER: 4 YEAR: 1990 FRAC: 1 NOBS: 23 CLINES: 2 DLINES: ???
Except for this comment, this series is the same USANX
that we entered earlier using COMBINE and RESHAPE
74.3
60.3
78.5
72
32.9
12.3
22
14.8
8.9
29
37.6
42.7
47.4
62
77.1
73.2
80.3
97.4
108.4
99.7
106.6
122.4
100.6
USER: x x DATAFILE: x UNEMP
PER: 1 YEAR: 1980 FRAC: 1 NOBS: 16
CLINES: 1 DLINES: ???
...and this is the same UNEMP series from earlier
7.1
7.6
9.7
9.6
7.5
7.2
7
6.2
5.5
5.3
5.5
6.7
7.4
6.8
6.1
5.6
[1]:
1990Q1
1991Q1
1992Q1
1993Q1
1994Q1
1995Q1
1990Q1 to 1995Q3
60.3
12.3
29
62
97.4
122.4
78.5
22
37.6
77.1
108.4
100.6
(23 observations)
72
14.8
42.7
73.2
99.7
UNEMP:
...and this is the same UNEMP series from earlier
Numeric scalar timeseries Time dimension: Periodicity 1,
1980A
1984A
1988A
1992A
1980A to 1995A
7.6
7.2
5.3
6.8
9.7
7
5.5
6.1
(16 observations)
9.6
6.2
6.7
5.6
YEAR
1988
1989
1990
1991
1992
1993
1994
1995
DEFENSE
405.5
401.6
401.5
397.5
375.8
355.4
337.0
319.6
OTHRFED
119.1
130.1
140.5
142.0
152.2
153.8
152.6
152.3
STATLOC
656.6
682.6
708.6
718.7
735.8
751.8
770.5
788.6

In the next example, the data are quarterly and don't contain a "YEAR" column. &READXMAT can read the
following file ("usnipaq.txt") if you specify a start date using the "START" keyword:
GDP
6326.4
6356.5
6393.4
6469.1
6508.5
6587.6
6644.9
6693.9
6701.0
6713.5
6776.4
6780.7
6814.3
6892.6
6928.4
CONS
4289.7
4318.8
4359.5
4390.0
4420.5
4458.7
4489.4
4524.0
4534.8
4569.9
4597.3
4609.4
4649.1
4687.6
4693.5
NFI
577.5
586.4
593.1
617.6
628.5
639.5
660.5
679.7
704.4
710.5
719.0
723.3
743.5
750.5
781.4
RFI
237.9
234.8
242.2
255.8
263.6
271.6
270.3
270.3
265.9
256.5
262.2
266.3
271.1
281.5
277.8
DINV
18.5
20.8
19.5
17.4
40.5
74.5
64.5
56.1
54.5
30.5
33.0
14.6
3.0
7.1
34.5
NX
56.0
64.4
86.2
81.5
99.3
107.3
111.7
104.3
122.5
121.4
101.6
84.9
104.0
114.7
137.4
Suppose we want to read these data into an archive called "QNIP". (In other words, we want the variable names
prefixed with "QNIP_".) Using the keyword "ARCH", we can tell &READXMAT to use a particular archive (prefix).
The following call uses both the "START" and "ARCH" keywords:
TROLL Command: &readxmat start 1993q1 arch qnip usnipaq.txt;
TROLL Command: listsave;
SAVE Database:
DEFENSE
OTHRFED
QNIP_CONS
QNIP_DINV
QNIP_GDP
QNIP_NFI
QNIP_NX
QNIP_RFI
STATLOC

Numeric
Numeric
Numeric
Numeric
Numeric
Numeric
Numeric
Numeric
Numeric
scalar
scalar
scalar
scalar
scalar
scalar
scalar
scalar
scalar
timeseries
timeseries
timeseries
timeseries
timeseries
timeseries
timeseries
timeseries
timeseries
1993Q1
1994Q1
1995Q1
1996Q1
1993Q1 to 1996Q3
234.8
271.6
256.5
281.5
242.2
270.3
262.2
277.8
(15 observations)
255.8
270.3
266.3
&READXMAT can also read vectors without a time dimension. By default, &READXMAT treats the columns of a data
file without a "YEAR" column as vectors, as in:
TROLL Command: &readxmat usnipaq.txt;
TROLL Command: do prt.(rfi);
RFI:
Numeric array 1 space dimension: 15
[1]:
[5]:
[9]:
[13]:
242.2
270.3
262.2
277.8
255.8
270.3
266.3
If a file has a "YEAR" column but you want the data read as vectors rather than timeseries, you can override the
"YEAR" column by specifying "NA" with the "START" keyword. Then the "YEAR" column will be treated
simply as another column of data:
TROLL Command: &readxmat start na govspend.asc;
TROLL Command: do prt.(defense);
DEFENSE:
Numeric array 1 space dimension: 8
[1]:
[5]:
401.5
337
397.5
319.6
[1]:
[5]:
1990
1994
1991
1995
understands. If you are a beginning TROLL user without a computer programming background, you will
probably want to skip this section. Even if you are an experienced user with a strong programming background,
you may find it easier to reformat your data before reading it into TROLL. In particular, the subsequent section
on spreadsheet data may be more useful. (If you work at a large site using TROLL, someone may already have
developed TPL programs to deal with the particular type of data that you use.)
For the adventurous (and the desperate), TROLL does have facilities to read ASCII or binary data directly from
host system files. To do so, you would typically use the external file input and character string manipulation
functions, which are covered in detail in the Reference Manual. This Guide will give a quick overview of the
process (including the functions typically involved) and an example. This section will probably be more useful
to programmers than to endusers.
a. reading a file all at once
Reading a file all at once is easy using the XREAD function, which returns an array of strings
corresponding to the lines in the file. You can also write a file all at once with XWRITE.
b. reading linebyline and letterbyletter
Open a host system file using HFOPEN, which returns a file pointer. You can then read data using HFGETC
(read individual bytes) and HFGETS (read a line as a string). If you use HFGETC, you can convert the bytes
into an ASCII string with CODE2STR. If the string represents a number, you can use CONVERT to extract that
number. When you finish, close the file using HFCLOSE. If you lose track, you can get information about
open files using HFOGETFP (get file pointer), HFTELL (get current position within a file), and HFOLIST (list
open files). If you want to go directly to a specific location in a file, you can use HFSEEK.
The example use the text file "debt.doc":
Net Government Debt
USA Quarterly
1982
1 851.1
1982
2 875.4
1982
3 929.5
1982
4 983.5
1983
1 1035.7
1983
2 1098.4
1983
3 1142.8
1983
4 1168.6
1984
1 1217.8
1984
2 1262.2
1984
3 1314.8
1984
4 1365.9
1985
1 1410.3
1985
2 1467
1985
3 1513.4
1985
4 1588.1
(Note the "\n", representing a newline character at the end of the line.) Read the first three bytes of the
next line:
TROLL Command: do nextchars = hfgetc(debtptr, 3);
TROLL Command: do prt.(nextchars);
NEXTCHARS:
NEXTCHARS = HFGETC(DEBTPTR,3)
Numeric array 1 space dimension: 3
[1]:
65
" Quarterly\n"
Read the starting year and quarter from the first data line:
TROLL Command: do startyr = convert(code2str(hfgetc(debtptr,5)));
TROLL Command: do prt.(startyr);
STARTYR:
Numeric scalar:
1982
"
851.1\n"
"
851.1"
851.1
Command:
Command:
Command:
Command:
do
do
do
do
OBS2:
Numeric scalar:
875.4
[1]:
929.5
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
do
do
do
do
do
do
do
do
do
do
do
do
...and so on. Let's just finish up what we have. First convert the starting date information to an actual
date:
TROLL Command: do stdate = pyf2date(4, startyr, startqtr);
1982Q1 to 1983Q3
875.4
1098.4
929.5
1142.8
(7 observations)
983.5
[1,1]:
Before you actually try to import data in this way, you will probably want to read the next chapter (and
perhaps start reading the TROLL Programming Language Manual) to learn some TROLL Programming
techniques. You could then write a macro to read your data, rather than reading it interactively line by
line.
C. SPREADSHEET DATA
TROLL offers several ways to import data from spreadsheets. Generally, methods that read spreadsheets directly are
designed for standard PC spreadsheets and are not intended for use with spreadsheet programs that run in UNIX
environments.
PHILCURV.WKS
UE NHWI CPI
1992M1 7.1 58.2
138.1
7.3 60.2
138.6
7.3 63.1
139.3
7.3 60.1
139.5
7.4 61.9
139.7
7.7 61.9
140.2
7.6 59.9
140.5
7.6 61.8
140.9
7.5 60.8
141.3
7.4 60.7
141.8
7.3 64.5
142.0
7.3 63.4
141.9
7.1 64.3
142.6
7.0 65.1
143.1
7.0 64.1
143.6
7.0 64.0
144.0
6.9 65.7
144.2
7.0 64.6
144.4
The spreadsheet represented here contains three columns of data representing three separate, unbroken time
series over the same time period. To read the data into TROLL, invoke the &WKS2TS macro, and specify the name
of the spreadsheet and the names of the columns you want to read, separated by spaces. &WKS2TS will read a
column only if the name of that column appears both on the spreadsheet and in the argument list. The following
usage causes TROLL to read the "UE" and "CPI" columns and to ignore the "NHWI" column:
TROLL Command: &wks2ts philcurv.wks ue cpi;

7.3
7.7
7.4
7
6.9
CPI:
Numeric scalar timeseries Time dimension: Periodicity 12,
Time dimension >
1992M01:
138.125094
1992M05:
139.719722
1992M09:
141.305177
1993M01:
142.598535
1993M05:
144.197613
7.3
7.6
7.3
7
7.3
7.6
7.3
7
138.622344
140.222715
141.79975
143.098565
144.397951
139.32932
140.517184
141.998265
143.598056
139.524384
140.910631
141.89887
143.99755
The current version of &WKS2TS will read all series in the file if no series are specified, and it will store series
according to the current SEARCH list. The version included with TROLL releases before 1.093 is somewhat
different: all series must be specified explicitly, and it will store them in the SAVE database regardless of the
SEARCH list.
CONFIDEN.WKS
Col
Feb.
Mar.
Apr.
May
June
July
Row
1
CONSUMER
CONFIDENCE
2
3
1996
All series seasonally
adjusted
Jan.
Aug.
Sept.
Oct.
4
Composite Series: Index Numbers,
1985=100
5
6
7
Consumer Confidence
Index
88.4
Present Situation
101.1 110.8 110.0 118.2 120.2 114.7 125.0 129.5 128.5 124.6
Expectations
79.9
10
98.0
89.5
98.4
90.7
95.9
92.4
90.3
95.0
107.3
11
12
Business Conditions
13
Good
21.0
22.3
24.0
23.5
25.7
23.1
27.9
28.5
27.0
27.2
14
Bad
21.9
18.5
18.3
17.1
17.4
19.0
17.0
14.9
16.0
15.8
15
Normal
57.1
59.2
57.7
59.4
56.9
57.9
55.1
56.6
57.0
57.0
16
Employment
17
Jobs plentiful
21.3
21.8
22.5
23.0
24.8
24.6
26.5
27.0
26.4
25.4
18
52.4
54.8
51.3
55.6
52.4
51.8
51.1
51.1
53.2
52.2
19
26.3
23.4
26.2
21.4
22.8
23.6
22.4
21.9
20.4
22.4
There are three "blocks" of data in this spreadsheet. There are several different ways you might try to read it
using the WKS2MAT function. One possibility is to read the whole spreadsheet into a single matrix. That method
might be preferable if we wanted to retain all the information in the spreadsheet but didn't yet know how to use
it. However, it has one major disadvantage: since WKS2MAT cannot read both words and numbers in a single call,
we would have to read all the numbers as character strings.
A second possibility is to read individual rows (or columns) as separate matrices. That method might be
preferable if we wanted to treat each individual series separately.
Finally, we could read each of the blocks of data as a complete, distinct matrix. The example that follows uses
this last method. The following series of commands reads the matrices into TROLL:
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
do
do
do
do
ccindex=wks2mat("confiden.wks","b7..k9");
business=wks2mat("confiden.wks","b13..k15");
employment=wks2mat("confiden.wks","b17..k19");
prt.(ccindex,business,employment);
CCINDEX:
CCINDEX = WKS2MAT("confiden.wks","b7..k9")
Numeric array 2 space dimensions: 3 by 10
[1,1]:
[1,5]:
[1,9]:
[2,1]:
[2,5]:
[2,9]:
[3,1]:
[3,5]:
[3,9]:
98.400103
106.988086
104.8254
111.986724
109.955811
124.999103
118.16046
129.536122
90.696298
94.980741
95.935361
100.287126
BUSINESS:
BUSINESS = WKS2MAT("confiden.wks","b13..k15")
Numeric array 2 space dimensions: 3 by 10
[1,1]:
[1,5]:
[1,9]:
[2,1]:
[2,5]:
[2,9]:
[3,1]:
[3,5]:
[3,9]:
24
27.9
23.5
28.5
18.3
17
17.1
14.9
57.7
55.1
59.4
56.6
EMPLOYMENT:
EMPLOYMENT = WKS2MAT("confiden.wks","b17..k19")
Numeric array 2 space dimensions: 3 by 10
[1,1]:
[1,5]:
[1,9]:
[2,1]:
[2,5]:
22.5
26.5
23
27
51.3
51.1
55.6
51.1
[2,9]:
[3,1]:
[3,5]:
[3,9]:
53.2
26.3
22.8
20.4
52.2
23.4
23.6
22.4
26.2
22.4
21.4
21.9
Now we have all the data we need from the spreadsheet, but the data are organized as matrices without time
dimensions. Since the data represent time series, it makes sense to reshape the data into time series:
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
do
do
do
do
ccindex=reshape(ccindex,1996m1,3);
business=reshape(business,1996m1,3);
employment=reshape(employment,1996m1,3);
prt.(ccindex,business,employment);
CCINDEX:
CCINDEX = RESHAPE(CCINDEX,1996M01,3)
Numeric array timeseries Time dimension: Periodicity 12,
1 space dimension: 3
1996M01[1]:
1996M05[1]:
1996M09[1]:
1996M01[2]:
1996M05[2]:
1996M09[2]:
1996M01[3]:
1996M05[3]:
1996M09[3]:
1996M01 to 1996M10
98.001819
100.067504
107.284535
110.800497
114.713365
124.630621
89.469367
90.303597
95.720478
(10 observations)
98.400103
106.988086
104.8254
111.986724
109.955811
124.999103
118.16046
129.536122
90.696298
94.980741
95.935361
100.287126
BUSINESS:
BUSINESS = RESHAPE(BUSINESS,1996M01,3)
Numeric array timeseries Time dimension: Periodicity 12,
1 space dimension: 3
1996M01[1]:
1996M05[1]:
1996M09[1]:
1996M01[2]:
1996M05[2]:
1996M09[2]:
1996M01[3]:
1996M05[3]:
1996M09[3]:
1996M01 to 1996M10
22.3
23.1
27.2
18.5
19
15.8
59.2
57.9
57
(10 observations)
24
27.9
23.5
28.5
18.3
17
17.1
14.9
57.7
55.1
59.4
56.6
EMPLOYMENT:
EMPLOYMENT = RESHAPE(EMPLOYMENT,1996M01,3)
Numeric array timeseries Time dimension: Periodicity 12,
1 space dimension: 3
1996M01[1]:
1996M05[1]:
1996M09[1]:
1996M01[2]:
1996M05[2]:
1996M09[2]:
1996M01[3]:
1996M05[3]:
1996M09[3]:
1996M01 to 1996M10
21.8
24.6
25.4
54.8
51.8
52.2
23.4
23.6
22.4
(10 observations)
22.5
26.5
23
27
51.3
51.1
55.6
51.1
26.2
22.4
21.4
21.9
We now have three vector time series, each of which represents the variation of three pieces of information over
time. However, the information in the CCINDEX matrix is related in a way that is different from that of the
other two matrices. Consider the following:
TROLL Command: do empsum = sum(i=1 to 3: employment[i]);
TROLL Command: do bussum = sum(i=1 to 3: business[i]);
TROLL Command: do prt.(empsum,bussum);
EMPSUM:
EMPSUM = SUM(I = 1 TO 3: EMPLOYMENT[I])
Numeric scalar timeseries 
Time dimension:
Periodicity 12,
1996M01 to 1996M10
100
100
100
100
100
(10 observations)
100
100
BUSSUM:
BUSSUM = SUM(I = 1 TO 3: BUSINESS[I])
Numeric scalar timeseries Time dimension: Periodicity 12,
Time dimension >
1996M01:
100
1996M05:
100
1996M09:
100
1996M01 to 1996M10
100
100
100
100
100
(10 observations)
100
100
1996M01 to 1996M10
298.271682
305.084466
327.635634
299.052213
326.96793
(10 observations)
318.921221
341.809972
Both BUSINESS and EMPLOYMENT represent survey results in which respondents must fall into one of three
categories. For each observation, the results must sum to 100 percent. CCINDEX, on the other hand, simply
represents three sets of index numbers whose relationship is more complex. It makes sense to represent
BUSINESS and EMPLOYMENT as vector time series, but CCINDEX is different. Accordingly, the following
statements divides CCINDEX into three separate series:
TROLL Command: do arrsplit(ccindex, 1,, c.("overall","present","future"));
TROLL Command: do prt.(overall,present,future);
OVERALL:
Numeric scalar timeseries Time dimension: Periodicity 12,
Time dimension >
1996M01:
88.405725
1996M05:
103.538385
1996M09:
111.813456
98.001819
100.067504
107.284535
PRESENT:
Numeric scalar timeseries Time dimension: Periodicity 12,
Time dimension >
1996M01:
101.093095
1996M05:
120.232788
1996M09:
128.533105
98.400103
106.988086
1996M01 to 1996M10
110.800497
114.713365
124.630621
FUTURE:
Numeric scalar timeseries Time dimension: Periodicity 12,
Time dimension >
1996M01:
79.947478
1996M05:
92.408783
1996M09:
100.667023
1996M01 to 1996M10
109.955811
124.999103
1996M01 to 1996M10
89.469367
90.303597
95.720478
90.696298
94.980741
(10 observations)
104.8254
111.986724
(10 observations)
118.16046
129.536122
(10 observations)
95.935361
100.287126
When you read your own data, the following information about WKS2MAT may be useful:
You can use named ranges with WKS2MAT. For example, if you named a certain range "employment" in
the file "ccinamed.wks", you could read that range thus:
TROLL Command: do employment=wks2mat("ccinamed.wks","employment");
If you omit the range argument, WKS2MAT will read the entire active range in the spreadsheet.
You can read data as character strings by adding the argument "STR" after the range argument, as follows:
[1,1]:
[1,8]:
" May"
"June"
"July"
If the filename is unambiguous, you can omit the file extension (use "confiden" instead of
"confiden.wks").
3. "Save As Text"
In some cases, it may be more effective to convert a spreadsheet data to ASCII text and then read the text using
one of the methods discussed earlier.
4. Other Options?
As you might expect, importing data from spreadsheets is a common need among TROLL users. Many users
have come up with their own solutions, and some of these solutions are widely available. If the methods
described here are not to your liking, check with other TROLL users, consultants, distributors, and such to see if
a more appropriate method is available.
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
do
do
do
do
do
do
do
do
do
f = hfopen("integers.dat","rb");
byteoffset = 8*c.(0,1,2,3); // Offset of bytes in an integer
bytevals = 2**byteoffset; // Significance of each byte
bytes = hfgetc(f,4); // Read data for first integer
integer1 = total(bytevals*bytes); // Compute value
hfseek(f, 4, "Current"); // Skip second integer
bytes = hfgetc(f,4); // Read data for third integer
integer3 = total(bytevals*bytes); // Compute value
prt.(integer1, integer3);
INTEGER1:
Numeric scalar:
INTEGER3:
Numeric scalar:
files are humanreadable but relatively inefficient for use by TROLL. They are also portable across
platforms, so, for example, you can create a FORMDATA file on a PC and use it on a UNIX workstation. Normally,
the file extension .frm is used for FORMDATA files. The FORMDATA format is described in detail under Using
TROLL's FORMDATA Text Format in the section on Importing TEXT DATA.
2. TROLLDB
files are designed for efficient use by TROLL, but they are not human readable and not always portable
across platforms. Normally the file extension .trl is used for TROLLDB files.
TROLLDB
3. TESTBIN1
TESTBIN1
TESTBIN1
databases are compact and portable and thus convenient for archiving and transportation of data.
databases are not humanreadable. Normally the file extension .bin is used for TESTBIN1 files.
4. Special Formats
Some versions of TROLL support FAME files. All versions support AREMOS TSD files. In addition, some
TROLL sites have implemented sitespecific support for other database types.
Generally, you can distinguish between TROLL symbols (which TROLL automatically converts to capitals) and
TROLL strings (which TROLL does not convert). In the example above, the command do this=1 creates a symbol
called THIS. When you enter an ordinary command, TROLL converts this to THIS, and it recognizes the name. On the
other hand, "this" and "THIS" are string literals, and they do not get converted. GETDATA is peculiar in that it uses
strings as symbols, and it uses them without any changes. (This peculiar behavior can be useful occasionally when one
needs to access data that were not created by TROLL.)
There is nothing peculiar about the strings themselves. Strings can always contain either small or capital letters (or
both), and TROLL knows the difference:
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
do
do
do
do
capstring = "BEANS" ;
smallstring = "beans" ;
stringbeans = "beans" ;
prt.( stringbeans == capstring ) ;
STRINGBEANS == CAPSTRING:
Boolean scalar: FALSE
TROLL Command: do prt.( stringbeans == smallstring ) ;
STRINGBEANS == SMALLSTRING:
Boolean scalar: TRUE
TROLL Command: trexit ;
Another context in which strings are used as symbols, so that they must normally be capitalized, is in file access
functions used to access data files. For example, when we create a variable called x in the database temp, DFLIST can
find X but not x:
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
DFLIST("temp","x"):
String array 1 space dimension: 0
Space dimension number 1 >
TROLL Command: do prt.( dflist( "temp", "X" ) ) ;
DFLIST("temp","X"):
String scalar: "X"
Similar issues may arise with DFDELETE, DFRENAME, FLIST, FDELETE, and FRENAME.
Footnotes
1. Technically, on most systems, SAVE is in "virtual memory", not necessarily in "physical memory", but this is an issue handled by the host system. From TROLL's
point of view, all virtual memory is just "memory".
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
estimate;
threesls;
outlvl int 1;
estimate;
zellner;
outlvl int 1;
estimate;
C:\troll>rename eg2.txt eg2.inp
C:\troll>troll
TROLL Release 1.091
Copyright (C) Intex Solutions, Inc. 19931998
Copyright (C) Massachusetts Institute of Technology 19781987
CONS = A0+A1*(EXDEMAND+INVEST)
INVEST = B0+B1*(EXDEMAND+CONS)
CONS = A0+A1*(EXDEMAND+INVEST)
NOB = 27
NOVAR = 2 NCOEF = 2
RANGE: 1969A to 1995A
RSQ =
0.947023
F(1/25) =
446.903387
SER =
148.604555
DW(0) =
1.128891
MAX:HAT =
0.163032
DFFITS =
0.471296
COEF
A0
A1
ESTIMATE
1484.786935
2.779316
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.944904
0
552082.842861
13.746273
2.244192
TSTAT
197.604798
0.131471
PROB>T
7.513921
21.14009
INVEST = B0+B1*(EXDEMAND+CONS)
NOB = 27
NOVAR = 2 NCOEF = 2
RANGE: 1969A to 1995A
RSQ =
0.672506
F(1/25) =
51.337314
SER =
69.11211
DW(0) =
1.136274
MAX:HAT =
0.138467
DFFITS =
0.591527
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
0.659406
0
119412.093844
9.52663
1.837855
0
0
COEF
B0
B1
ESTIMATE
STER
217.329789
0.129394
TSTAT
64.053175
0.018059
PROB>T
3.392959
7.165006
0.002307
0
NEQ: 2
1658.948879
2.896423
286.031144
0.109593
STD ERR
210.524031
0.140305
66.267126
0.018721
CRSQ
0.945342
0.656757
SSR
0.943155
0.643027
569604.260897
125154.572678
SER
150.944263
70.754384
NEQ: 2
1658.948879
2.896423
286.031144
0.109593
FEVALMAX: 500
STD ERR
1.449408
0.000966
0.973607
0.000275
0.945342
0.656757
CRSQ
SSR
0.943155
0.643027
569604.260883
125154.572648
NEQ: 2
SER
150.944263
70.754384
1658.948879
2.896423
286.031144
0.109593
FEVALMAX: 500
STD ERR
210.520997
0.140302
66.286481
0.018728
CRSQ
0.945342
0.656757
0.943155
0.643027
SSR
569604.260883
125154.572648
SER
150.944263
70.754384
1484.786935
2.779316
217.329789
0.129394
FEVALMAX: 500
317.453518
STD ERR
1.329736
0.000885
0.926801
0.000261
0.947023
0.672506
CRSQ
0.944904
0.659406
SSR
552082.842861
119412.093844
SER
148.604555
69.11211
1537.085898
2.814482
184.572979
0.138835
STD ERR
187.189308
0.124499
60.698883
0.017101
FEVALMAX: 500
316.981119
CRSQ
0.946871
0.668926
SSR
0.944746
0.655683
553662.812995
120717.579224
SER
148.817044
69.488871
ZELLNER Command:
ZELLNER Command: trexit ;
Leaving TROLL...
This is essentially the same output produced in Chapter One, but this time the process is automatic. TROLL executes
each command in the file just as if you had entered the same thing directly from the keyboard.
For variety, the next passage uses a different file, the "simple Keynesian forwardlooking simulation" from Chapter
One, and it runs in a UNIX environment instead of Windows. This time we'll skip the "rename" and assume that the file
already has the .inp extension.
[20]% cat flkeynes.inp
usemod;
modedit;
addsym exogenous i;
addsym endogenous y c;
addeq bottom y=c+i;
addsym endogenous yperm;
addeq bottom c=.8*yperm;
addeq bottom yperm = .8*y + .2*y(+1);
print;
do y=exp(1+reshape(seq(21),1a)/10);
do c=.8*y;
do yperm=y;
do i=.2*y*(1+randnorm(1,2));
do prt.(i);
simulate stack 20;
list solutions y;
simstart 1a; dotil 20a;
[21]% troll flkeynes
TROLL Release 1.042
Copyright (C) Intex Solutions, Inc. 19931998
Copyright (C) Massachusetts Institute of Technology 19781987
TROLL Command: usemod;
New model: (nameless)
TROLL Command: modedit;
MODEDIT Command: addsym exogenous i;
MODEDIT Command: addsym endogenous y c;
MODEDIT Command: addeq bottom y=c+i;
MODEDIT Command: addsym endogenous yperm;
MODEDIT Command: addeq bottom c=.8*yperm;
MODEDIT Command: addeq bottom yperm = .8*y + .2*y(+1);
MODEDIT Command: print;
Symbols:
ENDOGENOUS :
C Y YPERM
EXOGENOUS :
I
Equations:
1:
2:
3:
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
Y = C+I
C = 0.8*YPERM
YPERM = 0.8*Y+0.2*Y(+1)
Command:
Command:
Command:
Command:
Command:
do
do
do
do
do
y=exp(1+reshape(seq(21),1a)/10);
c=.8*y;
yperm=y;
i=.2*y*(1+randnorm(1,2));
prt.(i);
I:
I = 0.2*Y*(1+RANDNORM(1,2))
Numeric scalar timeseries Time dimension: Periodicity 1,
1A to 21A
(21 observations)
1A
5A
9A
13A
17A
21A
:
:
:
:
:
:
0.35667
0.532089
0.793784
1.184186
1.766598
0.394181
0.588049
0.877267
1.308728
1.952393
0.435638
0.649895
0.969529
1.446368
2.157728
Notice that TROLL does not exit automatically. If you want TROLL to exit after executing an input file, you can end
the file with the command "trexit;". If you want to exit the particular task (in this case, the SIMULATE task), you can
end the file with the command "quit;". Since TROLL does not exit automatically, you can use an input file to set up
your TROLL environment.
For example, suppose you share the computer on which you run TROLL. Perhaps you use it during the day, and the
other user works at night. To avoid confusion, you keep your workspaces separate. Since you are not using the default
databases, you must make certain changes to the ACCESS and SEARCH lists whenever you enter TROLL. You could do this
by typing in the commands at the beginning of each TROLL session:
TROLL
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
Command:
Accessed Databases:
Alias
SAVE
.
TROLLSYS
MYDATA
MYDIR
DB Type
MEMDB
DISK
DISK
FORMDATA
DISK
R/W?
R/W
R/W
R
R/W
R/W
Filetype
DATA
ALL
ALL
DATA
ALL
W?
W
W
W
Filetype
DATA
DATA
NONDATA
ALL
NONDATA
Basic?
BASIC
BASIC
BASIC
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\sys\current
c:\troll\mydir\mydata.frm
c:\troll\mydir
...but why bother? Instead, put the commands in an input file and invoke the input file whenever you start TROLL:
C:\troll>type mysetup.inp
access mydata type formdata mode w id c:\troll\mydir\mydata.frm;
search after save mydata w;
access mydir type disk mode w id c:\troll\mydir;
search before trollsys mydir;
C:\troll>troll mysetup
TROLL Release 1.042
Copyright (C) Intex Solutions, Inc. 19931998
Copyright (C) Massachusetts Institute of Technology 19781987
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
Command:
Command:
access
search
access
search
lkaccess;
Accessed Databases:
Alias
SAVE
.
TROLLSYS
MYDATA
MYDIR
DB Type
MEMDB
DISK
DISK
FORMDATA
DISK
R/W?
R/W
R/W
R
R/W
R/W
Filetype
DATA
ALL
ALL
DATA
ALL
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\sys\current
c:\troll\mydir\mydata.frm
c:\troll\mydir
W?
W
W
W
Filetype
DATA
DATA
NONDATA
ALL
NONDATA
Basic?
BASIC
BASIC
BASIC
TROLL Command:
B. PROFILE FILES
As you might have surmised, there is an even easier way to run an input file automatically at TROLL startup: just name
the file "profile.inp". You can place the profile file either in the directory from which you start TROLL or in the
TROLL system directory (the TROLLSYS database, normally the directory into which TROLL was installed). (Obviously
you have to be careful if you're sharing a computer; perhaps you could arrange to start TROLL from different
directories with different profile files.) Whenever you want to change the way TROLL starts, simply change the
profile file. Proceeding from the previous example:
C:\troll>copy mysetup.inp profile.inp
1 file(s) copied.
C:\troll>troll
TROLL Release 1.042
Copyright (C) Intex Solutions, Inc. 19931998
Copyright (C) Massachusetts Institute of Technology 19781987
TROLL
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
Command:
access
search
access
search
trexit
If you prefer not to see all the commands every time, you can use the "SCREEN
command, as in the following profile file:
C:\troll>type profile.inp
sysopt screen off;
access mydata type formdata mode w id c:\troll\mydir\mydata.frm;
OFF"
Although you didn't see most of it, the profile ran, as you can verify:
TROLL Command: lkaccess;
Accessed Databases:
Alias
SAVE
.
TROLLSYS
MYDATA
MYDIR
DB Type
MEMDB
DISK
DISK
FORMDATA
DISK
R/W?
R/W
R/W
R
R/W
R/W
Filetype
DATA
ALL
ALL
DATA
ALL
Basic?
Fixed
Fixed
Fixed
ID
(none)
(none)
d:\troll\sys\current
c:\troll\mydir\mydata.frm
c:\troll\mydir
W?
W
W
W
Filetype
DATA
DATA
NONDATA
ALL
NONDATA
Basic?
BASIC
BASIC
BASIC
Naturally, you can use the "SCREEN OFF" option with any input file, not just with profile files. Furthermore, you can
turn the screen on and off during the course of an input file, so that you can verify important parts but ignore the dull
sections.
C. LOG FILES
Finally, a word about log files. You may have noticed that TROLL creates a file called troll.log during each session.
These files can be useful to refresh your memory, to document your results, or to diagnose problems. Log files can also
be useful to create input files from interactive sessions. That way you can reproduce the results without having to
remember everything you did. Since a log file normally contains all the commands you typed, you can just cut out
TROLL's responses and rename the log file with the ".inp" extension.
Normally TROLL overwrites the previous log file when you start a new TROLL session. To save an earlier troll.log
file, you must rename it before you start a new session. Alternatively, you can use different names for different log files.
To change the name of the log file, use "sysopt logfile". For example:
TROLL Command: sysopt logfile run5.log;
Now troll will record the rest of your session in run5.log instead of troll.log. Also, when you set a specific log file
this way, troll will not automatically overwrite the old log file. Instead, it will append the new log to the end of the old
one.
TROLL Command: trexit ;
the result and change the parameter values by hand, but that procedure could become quite tedious after a few repetitions.
Macros allow you to overcome some of the limitations of input files. Like an input file, a macro contains a sequence of
commands. There are several major differences:
TROLL processes macros differently, so you must use different syntax in a macro than you do in an interactive session
or an input file.
Macros can take "arguments", and you can specify argument values when you run a macro, without changing the macro
itself.
Macros can use "logic" statements (conditionals, loops, and so on) to make decisions and repeat sequences of steps
without additional input from the user.
When you write a macro, you must "compile" it before you can run it. You write "source code" that is humanreadable,
and the macro compiler coverts it to "object code" that only TROLL can read.
Macro files use the extensions .src (for source code) and .prg (for compiled object code).
The syntax differences between macros and input files are often quite simple. To show the most obvious differences, we will
convert flkeynes.inp into a macro. The first step is to rename the file with the .src extension:
C:\troll>rename flkeynes.inp flkeynes.src
(In a UNIX environment, you would probably use the "mv" command instead of "rename".) Now edit flkeynes.src using a text
editor (such as Notepad, KEdit, ex, vi, or the TROLL Editor). The necessary changes are almost trivial. First, add two
greaterthan signs (">>")at the beginning of each line, so the text becomes:
>>usemod;
>>modedit;
>>addsym exogenous i;
>>addsym endogenous y c;
>>addeq bottom y=c+i;
>>addsym endogenous yperm;
>>addeq bottom c=.8*yperm;
>>addeq bottom yperm = .8*y + .2*y(+1);
>>print;
>>do y=exp(1+reshape(seq(21),1a)/10);
>>do c=.8*y;
>>do yperm=y;
>>do i=.2*y*(1+randnorm(1,2));
>>do prt.(i);
>>simulate stack 20;
>>list solutions y;
>>simstart 1a; dotil 20a;
(To make these lines easier to read and edit in the future, you may prefer to put a space after the two greaterthan signs on each
line. The spaces will not affect TROLL's interpretation.) In TROLL macro terminology, a line beginning with two greaterthan
signs is called a "queueinput statement," and (in this context) it instructs TROLL to treat the remainder of the line as if it had
been typed from the keyboard. In other words, the queueinput statement in a macro behaves very much like an ordinary
statement in an input file. However, the compiler will not know how to process these statements by themselves. Before
processing these statements, the macro needs a formal introduction, which looks like this:
addfun main ;
procedure main()
begin;
These lines go at the top of flkeynes.src. If you prefer, you can substitute an opencurlybrace ("{") for "begin;". The first two
lines merely inform TROLL that this is a macro. The third line, "begin;" or "{" indicates the beginning of a "block". A block is
a sequence of statements to be executed together. In this case, the block is the entire macro. You must indicate the end of the
block with either and "end;" statement or a closecurlybrace ("}"). Thus the macro becomes:
addfun main ;
procedure main()
begin;
>>usemod;
>>modedit;
>>addsym exogenous i;
>>addsym endogenous y c;
>>addeq bottom y=c+i;
>>addsym endogenous yperm;
>>addeq bottom c=.8*yperm;
>>addeq bottom yperm = .8*y + .2*y(+1);
>>print;
>>do y=exp(1+reshape(seq(21),1a)/10);
>>do c=.8*y;
>>do yperm=y;
>>do i=.2*y*(1+randnorm(1,2));
>>do prt.(i);
>>simulate stack 20;
>>list solutions y;
>>simstart 1a; dotil 20a;
end;
You are now ready to compile the macro. (Note: the directory containing the source file must be on TROLL's SEARCH list.)
Compiling is easy: just start a TROLL session and type "compile" followed by the name of the source file (without the .src
extension):
C:\troll>troll
TROLL Release 1.042
Copyright (C) Intex Solutions, Inc. 19931998
Copyright (C) Massachusetts Institute of Technology 19781987
TROLL Command: compile flkeynes;
TROLL Compiler: Rel. 1.0
END OF COMPILATION
ERRORS:
0
WARNINGS: 0
Behind the scenes, TROLL has created an object file called flkeynes.prg, which contains the readytorun macro. You can run
the macro by typing the name preceded by an ampersand:
TROLL Command: &flkeynes;
New model: (nameless)
Symbols:
ENDOGENOUS :
C Y YPERM
EXOGENOUS :
I
Equations:
1:
2:
3:
Y = C+I
C = 0.8*YPERM
YPERM = 0.8*Y+0.2*Y(+1)
I:
I = 0.2*Y*(1+RANDNORM(1,2))
Numeric scalar timeseries Time dimension: Periodicity 1,
1A
5A
9A
13A
17A
21A
1A to 21A
0.35667
0.532089
0.793784
1.184186
1.766598
(21 observations)
0.394181
0.588049
0.877267
1.308728
1.952393
0.435638
0.649895
0.969529
1.446368
2.157728
[12A]
[13A]
[14A]
[15A]
[16A]
[17A]
[18A]
[19A]
[20A]
5.299193
5.863624
6.496306
7.215526
8.055384
9.084814
10.450307
12.471954
15.859444
SIMULATE Command:
The GET statement causes the macro to store the value obtained from the user in the specified "macro variable", in this case mpc.
The value can then be retrieved by using the "ampersand" syntax:
>>addeq bottom c=&mpc*yperm;
The new statement allows the user to substitute values different from .8 by providing an argument to the macro. For
consistency, we'll also use the user's argument to compute starting values for "c", so the macro becomes:
addfun main ;
procedure main()
begin;
get mpc; // Get "marginal propensity to consume" from user
>>usemod;
>>modedit;
>>addsym exogenous i;
>>addsym endogenous y c;
>>addeq bottom y=c+i;
>>addsym endogenous yperm;
>>addeq bottom c=&mpc*yperm; // Simple consumption function
>>addeq bottom yperm = .8*y + .2*y(+1);
>>print;
>>do y=exp(1+reshape(seq(21),1a)/10);
>>do c=&mpc*y; // Compute starting values for "c"
>>do yperm=y;
>>do i=.2*y*(1+randnorm(1,2));
>>do prt.(i);
>>simulate stack 20;
>>list solutions y;
>>simstart 1a; dotil 20a;
end;
To distinguish this from the original FLKEYNES, we'll rename it "flusempc.src". Now watch:
TROLL Command: compile flusempc;
TROLL Compiler: Rel. 1.0
END OF COMPILATION
ERRORS:
0
WARNINGS: 0
TROLL Command: &flusempc .8;
New model: (nameless)
Symbols:
ENDOGENOUS :
C Y YPERM
EXOGENOUS :
I
Equations:
1:
2:
3:
Y = C+I
C = 0.8*YPERM
YPERM = 0.8*Y+0.2*Y(+1)
I:
I = 0.2*Y*(1+RANDNORM(1,2))
Numeric scalar timeseries Time dimension: Periodicity 1,
1A
5A
9A
13A
17A
21A
1A to 21A
0.35667
0.532089
0.793784
1.184186
1.766598
(21 observations)
0.394181
0.588049
0.877267
1.308728
1.952393
0.435638
0.649895
0.969529
1.446368
2.157728
Y = C+I
C = 0.99*YPERM
YPERM = 0.8*Y+0.2*Y(+1)
I:
I = 0.2*Y*(1+RANDNORM(1,2))
Numeric scalar timeseries Time dimension: Periodicity 1,
1A
5A
9A
13A
17A
21A
1A to 21A
0.35667
0.532089
0.793784
1.184186
1.766598
(21 observations)
0.394181
0.588049
0.877267
1.308728
1.952393
0.435638
0.649895
0.969529
1.446368
2.157728
Y = C+I
C = 0.5*YPERM
YPERM = 0.8*Y+0.2*Y(+1)
I:
I = 0.2*Y*(1+RANDNORM(1,2))
Numeric scalar timeseries Time dimension: Periodicity 1,
1A
5A
9A
13A
17A
21A
1A to 21A
0.35667
0.532089
0.793784
1.184186
1.766598
(21 observations)
0.394181
0.588049
0.877267
1.308728
1.952393
0.435638
0.649895
0.969529
1.446368
2.157728
This macro follows FLUSEMPC wordforword until the line that says, "Loop through stack sizes." That line is followed by a "for
loop" that tells TROLL, "Start with nstack equal to 2; then repeat the following block as long as nstack is less than 21; and
after each repetition, add one to nstack." This loop illustrates another application of the "block" concept: the statements
between "// start loop block" and "// end loop block" are executed together. When you think about how the loop works,
you can think of this block as a "black box" that gets executed for each repetition of the loop.
Inside that black box, the macro does some calculations using macro variables. With TROLL's MODULO function, it computes the
modulus (remainder) from dividing 20 by nstack, and it assigns that modulus to the variable modv. Then it takes action based on
the value of modv.
The meaning of the "ifthenelse" structure should be clear: if modv is zero (that is, if nstack goes evenly into 20), then execute
the "if block"; otherwise, execute the "else block".
The content of the "if block" should be familiar: those queueinput statements are taken directly from FLUSEMPC, except that the
number 20 has been replaced by "&nstack". "&nstack" should remind you of "&mpc": the "ampersand" syntax is the same,
because both are examples of macro variables in queueinput statements. The difference is where the variables got their values:
mpc got its value from the user (outside the macro); nstack got its value from the "for" statement (inside the macro).
The "else block" illustrates another aspect of macro programming: you don't have to do everything with queueinput
statements!! The one statement in the "else block" is an ordinary "expression statement", much like an expression that you
might type into an interactive TROLL session. It calls the PRINT function with ordinary arguments. Notice that there are no
ampersands: since the statement is executed strictly within the macro (rather than passing information to the command line), it
doesn't need ampersands. It's just as if nstack and modv were ordinary TROLL variables in an ordinary TROLL session, except
that this "virtual TROLL session" takes place within a macro.
Okay, let 'er rip.
TROLL Command: compile flstacks;
Y = C+I
C = 0.7*YPERM
YPERM = 0.8*Y+0.2*Y(+1)
I:
I = 0.2*Y*(1+RANDNORM(1,2))
Numeric scalar timeseries Time dimension: Periodicity 1,
1A
5A
9A
13A
17A
21A
1A to 21A
0.35667
0.532089
0.793784
1.184186
1.766598
(21 observations)
0.394181
0.588049
0.877267
1.308728
1.952393
0.435638
0.649895
0.969529
1.446368
2.157728
17A
Solution:
Y [17A]
5.745128
[18A]
6.638375
[19A]
8.244909
[20A]
11.966911
Constructing stackedtime incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
Date:
What:
Value:
1A
Solution: Y [1A]
1.141354
[2A]
1.281911
[3A]
1.481222
[4A]
1.839688
[5A]
2.670179
6A
Solution: Y [6A]
1.881775
[7A]
2.113515
[8A]
2.442122
[9A]
3.033133
[10A]
4.40238
11A
Solution: Y [11A]
3.102523
[12A]
3.484596
[13A]
4.026378
[14A]
5.00079
[15A]
7.258298
16A
Solution: Y [16A]
5.115195
[17A]
5.745128
[18A]
6.638375
[19A]
8.244909
[20A]
11.966911
Ignoring nstack = 6: modulus is 2
Ignoring nstack = 7: modulus is 6
Ignoring nstack = 8: modulus is 4
Ignoring nstack = 9: modulus is 2
Constructing stackedtime incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
Date:
What:
Value:
1A
Solution: Y [1A]
1.131338
[2A]
1.250433
[3A]
1.382289
[4A]
1.528755
[5A]
1.69296
[6A]
1.881775
[7A]
2.113515
[8A]
2.442122
[9A]
3.033133
[10A]
4.40238
11A
Solution: Y [11A]
3.075297
[12A]
3.399028
[13A]
3.75745
[14A]
4.155587
[15A]
4.601944
[16A]
5.115195
[17A]
5.745128
[18A]
6.638375
[19A]
8.244909
[20A]
11.966911
Ignoring nstack = 11: modulus is 9
Ignoring nstack = 12: modulus is 8
Ignoring nstack = 13: modulus is 7
Ignoring nstack = 14: modulus is 6
Ignoring nstack = 15: modulus is 5
Ignoring nstack = 16: modulus is 4
Ignoring nstack = 17: modulus is 3
Ignoring nstack = 18: modulus is 2
Ignoring nstack = 19: modulus is 1
Constructing stackedtime incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
Date:
What:
Value:
1A
Solution: Y [1A]
1.131284
[2A]
1.250262
[3A]
1.381754
[4A]
1.527074
[5A]
1.687678
[6A]
1.865173
[7A]
2.061336
[8A]
2.278131
[9A]
2.517734
[10A]
2.782557
[11A]
3.075297
[12A]
3.399028
[13A]
3.75745
[14A]
4.155587
[15A]
4.601944
[16A]
5.115195
[17A]
5.745128
[18A]
[19A]
[20A]
6.638375
8.244909
11.966911
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
II. DO COMMANDS
III. THE TROLL MODELLING LANGUAGE
IV. BUILTIN FUNCTIONS
The usual way around this limitation is to use the CONVERT function, which usually performs the most obvious
conversion by default:
TROLL Command: do prt.( x  convert( y ) ) ;
XCONVERT(Y):
String scalar:
"12"
There are two notable exceptions, where direct mixing of datatypes is appropriate. The first is mixing of dates and
numbers (for addition and subtraction), wherein the numbers are interpreted in accordance with the periodicity of the
dates:
TROLL Command: do prt.( 2000m1 + 7  3 ) ;
2000M01+73:
Date scalar: 2000M05
The other exception is when one of the datatypes is the NA type. Usually the NA datatype is created when you specify a
literal NA. If you then use the NA in conjunction with another datatype, TROLL will normally convert the NA to the
appropriate type:
TROLL Command: do natype = na ;
TROLL Command: do prt.( natype, natype+1, natype"string", natype OR TRUE ) ;
NATYPE:
NA scalar:
NA
NATYPE+1:
Numeric scalar:
NATYPE"string":
String scalar:
NATYPE OR TRUE:
Boolean scalar:
NA
NA
TRUE
10
COLVEC:
COLVEC = SEQ(3)
Numeric array 1 space dimension: 3
[1]:
SCALAR+COLVEC:
Numeric array 1 space dimension: 3
[1]:
13
A more complicated example involves combining a column vector and a row vector. In this case, each of the vectors is
replicated along the dimension of the other:
TROLL Command: do rowvec = transp( seq( 4 ) ), prt.( rowvec ) ;
ROWVEC:
ROWVEC = TRANSP(SEQ(4))
Numeric array 2 space dimensions: 1 by 4
[1,1]:
[1,1]:
[2,1]:
[3,1]:
31
32
33
41
42
43
The example above actually involves two instances of conformation: first, the scalar 10 is conformed with the row
vector, and then the result is conformed with the column vector. You might not notice the first instance, because it
corresponds to the standard algebraic process of multiplying a vector by a scalar. The following example involves
multiple conformation for addition:
TROLL Command: do prt.( 100*colvec + scalar + rowvec ) ;
100*COLVEC+SCALAR+ROWVEC:
Numeric array 2 space dimensions: 3 by 4
[1,1]:
[2,1]:
[3,1]:
113
213
313
114
214
314
The process of conforming a constant and a timeseries is similar to that for a scalar and a vector:
TROLL Command: do series = reshape( seq( 5 ), 2000m1 ), constant = 10 ;
TROLL Command: do prt.( constant, series, constant + series ) ;
CONSTANT:
Numeric scalar:
10
SERIES:
SERIES = RESHAPE(SEQ(5),2000M01)
Numeric scalar timeseries Time dimension: Periodicity 12,
2000M01:
2000M05:
CONSTANT+SERIES:
Numeric scalar timeseries Time dimension: Periodicity 12,
2000M01:
2000M05:
12
13
14
TROLL can also conform a scalar timeseries with a constant row vector and a constant column vector to produce a
matrix timeseries:
TROLL Command: do prt.( 100*colvec + 10*rowvec + series ) ;
100*COLVEC+10*ROWVEC+SERIES:
Numeric array timeseries Time dimension: Periodicity 12,
2 space dimensions: 3 by 4
2000M01[1,1]:
2000M01[2,1]:
2000M01[3,1]:
2000M02[1,1]:
131
231
331
132
141
241
341
142
2000M02[2,1]:
2000M02[3,1]:
2000M03[1,1]:
2000M03[2,1]:
2000M03[3,1]:
2000M04[1,1]:
2000M04[2,1]:
2000M04[3,1]:
2000M05[1,1]:
2000M05[2,1]:
2000M05[3,1]:
212
312
113
213
313
114
214
314
115
215
315
222
322
123
223
323
124
224
324
125
225
325
232
332
133
233
333
134
234
334
135
235
335
242
342
143
243
343
144
244
344
145
245
345
The process of conforming timeseries to one another is straightforward, but if the series do not overlap, the result will be
empty:
TROLL Command: do series2 = reshape( seq(3), 2000m8 ) ;
TROLL Command: do prt.( series2, series + series2 ) ;
SERIES2:
SERIES2 = RESHAPE(SEQ(3),2000M08)
Numeric scalar timeseries Time dimension: Periodicity 12,
2000M08:
SERIES+SERIES2:
Numeric scalar timeseries Time dimension: Periodicity 12,
In the above example, a feasible conformation produces an empty result. When the conformation is not feasible, there is
no result at all:
TROLL Command: do annual = reshape( seq( 4 ), 1999a ), prt.( annual ) ;
ANNUAL:
ANNUAL = RESHAPE(SEQ(4),1999A)
Numeric scalar timeseries Time dimension: Periodicity 1,
1999A:
The examples so far have used numeric data, but of course the same rules apply to other datatypes:
TROLL Command: do firstnames = c.( "John", "Jane" ) ;
TROLL Command: do lastnames = transp( c.( "Smith", "Jones" ) ) ;
TROLL Command: do prt.( firstnames, lastnames, firstnames  " "  lastnames ) ;
FIRSTNAMES:
FIRSTNAMES = C.("John","Jane")
String array 1 space dimension: 2
Space dimension number 1 >
[1]: "John" "Jane"
LASTNAMES:
LASTNAMES = TRANSP(C.("Smith","Jones"))
String array 2 space dimensions: 1 by 2
Space dimension number 2 >
[1,1]: "Smith" "Jones"
FIRSTNAMES" "LASTNAMES:
String array 2 space dimensions: 2 by 2
Space dimension number 2 >
[1,1]: "John Smith" "John Jones"
[2,1]: "Jane Smith" "Jane Jones"
II. DO COMMANDS
To perform arithmetic operations and other transformations on data during a TROLL session, you will typically use the "DO"
commands. The most obvious "DO" command is the generic DO command, specified with the word "DO" followed by a
modelling language expression. The generic DO command has been used extensively in examples thus far. When you create or
modify data using the generic DO command, the SEARCH list determines where TROLL stores the resulting data object: as per its
default, TROLL stores the new or revised data object in the first datawritable database on the current SEARCH list (see the
discussion of "ACCESS and SEARCH" in Chapter Three).
What if you want to control where TROLL stores the object without changing the SEARCH list? Even with the generic DO
command, you have considerable control, because you can refer to the target object by a multilevel name (a name containing
an underscore). As explained in Chapter Three, the first level of the name can refer to an archive within the first datawritable
database on the SEARCH list. That technique gives you explicit control over the write location.
TROLL provides an alternative option, if you want to make sure that your new data either does or does not replace existing data
(or create new data) in a permanent database. The DOFILE command instructs TROLL to store the object in the first permanent
datawritable database on the SEARCH list. ("Permanent" means located on a nonvolatile medium such as a hard disk, rather than
in RAM.) Using the DOFILE command, you can ensure that resulting data are "filed" in a "permanent" location.
Alternatively, you may want to avoid overwriting permanently stored data, or you may want to avoid the relatively slow access
speeds for permanent media. If so, you can use the DOSAVE command, which stores its results in the SAVE database.
Both DOFILE and DOSAVE use the same syntax as the DO command. All three (DO, DOFILE, and DOSAVE) are "utility commands" that
can be used anywhere in a TROLL session without exiting from the current task or entering a new task.
Finally, there is the DOCORE command. DOCORE causes TROLL to enter a "DO task" in which it can do temporary calculations and
store the results "very temporarily"  that is, only for the remainder of the DO task. During the DO task, you can use DOSAVE or
DOFILE to save a result to a more permanent location. See the section on "Calculations" in Chapter Two.
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
2. Analysis Information
a. SYMTAB
b. LKSYM
c. LKXREF
d. LKORD
D. CHANGING MODELS
1. Changing Symbols
a. CHANGESYM: changing symboltypes
b. RENAMESYM: changing symbolnames
c. DELSYM: deleting symbols
d. ADDSYM: adding symbols
2. Changing Equations
a. CHANGEQ: editing an equation
b. REPEQ: replacing equations
c. DELEQ: removing equations
d. ADDEQ: adding equations
3. Changing Analysis
a. RENORM:
2. Declaring Symbols
Before discussing other symboltypes, let us look at the mechanics of model specification. To start specifying a
model, invoke the modelediting task ("MODEDIT"). By default MODEDIT edits a copy of the "current" model.
Before invoking MODEDIT you can use the USEMOD command (without an argument) to clear any existing model
from the workspace.
TROLL Command: usemod;
New model: (nameless)
TROLL Command: modedit;
MODEDIT Command:
As an example, consider the following simple Keynesian model with a forward looking financial sector and a
backwardlooking real sector:
Real Sector:
Financial Sector:
Phillips Curve:
where
Y
r
G
p
=
=
=
=
In this model, G is the only exogenous variable; Y, r, and p are endogenous; and the a's, b's, and c's are
coefficients. We declare the symbols using the ADDSYM command:
MODEDIT Command: addsym exogenous g ;
MODEDIT Command: addsym endogenous y r p ;
MODEDIT Command: addsym coefficient a0 a1 a2 a3 b0 b1 b2 c0 c1 c2 c3 ;
3. Specifying Equations
Now we're ready for the equations. TROLL requires you to specify an order for the equations, by using a
positionspecifier in the ADDEQ command. Typically, we add equations at the bottom:
MODEDIT Command: addeq bottom y = a0  a1*r(1) + a2*r(2) + a3*g ;
MODEDIT Command: addeq bottom r = b0 + b1*r(1) + b2*p(+1) ;
MODEDIT Command: addeq bottom p = c0 + c1*p(1) + c2*y(1) + c3*y(2) ;
B0
B1
B2
C0
C1
C2
C3
Equations:
1:
2:
3:
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*P(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
Y = A0A1*R(1)+A2*R(2)+A3*G
NOB = 24
NOVAR = 4 NCOEF = 4
RANGE: 1973A to 1996A
RSQ =
0.574338
F(3/20) =
8.995207
SER =
1.502501
DW(0) =
1.634555
MAX:HAT =
0.39338
DFFITS =
1.13398
COEF
A0
A1
A2
A3
ESTIMATE
2.437701
0.905111
0.603706
0.388469
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.510489
0.000566
45.150199
11.600635
2.201904
TSTAT
0.921934
0.188103
0.191515
0.203275
PROB>T
2.644117
4.811775
3.152258
1.911054
0.015564
0.000106
0.005013
0.070437
R = B0+B1*R(1)+B2*P(+1)
NOB = 24
NOVAR = 3 NCOEF = 3
RANGE: 1973A to 1996A
RSQ =
0.733003
F(2/21) =
28.826316
SER =
1.417157
DW(0) =
1.459242
MAX:HAT =
0.349474
DFFITS =
1.247669
COEF
B0
B1
B2
ESTIMATE
0.094675
0.73251
0.365853
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.707575
0
42.175025
7.081209
2.815043
TSTAT
0.97642
0.111071
0.11264
PROB>T
0.096962
0.923676
6.594949 1.55796154e006
3.247981
0.003849
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
NOB = 24
NOVAR = 4 NCOEF = 4
RANGE: 1973A to 1996A
RSQ =
0.821551
F(3/20) =
30.692242
SER =
1.167584
DW(0) =
1.631293
MAX:HAT =
0.316478
DFFITS =
1.412367
COEF
C0
C1
C2
C3
ESTIMATE
1.123889
1.100438
0.266039
0.250203
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.812004
0.124288
0.13715
0.120049
0.794783
0
27.265067
6.947931
2.492358
TSTAT
1.384093
8.853968
1.939769
2.084171
PROB>T
0.181582
0
0.066642
0.050179
[2007A]
[2008A]
[2009A]
[2010A]
[2011A]
[2012A]
[2013A]
[2014A]
[2015A]
Y [1996A]
[1997A]
[1998A]
[1999A]
[2000A]
[2001A]
[2002A]
[2003A]
[2004A]
[2005A]
[2006A]
[2007A]
[2008A]
[2009A]
[2010A]
[2011A]
[2012A]
[2013A]
[2014A]
[2015A]
R [1996A]
[1997A]
[1998A]
[1999A]
[2000A]
[2001A]
[2002A]
[2003A]
[2004A]
[2005A]
[2006A]
[2007A]
[2008A]
[2009A]
[2010A]
[2011A]
[2012A]
[2013A]
[2014A]
[2015A]
P [1996A]
[1997A]
[1998A]
[1999A]
[2000A]
[2001A]
[2002A]
[2003A]
[2004A]
[2005A]
[2006A]
[2007A]
[2008A]
[2009A]
[2010A]
[2011A]
[2012A]
[2013A]
[2014A]
[2015A]
2
2
2
2
2
2
2
2
2
0.42631
1.944598
2.050101
2.02676
1.982351
1.93007
1.874426
1.818283
1.763627
1.711794
1.663624
1.619585
1.579869
1.544467
1.513234
1.485933
1.462267
1.441915
1.424539
1.40981
5.091678
4.682755
4.435793
4.320135
4.300753
4.349303
4.443715
4.567073
4.706619
4.852916
4.999151
5.14057
5.27401
5.39752
5.510065
5.611278
5.701273
5.780497
5.849612
5.294206
2.879321
2.586348
2.34623
2.489944
2.668279
2.846872
3.018382
3.179233
3.327382
3.461823
3.582303
3.689099
3.782853
3.864438
3.934862
3.995193
4.046505
4.089845
4.126201
4.156495
"fixed" (that is, different values will often appear in different runs of the same model). Unlike a COEFFICIENT, a
PARAMETER changes according to the user's instructions rather than the outcome of a TROLL estimation task.
Suppose, for example, that you want to look at the effects of the assumption about forwardlooking behavior in
the financial sector in the model presented above. As heretofore described, the model makes the specific
assumption that any inflationsensitivity in the financial sector will be forwardlooking. To vary that assumption,
you could use a PARAMETER ("k") in the second equation:
Financial Sector:
(For simplicity, this formulation ignores the contemporaneous inflation rate.) To change the TROLL model, you
have to add a symbol and revise the equation. Adding the symbol is straightforward:
SIMULATE Command: addsym parameter k ;
(This is really a MODEDIT command, not a SIMULATE command, but as usual TROLL knows that it has to enter a
new task.)
2. Changing Equations
Having added the symbol, you now have a choice of how to change the equation. The most straightforward way
would be to delete the old equation ("deleq 2;") and then add the new one. In this case, though, there's a
quicker (albeit uglier) way:
MODEDIT Command: changeq /b2*p(+1)/ b2 * (k*p(1) + (1k)*p(+1)) /
2 ;
Since the first part of equation 2 is unchanged, it need not be deleted. CHANGEQ changes only the section cited
between the initial pair of delimiters (slashes, in this case). By the way, "changeq / b2*p(+1)/..." wouldn't
work, because TROLL eliminated the space before "b2" when it first read the equation (as shown in response to
the PRINT command). Here is what the model looks like now:
MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
P R Y
EXOGENOUS :
G
COEFFICIENT :
A0 A1 A2 A3
B0
B1
B2
C0
C1
C2
C3
PARAMETER :
K
Equations:
1:
2:
3:
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*(K*P(1)+(1K)*P(+1))
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
Setting k in this way ensures that a value will exist, and the new value will supersede any data object that
happens to have the name k in a database further down on the SEARCH list. (You still have to be careful, though, if
there is a readSEARCHable database before the first writeSEARCHable one. The DO statement writes to the first
writeSEARCHable database on the SEARCH list, but the model will use the first k that it finds, which might be in a
nonwriteSEARCHable database.)
Since equations 1 and 3 are unchanged, there is no need to reestimate them. Thus,
MODEDIT Command: olsmod 2 ;
ORDINARY LEAST SQUARES
2 :
R = B0+B1*R(1)+B2*(K*P(1)+(1K)*P(+1))
NOB = 24
NOVAR = 3 NCOEF = 3
RANGE: 1973A to 1996A
RSQ =
0.687409
F(2/21) =
23.090217
SER =
1.533392
DW(0) =
1.358704
MAX:HAT =
0.34085
DFFITS =
1.118524
COEF
ESTIMATE
B0
B1
B2
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.67363
0.651496
0.354904
0.657638
0
49.377124
6.792331
2.429851
TSTAT
1.003463
0.127834
0.145526
PROB>T
0.671305
0.509344
5.096439 4.77353786e005
2.438773
0.023703
You can compare this with the earlier result (equivalent to K=0) and try other parameter values, if you like. You
can use the same command sequence as before to run a simulation. (Remember to SAVECOEF after estimating if
you want to use the new coefficients!)
B0
B1
B2
C0
C1
C2
C3
PARAMETER :
K
FUNCTION :
LOG
Equations:
1:
2:
3:
Y = A0A1*LOG(R(1))+A2*LOG(R(2))+A3*G
R = B0+B1*R(1)+B2*(K*P(1)+(1K)*P(+1))
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
By changing the functional form, we've introduced a new symbol into the model. "LOG" is a symbol. Because
LOG is a builtin function, TROLL recognizes it and places it in the model's symbol table under symboltype
"FUNCTION".
Since the model is still linear in the coefficients, TROLL can still estimate it by OLS:
MODEDIT Command: olsmod 1 ;
ORDINARY LEAST SQUARES
1 :
Y = A0A1*LOG(R(1))+A2*LOG(R(2))+A3*G
NOB = 24
NOVAR = 4
NCOEF = 4
ESTIMATE
A0
A1
A2
A3
5.032798
6.022286
3.408574
0.518747
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
1.759515
1.352156
1.349559
0.213584
0.478986
0.001033
48.05588
20.470351
2.609839
TSTAT
2.860332
4.453839
2.525695
2.428778
PROB>T
0.009672
0.000244
0.020098
0.024703
TROLL can work transparently with the LOG function, because TROLL knows how to differentiate LOG. Thus,
there is no problem with using logs in either an estimation or a simulation. TROLL accepts the following
functions in simulations and (where appropriate) in estimations:
ABSV
SIGN
MIN
MAX
MINARG
MAXARG
SELECT
LOG
LOG10
EXP
SQRT
PNORM
SIN
COS
TAN
COTAN
ARCSIN
ARCCOS
ARCTAN
ARCCOT
ROUND
ROUNDUP
TRUNCATE
FLOOR
CEILING
Technically, a model can contain any valid function, including userdefined functions (which must be declared
as symbols). In practice, functions other than those listed above may not be very useful in models, since TROLL
will not be able to simulate models containing such other functions.
B0
B1
B2
C0
C1
C2
C3
PARAMETER :
K
FUNCTION :
LOG
Equations:
1:
2:
3:
Y = A0A1*LOG(R(1))+A2*LOG(R(2))+A3*G
R = B0+B1*R(1)+B2*(K*P(1)+(1K)*P(+1))
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
COEFFICIENT
'D
DEFINITION
'N
ENDOGENOUS
'X
EXOGENOUS
'F
FUNCTION
'P
PARAMETER
'POL
POLICY
B0
B1
B2
C0
C1
C2
C3
PARAMETER :
K
FUNCTION :
LOG
Equations:
1:
2:
3:
Y = A0A1*LOG(R(1))+A2*LOG(R(2))+A3*G
R = B0+B1*R(1)+B2*(K*P(1)+(1K)*P(+1))
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
B0
B1
B2
C0
C1
C2
C3
Equations:
1:
2:
3:
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*P(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
Note that G does not need any declaratory suffix (type abbreviation) in this version, since it defaults to the correct
symboltype. Also note that each symbol need only be declared once: subsequent references to the symbol inherit the
declared symboltype.
symboltype
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
EXOGENOUS
A0
COEFFICIENT
A1
COEFFICIENT
A2
COEFFICIENT
A3
COEFFICIENT
B0
COEFFICIENT
B1
COEFFICIENT
B2
COEFFICIENT
C0
COEFFICIENT
C1
COEFFICIENT
C2
COEFFICIENT
C3
COEFFICIENT
Equations
number
specification
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*P(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
This rudimentary model file contains all the information that TROLL needs about the model when the model is
created. TROLL can access symbols unambiguously by symbolname; it can access equations unambiguously by
number; and it can access the model file unambiguously by name.
Command:
Command:
Command:
Command:
Equations:
1:
2:
3: PC
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*P(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
C3
COEFFICIENT :
A0 A1 A2 A3
B0
B1
B2
OK.
iii. adding labels and changing equations
To demonstrate ways of adding labels to existing equations, we'll label the other equations. First,
we label the real sector equation "IS" (as per its traditional Keynesian appellation).
MODEDIT Command: changeq /y/is: y/ 1 ;
MODEDIT Command: print eq 1 ;
Equations:
1: IS
Y = A0A1*R(1)+A2*R(2)+A3*G
In this case, CHANGEQ is the quickest way to add a label, but generally CHANGEQ must be used with
caution. Although (as above) it can add a label by modifying the beginning of the equation with
the standard labelinclusion syntax, CHANGEQ cannot see existing equation labels. Therefore, you
cannot use CHANGEQ to delete an existing label. You might use REPEQ ("replace equation").
Unfortunately, you have to retype the whole equation. The following command uses REPEQ to add
a label to the financial sector equation (equation 2):
MODEDIT Command: repeq 2 finance: r = b0 + b1*r(1) + b2*(+1) ;
MODEDIT Command: print eq finance ;
Equations:
2: FINANCE
R = B0+B1*R(1)+B2*(+1)
Note that TROLL can now retrieve the equation by its label.
b. comments
i. model comments
It's easy to add a comment to a model. Just use MODCOM:
MODEDIT Command: modcom Simple Keynesian Model with FL Finance ;
MODEDIT Command: print ;
Simple Keynesian Model with FL Finance
Symbols:
ENDOGENOUS :
P R Y
EXOGENOUS :
G
COEFFICIENT :
A0 A1 A2 A3
B0
B1
B2
C0
C1
C2
C3
Equations:
1: IS
2: FINANCE
3: PC
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
It's a little harder to change a comment once you've added it. Strictly speaking, you can't
"change" an existing comment, but you can replace it by issuing a new MODCOM command:
MODEDIT Command: modcom Simple Model to Demonstrate Model Creation in TROLL ;
MODEDIT Command: print ;
Simple Model to Demonstrate Model Creation in TROLL
Symbols:
ENDOGENOUS :
P R Y
EXOGENOUS :
G
COEFFICIENT :
A0 A1 A2 A3
B0
B1
B2
C0
C1
C2
C3
Equations:
1: IS
2: FINANCE
3: PC
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
B0
B1
B2
C0
C1
C2
C3
Equations:
1: IS
2: FINANCE
3: PC
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
Multiline comments are perfectly acceptable. Just wait until the end of the comment before
typing the semicolon:
MODEDIT
Comment
Comment
Comment
MODEDIT
Command: modcom
or ';': Simple Keynesian Model with ForwardLooking Financial Sector
or ';': Used to Demonstrate Model Creation in TROLL
or ';': ;
Command: print ;
B0
B1
B2
C0
C1
C2
C3
Equations:
1: IS
2: FINANCE
3: PC
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
Command:
Command:
Command:
Command:
Command:
B0
B1
B2
C0
C1
C2
C3
Equations:
1: IS
2: FINANCE
3: PC
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
Command:
Command:
Command:
Command:
eqcom
eqcom
eqcom
print
is Real Sector ;
finance Financial Sector ;
pc Phillips Curve ;
com equations all ;
Equations:
Real Sector
1: IS
Y = A0A1*R(1)+A2*R(2)+A3*G
Financial Sector
2: FINANCE R = B0+B1*R(1)+B2*(+1)
Phillips Curve
3: PC
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
By default, when printing a model, TROLL includes the model comment but not equation and
symbol comments. The keyword COM (or COMMENT) in the examples above requests comments to
be printed.
LKSYM
tells which symbols appear in which equations, but it does not give lag/lead information:
Used in Equations
1
1
1
1
2
2
2
3
3
3
3
1
3
1
1
2
3
displays a set of symbols  by default, the ENDOGENOUS and DEFINITION variables (collectively
called "endogenous" with a small E). For each variable, it tells which equation(s) include that variable
without a lag:
LKXREF
P
R
Y
3
2
1
b. block ordering
In preparation for simulation, TROLL "normalizes" a model and divides it into "blocks" of simultaneous
equations. Normalization simply means pairing equations with endogenous (ENDOGENOUS or DEFINITION)
variables. (The pairing may be arbitrary when some endogenous variables appear unlagged in more than
one equation.) TROLL divides the normalized model into the smallest possible blocks of equations that
must be solved simultaneously. This process is called "block ordering", and the resulting list of blocks
represents the block ordering of the model. LKORD displays information about the model's block ordering:
TROLL Command: lkord all ;
Analyzing Model's Block Structure
The model has 3 blocks, including 0 simultaneous blocks.
The largest block has 1 equation and the next largest has 1.
Block
Size
Eqn
Var
c. simulation code
Simulation code consists of the symbolic partial derivatives of each equation with respect to each current
endogenous variable in the equation's block. TROLL appends this information to the model file for its
own use. The derivatives are used in the simulation process. As long as TROLL can produce the
simulation code successfully, the details of it need not concern the user.
B0
B1
B2
C0
C1
C2
C3
Equations:
Real Sector
1: IS
Y = A0A1*R(1)+A2*R(2)+A3*G
Financial Sector
2: FINANCE R = B0+B1*R(1)+B2*(+1)
Phillips Curve
3: PC
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
Here you don't see the model analysis information added by TROLL. That's not considered "part of the model",
but it is included in the model file. In terms of the schematic representation used earlier, the complete model file
looks like this:
symboltype
comment
ENDOGENOUS
Inflation Rate
ENDOGENOUS
ENDOGENOUS
EXOGENOUS
A0
COEFFICIENT
(none)
A1
COEFFICIENT
(none)
A2
COEFFICIENT
(none)
A3
COEFFICIENT
(none)
B0
COEFFICIENT
(none)
B1
COEFFICIENT
(none)
B2
COEFFICIENT
(none)
C0
COEFFICIENT
(none)
C1
COEFFICIENT
(none)
C2
COEFFICIENT
(none)
C3
COEFFICIENT
(none)
Equations
number
label
specification
comment
IS
Y=
A0A1*R(1)+A2*R(2)+A3*G
Real Sector
FINANCE
R = B0+B1*R(1)+B2*P(+1)
Financial Sector
PC
P=
Phillips Curve
C0+C1*P(1)+C2*Y(1)+C3*Y(2)
Incidence Matrix
estimate the whole model at once, you might first want to engage in exploratory estimation of individual equations or
sets of equations to help you decide on a specification and/or an estimation technique. You might want to estimate some
equations that aren't even in the model to help you with a partly subjective calibration process, or to help you decide on
a specification and/or estimation technique for the whole model.
And surely you won't want to simulate a model just once. You'll simulate, shock the variables, and simulate again. You
might use simulation as part of the estimation process: specify a tentative model; estimate it on a truncated sample;
simulate using historical data; and modify the specification according to the results.
Even in the imaginary simple case where you just want to estimate, simulate, and be done with it, the odds are you can't.
Your initial specification might not be possible to estimate using your initially chosen technique. You might get strangelooking results and have to figure out why. You might not be satisfied with the default simulation parameters. Someone
else might look at your method or your results and convince you that your initial choices didn't make any sense.
The practice of using models therefore involves much of the following activities:
cut
paste
truncate
combine
calibrate
shock
adjust
revise
respecify
find data
examine results
examine structure
examine parts in isolation
investigate possibilities
think
change your mind
fix something that doesn't work
try something that might not work
revert
repeat with modifications
repeat with different data
save a tentative version
work with several tentative versions
ask for comments
respond to comments
delegate
The remainder of this chapter will discuss the facilities TROLL has to help you with these activities.
B. GETTING INFORMATION
Whatever you do with your models, you will often want to check the content or structure of a model. Especially if you
model interactively, it is wise to check often to make sure the model looks the way you intended it.
1. Specification Information
There are two commands that give information about the content of a model. If you're in the process of editing
or simulating a model, you can get information about it with the PRINT command. Information from the PRINT
command incorporates the effects of your edits. If you're not editing or simulating a model, if you want to know
about a different model, or if you want to recall what the model looked like before you started editing, you can
use the PRTMOD command. Both commands offer various options that allow you to choose what parts of the
model to display and how.
a. PRINT
is a lowlevel command in the MODEDIT and SIMULATE tasks. It displays information specific to the
current task. This chapter has already presented numerous examples of the generic use of PRINT: by
default, PRINT lists all the symbols, all the equations, and the model comment (if any). You can also use
PRINT
in a more specific way; for example, to list all the ENDOGENOUS variables, along with their
comments:
PRINT
(By default, PRINT does not print comments, except for the model comment.) To list equations specified
either by position or by label:
MODEDIT Command: print equations top pc ;
Equations:
1: IS
3: PC
Y = A0A1*R(1)+A2*R(2)+A3*G
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
Y'N = A0'CA1'C*R'N(1)+A2'C*R'N(2)+A3'C*G'X
R'N = B0'C+B1'C*R'N(1)+B2'C*(+1)
P'N = C0'C+C1'C*P'N(1)+C2'C*Y'N(1)+C3'C*Y'N(2)
To list a specific set of symbols (in this case using the asterisk as a "wild card character"):
MODEDIT Command: print symbols b* ;
Symbols:
COEFFICIENT :
B0 B1 B2
See the Reference Manual, Sections 5.12 and 5.1.6, for the syntax of the PRINT command.
b. PRTMOD
The syntax of PRTMOD is very similar to that of PRINT. The difference is in where the information comes
from. PRTMOD can give information about any existing model file, including (and defaulting to) the
"CURRENT" model, but not including the temporary buffer model reported by PRINT. (If you are using
MODEDIT and have not made any edits, then the buffer model will be the same as the model you are
editing.) The following example demonstrates:
MODEDIT Command: filemod previous ; // Start by saving our model as "PREVIOUS"
TROLL Command: addeq bottom new: x = 1 ; // Add a new equation
MODEDIT Command: docore 1 ; // Exit to another (arbitrary) task
DO Command:
// causing MODEDIT to save model as "CURRENT"
DO Command: quit ;
TROLL Command: addeq bottom newer: y = 1 ; // Add yet another equation
MODEDIT Command: print ; // Prints buffer with both new equations
B0
B1
B2
C0
C1
C2
C3
Equations:
1:
2:
3:
4:
5:
IS
FINANCE
PC
NEW
NEWER
Y
R
P
X
Y
=
=
=
=
=
A0A1*R(1)+A2*R(2)+A3*G
B0+B1*R(1)+B2*(+1)
C0+C1*P(1)+C2*Y(1)+C3*Y(2)
1
1
B0
B1
B2
C0
C1
C2
C3
Equations:
1:
2:
3:
4:
IS
FINANCE
PC
NEW
Y
R
P
X
=
=
=
=
A0A1*R(1)+A2*R(2)+A3*G
B0+B1*R(1)+B2*(+1)
C0+C1*P(1)+C2*Y(1)+C3*Y(2)
1
B0
B1
B2
C0
C1
C2
C3
Equations:
1: IS
2: FINANCE
3: PC
Y = A0A1*R(1)+A2*R(2)+A3*G
R = B0+B1*R(1)+B2*(+1)
P = C0+C1*P(1)+C2*Y(1)+C3*Y(2)
2. Analysis Information
The contents of a model may be difficult to interpret without some analysis. Large models especially may be
hard for the mind to swallow whole. Although the primary purpose of TROLL's model analysis is to prepare a
model for simulation, the model analysis commands can also help you understand how a model works. Certainly
they can help you anticipate simulation problems and choose simulation methods and parameters.
At this point we'll leave the simple, canned example and go to something more representative of realworld
modelling: the Japanese submodel from the IMF's Mark II Multimod model. Here it is:
TROLL Command: usemod models_multj ;
PARAMETER :
CE87 EE87 FE87 GE87 IE87 JBETA JDUMCT JE87 JK87 JL87
JRHO JRPREM JY87 RE87 SE87 T2 TAU1 TAU2 TRDE TRDER
FUNCTION :
EXP LOG
Equations:
1: JC
2: JCOIL
3: JK
4: JINV
5: JXM
6: JXA
7: JXT
8: JIM
9: JIOIL
10: JIC
11:
12:
13:
14:
JIT
JA
JGDP
JGNP
15: JW
16: JWH
17: JWK
18: JYD
19: JGE
20: JTAX
21: JTAXK
22: JTAXH
23: JTRATE
24: JB
25: JGDEF
26: JM
27: JRS
28: JRL
29:
30:
31:
32:
JR
JRLR
JRSR
JPGNP
33: JPNO
34: JP
35: JPFM
36: JPXM
37: JPXT
38: JPIM
39: JPIMA
40: JPIT
41: JYCAP
42:
43:
44:
45:
JBETA
JLF
JCU
JNFA
46:
47:
48:
49:
50:
JTB
JCAB
JER
JREER
JMERM
51: JFA
JA_TRATE(1))+RES_JA_TRATE
DEL(1: JA_B)+DEL(1: JA_M) = JA_R*JA_B(1)+JA_P*JA_GJA_TAX+
JA_GEXOG+RES_JA_B*JA_P
JA_GDEF = DEL(1: JA_B+JA_M)
LOG(JA_M/JA_P) = JM0+JM1*LOG(JA_A)+JM2*JA_RS+JM4*LOG(JA_M(1)/
JA_P(1))+RES_JA_M
DEL(1: JA_RS)JR3*(JA_RS(1)JA_RS(1)) = JR1*LOG(JA_MT/JA_M)/JM2+
RES_JA_RS
JA_RL/100 = ((1+JA_RS/100)*(1+JA_RS(1)/100)*(1+JA_RS(2)/100)*(1+
JA_RS(3)/100)*(1+JA_RS(4)/100))**0.21+RES_JA_RL
JA_R = 0.5*JA_RS(1)/100+0.5*SUM(I = 3 TO 1: JA_RL(I)/100)/3
JA_RLR = (1+JA_RL/100)/(JA_P(5)/JA_P)**0.21
JA_RSR = (1+JA_RS/100)/(JA_P(1)/JA_P)1
DEL(1: LOG(JA_PGNPNO)) = DEL(1: LOG(JA_PGNPNO(1)))JP3*DEL(1:
LOG(JA_PGNPNO(1)/JA_PGNPNO(1)))+JP1*(JA_CU/1001)+JP2*DEL(1:
LOG(JA_P/JA_PGNPNO))+RES_JA_PGNP
JA_PGNPNO = (JA_GDP*JA_PGNPJA_PRODOIL*POIL/JA_ER*JE87)/(JA_GDPJA_PRODOIL)
JA_PGNP = (JA_P*JA_A+JA_XT*JA_PXTJA_IT*JA_PIT)/JA_GDP+RES_JA_P*
JA_PGNP
LOG(JA_PFM) = 0.5*(W21*LOG(US_PXM*US_ER/UE87)+L21*LOG(US_PGNPNO*
US_ER/UE87)+W22*LOG(JA_ER/JE87)+1*LOG(JA_ER/JE87)+W23*LOG(
GR_PXM*GR_ER/GE87)+L23*LOG(GR_PGNPNO*GR_ER/GE87)+W24*LOG(CA_PXM*
CA_ER/CE87)+L24*LOG(CA_PGNPNO*CA_ER/CE87)+W25*LOG(FR_PXM*FR_ER/
FE87)+L25*LOG(FR_PGNPNO*FR_ER/FE87)+W26*LOG(IT_PXM*IT_ER/IE87)+
L26*LOG(IT_PGNPNO*IT_ER/IE87)+W27*LOG(UK_PXM*UK_ER/EE87)+L27*LOG
(UK_PGNPNO*UK_ER/EE87)+W28*LOG(SI_PXM*SI_ER/SE87)+L28*LOG(
SI_PGNPNO*SI_ER/SE87)+W29*LOG(RW_PXM*RW_ER/RE87)+L29*LOG(DC_PGNP
*RW_ER/RE87))
DEL(1: LOG(JA_PXM)) = JPXM0+JPXM1*DEL(1: LOG(JA_PGNPNO))+(1JPXM1
)*DEL(1: LOG(JA_PFM))+JPXM2*LOG(JA_PGNPNO(1)/JA_PXM(1))+
RES_JA_PXM
JA_PXT = (JA_XMA*JA_PXM+POIL/JA_ER*JE87*JA_XOIL)/JA_XT
JA_PIM = (S12*US_PXM+S22*JA_PXM*JA_ER/JE87+S32*GR_PXM*GR_ER/GE87+
S42*CA_PXM*CA_ER/CE87+S52*FR_PXM*FR_ER/FE87+S62*IT_PXM*IT_ER/
IE87+S72*UK_PXM*UK_ER/EE87+S82*SI_PXM*SI_ER/SE87+S92*RW_PXM*
RW_ER/RE87)/(JA_ER/JE87)*(1+RES_JA_PIM)
JA_PIMA = JA_PIM+T2*(WTRADETRDE)/JA_ER/JA_IM
JA_PIT = (JA_IM*JA_PIMA+JA_IOIL*POIL/JA_ER*JE87+JA_ICOM*PCOM/
JA_ER*JE87)/JA_IT
JA_YCAP = JY87*(JBETA*(JA_K/JK87)**(JRHO)+(1JBETA)*((1+JPROD)**
(T21)*(1+RES_JA_YCAP/(1JBETA))*JA_LF/JL87)**(JRHO))**(1/JRHO
)
JA_BETA = JBETA*(JA_YCAP/JA_K/(JY87/JK87))**JRHO
JA_LF = JA_POP*JA_PART/(1+JA_DEM3)
JA_CU = 100*JA_GDP/JA_YCAP
DEL(1: JA_NFA) = (JA_XT*JA_PXTJA_IT*JA_PIT)*JA_ER+US_R*(JA_NFA(1)+JA_NFAADJ(1))+RES_JA_NFA
JA_TB = JA_XT*JA_PXTJA_IT*JA_PIT
JA_CURBAL = DEL(1: JA_NFA)
1+US_RS/100 = (1+JA_RS/100)*JA_ER(1)/JA_ER+RES_JA_ER
JA_REER = LOG(JA_PXM)LOG(JA_PFM)
JA_MERM = EXP(LOG(JA_ER/JE87)(+V23*LOG(GR_ER/GE87)+V24*LOG(CA_ER
/CE87)+V25*LOG(FR_ER/FE87)+V26*LOG(IT_ER/IE87)+V27*LOG(UK_ER/
EE87)+V28*LOG(SI_ER/SE87)))
JA_FA = (US_A*UE87)**L21*(JA_A*JE87)**L22*(GR_A*GE87)**L23*(CA_A*
CE87)**L24*(FR_A*FE87)**L25*(IT_A*IE87)**L26*(UK_A*EE87)**L27*(
SI_A*SE87)**L28*((HO_A+DC_A)*RE87)**L29/JE87
One way to try understanding this model is to go through the equations onebyone and figure out what each one
means and how they interrelate. (Try that with the 466 equations in the full Multimod!) Another way to
approach the model is focus directly on some important aspects of the model as a whole. For example...
a. SYMTAB
Suppose you want to know how forwardlooking behavior enters into the model. Rather than look
through all the equations and pick out those that seem to model forwardlooking behavior, you can use
the SYMTAB command to find the variables with positive leads. Thus:
TROLL Command:
Horizon:
Min
Max
1
0
1
0
0
0
1
0
1
0
0
0
0
0
symtab endogenous ;
Symboltype
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
Symbolname
JA_A
JA_B
JA_BETA
JA_C
JA_COIL
JA_CU
JA_CURBAL
1
1
0
1
0
0
1
1
0
0
0
2
0
1
0
1
1
1
1
2
0
1
0
1
0
0
1
3
0
1
0
0
0
0
0
1
1
0
1
1
1
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
5
0
0
1
0
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
1
1
0
0
0
0
0
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
JA_ER
JA_FA
JA_GDEF
JA_GDP
JA_GE
JA_GNP
JA_ICOM
JA_IM
JA_INVEST
JA_IOIL
JA_IT
JA_K
JA_LF
JA_M
JA_MERM
JA_NFA
JA_P
JA_PFM
JA_PGNP
JA_PGNPNO
JA_PIM
JA_PIMA
JA_PIT
JA_PXM
JA_PXT
JA_R
JA_REER
JA_RL
JA_RLR
JA_RS
JA_RSR
JA_TAX
JA_TAXH
JA_TAXK
JA_TB
JA_TRATE
JA_W
JA_WH
JA_WK
JA_XM
JA_XMA
JA_XT
JA_YCAP
JA_YD
A quick look reveals that only six of the endogenous variables have positive maximum leads. Excerpted
for reference:
1
1
2
1
0
1
1
5
1
4
1
1
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
JA_ER
JA_P
JA_PGNPNO
JA_RS
JA_WH
JA_WK
JA_ER,
the exchange rate; JA_P and JA_PGNPNO, price indexes; JA_RS, the shortterm interest rate; JA_WH,
human wealth; and JA_WK, capital wealth: any forwardlooking behavior in the model must operate
through anticipation of these variables.
But where do these variables show up in the model?
b. LKSYM
TROLL can tell us immediately which equations contain those variables. The LKSYM command exists for
just that purpose:
TROLL Command: lksym ja_er ja_p ja_pgnpno ja_rs ja_wh ja_wk ;
Variable
JA_ER
JA_P
JA_PGNPNO
JA_RS
JA_WH
JA_WK
Used in Equations
2
15
8
26
15
3
10
16
32
27
16
15
14
17
33
28
15
18
36
29
16
17
33
19
35
20
31
48
37
24
38
26
39
30
40
31
45
32
48
34
50
LOG(JA_M/JA_P) = JM0+JM1*LOG(JA_A)+JM2*JA_RS+JM4*LOG(JA_M(1)/
JA_P(1))+RES_JA_M
DEL(1: JA_RS)JR3*(JA_RS(1)JA_RS(1)) = JR1*LOG(JA_MT/JA_M)/JM2+
RES_JA_RS
JA_RL/100 = ((1+JA_RS/100)*(1+JA_RS(1)/100)*(1+JA_RS(2)/100)*(1+
JA_RS(3)/100)*(1+JA_RS(4)/100))**0.21+RES_JA_RL
JA_R = 0.5*JA_RS(1)/100+0.5*SUM(I = 3 TO 1: JA_RL(I)/100)/3
JA_RSR = (1+JA_RS/100)/(JA_P(1)/JA_P)1
1+US_RS/100 = (1+JA_RS/100)*JA_ER(1)/JA_ER+RES_JA_ER
This vein turns out to be a particularly rich one. The JRS and JRL equations both contain leads of JA_RS.
As a bonus, the JRSR equation contains a lead of JA_P, and the JER equation contains a lead of JA_ER. Not
a bad place to start if you want to study forwardlooking behavior in this model!
c. LKXREF
Lags or leads might be a starting place for a user trying to understand part of a model, but for TROLL,
contemporaneous variables are the starting place. By looking at contemporaneous endogenous variables,
TROLL can determine which equations it will have to solve simultaneously during simulation. (There is
no need to solve for lagged variables, since they are predetermined, and the presence of endogenous
leads only requires replication of the contemporaneous equation structure.) To begin anticipating the
simulation process, it is helpful to see which equations contain which contemporaneous endogenous
variables. Here's an example:
TROLL Command: lkxref all ;
Variable
JA_A
JA_B
JA_BETA
JA_C
JA_COIL
JA_CU
JA_CURBAL
JA_ER
JA_FA
JA_GDEF
JA_GDP
JA_GE
JA_GNP
JA_ICOM
JA_IM
JA_INVEST
JA_IOIL
JA_IT
JA_K
JA_LF
JA_M
JA_MERM
JA_NFA
JA_P
JA_PFM
JA_PGNP
JA_PGNPNO
JA_PIM
JA_PIMA
JA_PIT
JA_PXM
JA_PXT
JA_R
JA_REER
JA_RL
JA_RLR
JA_RS
JA_RSR
JA_TAX
JA_TAXH
JA_TAXK
JA_TB
JA_TRATE
JA_W
12
23
17
12
9
44
13
24
21
26
25
42
34
51
10
51
14
15
33
35
37
38
39
40
45
10
13
14
16
17
18
21
33
34
44
20
11
11
12
11
13
4
43
24
23
40
39
40
40
34
17
40
41
45
42
46
25
26
27
45
16
36
10
32
39
39
40
37
37
20
49
30
30
27
31
20
22
21
47
17
49
14
33
18
19
20
24
26
30
31
32
16
36
17
18
20
21
23
33
34
23
40
45
38
45
24
46
49
46
29
28
31
48
21
22
24
22
48
34
50
JA_WH
JA_WK
JA_XM
JA_XMA
JA_XT
JA_YCAP
JA_YD
15
3
5
6
7
41
1
16
15
6
7
13
42
18
16
17
8
34
44
37
37
45
46
d. LKORD
A model can be partitioned into blocks of equations, such that each block can be solved separately. In
TROLL, this process is called "block ordering". To prepare for block ordering, TROLL "normalizes" the
model by forming a onetoone association between endogenous variables and equations. TROLL then
divides the model into blocks and specifies an order in which the blocks can be solved.
To see the process, consider an ultrasimple model:
TROLL Command: usemod ;
New model: (nameless)
TROLL Command: addsym endogenous w x y z ;
MODEDIT Command: addeq bottom x = 2*y, x = y + 1,
MODEDIT Command: print ;
z = x,
w = 1  w ;
Symbols:
ENDOGENOUS :
W X Y Z
Equations:
1:
2:
3:
4:
X
X
Z
W
=
=
=
=
2*Y
Y+1
X
1W
Clearly, equations 1 and 2 cannot be solved separately. However, once 1 and 2 are solved, 3 can be
solved separately using the value of X. Equation 4 can be solved either before or after the rest.
Note that the first two equations can be solved in two different ways: you can plug X from equation 1 into
equation 2 and solve for Y, or you can plug X from equation 2 into equation 1 and solve for Y. This is a
difference of "normalization". Under the first alternative, you normalize by associating X with equation 1
and Y with equation 2. Under the second alternative, you do the reverse. The two normalizations will
produce the same solution, but one may be easier than the other. Similarly, a difference in normalization
should never cause TROLL to find a different solution to a model, but the difference may affect how
quickly the solution arrives or what possible problems are encountered along the way.
Although the normalization is ambiguous, the block structure is not. Any valid block ordering will place
equations 1 and 2 in the same block and will require that block to be solved before equation 3. (Equation
4 can be solved at any time, but the solution process will not depend on when it is solved, so the choice
is really cosmetic rather than structural.) Like this one, any valid TROLL model will have a unique
block structure. The LKORD command can display both the (arbitrary) normalization and the (unique)
block structure:
MODEDIT Command: lkord all ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
The model has 3 blocks, including 1 simultaneous block.
The largest block has 2 equations and the next largest has 1.
Block
Size
Eqn
Var
1
2
Y
X
We'll save this model for later and look at the Japan model again:
TROLL Command: filemod waysimpl ;
Size
Eqn
Var
43
JA_LF
29
JA_R
40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
17
18
20
21
23
24
26
27
28
30
31
32
33
34
35
36
37
38
39
40
41
42
44
48
49
51
JA_C
JA_COIL
JA_K
JA_INVEST
JA_XM
JA_XMA
JA_XT
JA_IM
JA_IOIL
JA_ICOM
JA_IT
JA_A
JA_GDP
JA_GNP
JA_WK
JA_YD
JA_TAX
JA_TAXK
JA_TRATE
JA_B
JA_P
JA_M
JA_RL
JA_RLR
JA_RSR
JA_PGNPNO
JA_ER
JA_PGNP
JA_PFM
JA_PXM
JA_PXT
JA_PIM
JA_PIMA
JA_PIT
JA_YCAP
JA_BETA
JA_CU
JA_RS
JA_REER
JA_FA
22
JA_TAXH
16
JA_WH
45
JA_NFA
15
JA_W
19
JA_GE
25
JA_GDEF
10
46
JA_TB
11
47
JA_CURBAL
12
50
JA_MERM
X
X
Z
W
=
=
=
=
2*Y
Y+1
X
1W
X = 2*Y
X = Y+1
Z = X
This SOURCEMOD command produced a file called "makemulj.inp" with the following content:
MODCOM
'Japan' submodel from Multimod. ;
ADDSYM
ENDOGENOUS
JA_A JA_B JA_BETA JA_C JA_COIL JA_CU JA_CURBAL JA_ER JA_FA JA_GDEF JA_GDP
JA_GE JA_GNP JA_ICOM JA_IM JA_INVEST JA_IOIL JA_IT JA_K JA_LF JA_M JA_MERM
JA_NFA JA_P JA_PFM JA_PGNP JA_PGNPNO JA_PIM JA_PIMA JA_PIT JA_PXM JA_PXT JA_R
JA_REER JA_RL JA_RLR JA_RS JA_RSR JA_TAX JA_TAXH JA_TAXK JA_TB JA_TRATE JA_W
JA_WH JA_WK JA_XM JA_XMA JA_XT JA_YCAP JA_YD,
EXOGENOUS
CA_A CA_ER CA_PGNPNO CA_PXM DC_A DC_PGNP DUM80 FR_A FR_ER FR_PGNPNO FR_PXM
GR_A GR_ER GR_PGNPNO GR_PXM HO_A IT_A IT_ER IT_PGNPNO IT_PXM JA_BT JA_CTREFF
JA_DELTA JA_DEM3 JA_DUM JA_G JA_GEXOG JA_MT JA_NFAADJ JA_PART JA_POP
JA_PRODOIL JA_TRATEBAR JA_XOIL PCOM POIL RES_JA_A RES_JA_B RES_JA_C
RES_JA_COIL RES_JA_ER RES_JA_GDP RES_JA_GNP RES_JA_ICOM RES_JA_IM
JPXM
JPXT
JPIM
:
:
JPIMA
JPIT
:
:
JYCAP
JBETA
JLF
JCU
JNFA
:
:
:
:
JTB
JCAB
JER
JREER
JMERM
:
:
:
:
:
JFA
UK_PGNPNO*UK_ER/EE87)+W28*LOG(SI_PXM*SI_ER/SE87)+L28*LOG(
SI_PGNPNO*SI_ER/SE87)+W29*LOG(RW_PXM*RW_ER/RE87)+L29*LOG(DC_PGNP
*RW_ER/RE87)) ,
DEL(1: LOG(JA_PXM)) = JPXM0+JPXM1*DEL(1: LOG(JA_PGNPNO))+(1JPXM1)*DEL
(1: LOG(JA_PFM))+JPXM2*LOG(JA_PGNPNO(1)/JA_PXM(1))+RES_JA_PXM
,
JA_PXT = (JA_XMA*JA_PXM+POIL/JA_ER*JE87*JA_XOIL)/JA_XT ,
JA_PIM = (S12*US_PXM+S22*JA_PXM*JA_ER/JE87+S32*GR_PXM*GR_ER/GE87+S42*
CA_PXM*CA_ER/CE87+S52*FR_PXM*FR_ER/FE87+S62*IT_PXM*IT_ER/IE87+
S72*UK_PXM*UK_ER/EE87+S82*SI_PXM*SI_ER/SE87+S92*RW_PXM*RW_ER/
RE87)/(JA_ER/JE87)*(1+RES_JA_PIM) ,
JA_PIMA = JA_PIM+T2*(WTRADETRDE)/JA_ER/JA_IM ,
JA_PIT = (JA_IM*JA_PIMA+JA_IOIL*POIL/JA_ER*JE87+JA_ICOM*PCOM/JA_ER*
JE87)/JA_IT ,
JA_YCAP = JY87*(JBETA*(JA_K/JK87)**(JRHO)+(1JBETA)*((1+JPROD)**(T21
)*(1+RES_JA_YCAP/(1JBETA))*JA_LF/JL87)**(JRHO))**(1/JRHO) ,
JA_BETA = JBETA*(JA_YCAP/JA_K/(JY87/JK87))**JRHO ,
JA_LF = JA_POP*JA_PART/(1+JA_DEM3) ,
JA_CU = 100*JA_GDP/JA_YCAP ,
DEL(1: JA_NFA) = (JA_XT*JA_PXTJA_IT*JA_PIT)*JA_ER+US_R*(JA_NFA(1)+
JA_NFAADJ(1))+RES_JA_NFA ,
JA_TB = JA_XT*JA_PXTJA_IT*JA_PIT ,
JA_CURBAL = DEL(1: JA_NFA) ,
1+US_RS/100 = (1+JA_RS/100)*JA_ER(1)/JA_ER+RES_JA_ER ,
JA_REER = LOG(JA_PXM)LOG(JA_PFM) ,
JA_MERM = EXP(LOG(JA_ER/JE87)(+V23*LOG(GR_ER/GE87)+V24*LOG(CA_ER/CE87
)+V25*LOG(FR_ER/FE87)+V26*LOG(IT_ER/IE87)+V27*LOG(UK_ER/EE87)+
V28*LOG(SI_ER/SE87))) ,
JA_FA = (US_A*UE87)**L21*(JA_A*JE87)**L22*(GR_A*GE87)**L23*(CA_A*CE87)
**L24*(FR_A*FE87)**L25*(IT_A*IE87)**L26*(UK_A*EE87)**L27*(SI_A*
SE87)**L28*((HO_A+DC_A)*RE87)**L29/JE87 ,
SOURCEMOD
makes available a number of options for the form and content of its output:
You can process only part of a model  for example, just the symbol declarations, or just some
of the equations (using the same kind of syntax as with other MODEDIT commands).
You can output to a TROLL string array instead of an .INP file.
You can introduce equations using REPEQ instead of ADDEQ, so that the result will replace an
existing set of equations.
You can have the input begin with USEMOD, so as to clear out any existing model when it runs.
You can have the input end with FILEMOD, so as to save the model when it runs.
You can have it declare symbols implicitly using suffixes.
You can have it include comments on symbols and/or equations (not included by default).
You can preview the result of SOURCEMOD using "PRINT SOURCEMOD"
The syntax for these options is described in Section 5.17 of the Reference Manual.
b. recreating with INPUT
Since SOURCEMOD produces an .INP file, you can reproduce the model by inputting that file with the INPUT
command  in the above example, "input makemulj.inp"
c. editing with a text editor
While the model is stored in an .INP file, you can edit it directly using the text editor of your choice.
This way, you won't have to worry that modelediting commands might not behave exactly as you
expect. What you see is what you get.
D. CHANGING MODELS
1. Changing Symbols
a. CHANGESYM: changing symboltypes
See the discussion and another example earlier in this chapter, and Section 5.5 of the Reference Manual.
b. RENAMESYM: changing symbolnames
RENAMESYM
is pretty straightforward:
Symbols:
ENDOGENOUS :
JA_ICOM JA_IM
JA_INVEST
JA_IOIL
JA_IT
ja_im ja_impman
ja_ioil ja_impoil ;
Symbols:
ENDOGENOUS :
JA_IMPCOM JA_IMPMAN
JA_IMPOIL
JA_INVEST
JA_IT
When you rename a symbol, the change affects only the model and not any associated data. If you
reestimate or resimulate the model with the same data, you will not generally get the same results. If
you rename an ENDOGENOUS or EXOGENOUS symbol, and your SEARCHed databases do not contain an object
corresponding to the new symbol name, you will get an error. You can use the DFRENAME function to
rename data objects if necessary.
You could also use RENAMESYM intentionally to change the data to which model symbols correspond. For
example, suppose you are experimenting with different definitions of national output, and suppose you
have data on both national product ("JA_GNP") and domestic product ("JA_GDP"). You could estimate
a model using GDP, then issue the command "renamesym ja_gdp ja_gnp;", and then reestimate, now
automatically using GNP instead of GDP.
c. DELSYM: deleting symbols
Unused symbols can sometimes cause problems. In particular, unused COEFFICIENT and PARAMETER
symbols can cause problems when starting a simulation, and any unused symbols are likely to confuse a
model user. DELSYM allows you to jettison unused symbols.
DELSYM will not delete symbols that are still used in equations. By default, it will warn you about the
symbols it cannot delete. You can suppress this warning with the NOWARN option. To make sure your
model contains no unused symbols, you can issue the command "delsym nowarn all;", which will
simply delete any unused symbols.
See Section 5.7 of the Reference Manual.
d. ADDSYM: adding symbols
This chapter has shown plenty of examples of ADDSYM. As explained, you can also avoid using ADDSYM by
declaring symbols implicitly with suffixes. The syntax for ADDSYM is described in Sections 5.3 and 5.1.6
of the Reference Manual.
2. Changing Equations
a. CHANGEQ: editing an equation
See discussion and other examples earlier in this chapter. Be careful with CHANGEQ because its behavior
may not be what you expect. Read the Reference Manual topic (Section 5.4), especially the notes. And
it's worth repeating: you cannot use CHANGEQ to delete an existing equation label. Also, the syntax for
using CHANGEQ to change an existing equation label may not be what you expect, since CHANGEQ cannot
see the old equation label.
b. REPEQ: replacing equations
replaces a model equation with a new equation in the same position. It is generally safer to use
than CHANGEQ (although obviously less compact), and it can be used to circumvent some of CHANGEQ's
limitations. See the earlier example and the Reference Manual topic (Section 5.15).
REPEQ
(Section 5.6).
d. ADDEQ: adding equations
See the rest of this chapter, including numerous examples, and the Reference Manual topic (Section 5.2).
Note that you must specify the position ("top", "bottom", "2", "5", etc.) in which the equation should
appear.
3. Changing Analysis
a. RENORM:
As pointed out earlier, TROLL is somewhat arbitrary in the correspondence it makes between between
equations and variables during "normalization". If you don't like TROLL's normalization, you can
change it. Consider the ultrasimple model from earlier:
MODEDIT Command: prtmod model waysimpl ;
Symbols:
ENDOGENOUS :
W X Y Z
Equations:
1:
2:
3:
4:
X
X
Z
W
=
=
=
=
2*Y
Y+1
X
1W
Size
Eqn
1
2
Y
X
Var
is associated with Equation 1, and X is associated with equation 2. We can change that as follows:
Size
Eqn
Var
1
2
X
Y
Now X is associated with Equation 1, and Y is associated with equation 2. In this case we only had to
specify one equation to renormalize, since only one alternative normalization was possible. In general, if
you specify only part of a block to renormalize, TROLL will arbitrarily renormalize the rest of that
block. You can, however, specify the renormalization as precisely as you wish. For example,
TROLL Command: usemod models_multj ;
TROLL Command: lkord block 3 ;
Size
Eqn
40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
17
18
20
21
23
24
26
27
28
30
31
32
33
34
35
36
37
38
39
40
41
42
44
48
49
51
Var
JA_C
JA_COIL
JA_K
JA_INVEST
JA_XM
JA_XMA
JA_XT
JA_IM
JA_IOIL
JA_ICOM
JA_IT
JA_A
JA_GDP
JA_GNP
JA_WK
JA_YD
JA_TAX
JA_TAXK
JA_TRATE
JA_B
JA_P
JA_M
JA_RL
JA_RLR
JA_RSR
JA_PGNPNO
JA_ER
JA_PGNP
JA_PFM
JA_PXM
JA_PXT
JA_PIM
JA_PIMA
JA_PIT
JA_YCAP
JA_BETA
JA_CU
JA_RS
JA_REER
JA_FA
Size
Eqn
40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
17
18
20
21
23
24
26
27
28
30
31
32
33
34
Var
JA_RLR
JA_GDP
JA_WK
JA_INVEST
JA_REER
JA_XM
JA_XMA
JA_IM
JA_COIL
JA_ICOM
JA_IOIL
JA_C
JA_XT
JA_GNP
JA_RSR
JA_YD
JA_TAX
JA_TAXK
JA_TRATE
JA_B
JA_A
JA_M
JA_RL
JA_P
JA_RS
JA_CU
JA_PGNP
JA_IT
35
36
37
38
39
40
41
42
44
48
49
51
JA_PFM
JA_PGNPNO
JA_PXT
JA_PIM
JA_PIMA
JA_PIT
JA_K
JA_BETA
JA_YCAP
JA_ER
JA_PXM
JA_FA
Note, though, that only certain normalizations are possible. TROLL will warn you if the renormalization
you ask for is not one of them:
TROLL Command: renorm 1 ja_rlr 2 ja_gdp 3 ja_wk 4 ja_k ;
ERROR 3213
It was not possible to normalize all equations.
Only 50 of 51 equations could be normalized.
Remember, also, that each renormalization supersedes previous renormalizations. The following
command is feasible to perform, but it undoes the effect of the earlier renormalization:
TROLL Command: renorm 4 ja_k ;
TROLL Command: lkord block 3 ;
The model has 12 blocks, including 1 simultaneous block.
The largest block has 40 equations and the next largest has 1.
Block
Size
Eqn
40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
17
18
20
21
23
24
26
27
28
30
31
32
33
34
35
36
37
38
39
40
41
42
44
48
49
51
Var
JA_C
JA_COIL
JA_WK
JA_K
JA_XM
JA_XMA
JA_XT
JA_IM
JA_IOIL
JA_ICOM
JA_IT
JA_INVEST
JA_A
JA_GNP
JA_RSR
JA_YD
JA_TAX
JA_TAXK
JA_TRATE
JA_B
JA_P
JA_M
JA_RL
JA_RLR
JA_RS
JA_CU
JA_PGNPNO
JA_PGNP
JA_PFM
JA_PXM
JA_PXT
JA_PIM
JA_PIMA
JA_PIT
JA_YCAP
JA_BETA
JA_GDP
JA_ER
JA_REER
JA_FA
We set G to 2, and G is an exogenous variable, but in the simulation, G does not have the value 2. How come?
SIMULATE Command: do prt.(g) ;
G:
G = 100*(US_G/US_G(1)1)
Numeric scalar timeseries Time dimension: Periodicity 1,
1970A
1974A
1978A
1982A
1986A
1990A
1994A
1970A to 1996A
0.15908
0.491335
2.238387
2.654389
2.654519
0.611696
0.037696
(27 observations)
1.979313
0.563261
0.557095
2.956225
1.340109
0.435118
1.107259
0.01859
2.460729
0.752966
5.889549
2.790764
0.219591
Apparently there is another G out there. When we set G to 2, we set the "SAVE" version of G, since "SAVE" is
specified in the first writable SEARCH rule. However, the first readable SEARCH rule specifies the "US" database:
SIMULATE Command: lksearch ;
Current SEARCH list:
Name

W?

Filetype

Basic?

US
SAVE
.
TROLLSYS
W
W
DATA
DATA
NONDATA
NONDATA
BASIC
BASIC
BASIC
Value:
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1A
5A
Z:
Z = RESHAPE(SEQ(7),1A)
2
6
1A to 7A
(7 observations)
3
7
1A
5A
1A to 7A
2
6
(7 observations)
3
7
The two simulations in the above example use the same simulation commands on the same equations. However,
in the first simulation, Z is a DEFINITION variable, and its values are calculated from its identity equation
regardless of the data. In the year 2A, Z is calculated as Z[2A] = X(1) = X[1A] = 1. Then, in the year 3A, X is
calculated as X[3A] = Z(1) = Z[2A] = 1, and then the simulation continues using these values.
In the second simulation, Z is an ENDOGENOUS variable, and its starting values are taken from the data. In the year
2A, before the simulation begins, Z has the value 2, which comes from the data object Z and not from an
equation. Simulation proceeds with X[3A] = Z(1) = Z[2A] = 2, and subsequent solutions derive from this value.
X = 1
X = 2
(The above example uses Windows file path syntax. On a UNIX system, you would replace the doublebackslashes with
single forwardslashes.)
Footnotes
1. The word "file" by itself is ambiguous. It often refers specifically to permanent storage. For example, commands like "FILEMOD" and "FILECOEF" use the "FILE"
prefix to indicate that the item is to be stored on disk (or other nonvolatile medium) rather than in RAM.
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
If you're not sure for which dates you have complete data, TROLL provides functions to compute that information. If you know
your data are incomplete, you can specify a disjoint set of date ranges (even for a single estimation task), thereby avoiding the
specific dates with missing data. BOUNDS are a global option in TROLL: once you set the BOUNDS, that set of dates applies to any
estimation tasks you undertake in your TROLL session until you explicitly reset them. The LKBOUNDS command reports the
bounds that currently apply:
TROLL Command: lkbounds ;
You can also establish, or reset, the BOUNDS by specifying them as part of the command that begins an estimation task.
There are two general ways to perform estimation tasks in TROLL. One is called "model input"; the other is called "direct
input". The model input option is available for all estimation tasks; the direct input option is available only for linear singleequation methods. Under the model input option, TROLL estimates all or part of the "CURRENT" model, as described in the
previous chapter. Under the direct input option, you describe the specification as part of the estimation command. With the
model input option, you specify explicitly all elements, including all coefficients, of the equation or equations to be estimated.
With the direct input option, the equation is assumed to be linear and (by default) to contain a constant term, so you need only
specify the names of the variables and any options you wish to use.
Bear in mind that BOUNDS only apply to estimation tasks. Even while an estimation task in progress, you can issue commands
that work with information outside the task, and the BOUNDS will not apply to that information. If you get a similar type of
information from the estimation task itself, the BOUNDS will apply. So, for example, if you request independent variable summary
statistics in a regression output, and you request the same statistics from the STATS function via a DO command, you may get a
different set of statistics. If you wish to work only with data from within the BOUNDS, you can set an identical data range in the
DRANGE command. (Remember to reset the DRANGE when you want to work with all the data again.)
Command:
Command:
Command:
to 2100A
Command:
As of TROLL 1.097, the BOUNDS function also offers a SET option which instructs it to set the newly calculated
bounds as if you had issued a BOUNDS statement.
Since the BOUNDS function is a function, it returns a value, namely an array containing the bounding dates. In this
case, we have ignored the return value and concerned ourselves with the side effect  a brief text description of
the bounds range. Again, since the BOUNDS function is a function, you can pass it any kind of time series you like,
including a transformed series, a lagged or leaded series, or even a constant.
Transformations, lags and leads, and constants have important implications for the possible bounds, as the
following examples will show. Transformations are important, first, because they can sometimes transform valid
data into missing values:
TROLL
TROLL
1A to
TROLL
WARNING 6001
NA(s) returned where operand values did not allow an operation.
The following problem(s) occurred during LOG:
 attempt to take log of a nonpositive number
11A to 20A
In fact, TROLL's transformations can also transform missing values into valid data, as we will see shortly.
The importance of lags and leads should be readily apparent:
TROLL Command: do bounds ( var (1), var(+2) ) ;
2A to 18A
The behavior of constants is simpler but less obvious. A constant is essentially a time series that lasts from the
infinite past into the infinite future. Therefore, a constant with a valid data value has no effect on the feasible
BOUNDS, since it overlaps with any dates in any time series. A constant without a valid data value, on the other
hand, does not overlap with any time series. Thus,
TROLL Command: do bounds ( var, 2 ) ;
1A to 20A
TROLL Command: do bounds ( var, na ) ;
(No common NAfree dates)
What happens if you have missing data in the middle of a data series? Does that prevent you from doing a single
estimation for the whole span of the sample period? Not in TROLL! A bounds specification can contain multiple
ranges, so that it will skip the missing data in the middle of the series and resume when valid data are once again
available. The following example demonstrates.
TROLL Command: do pi = 3.1415926535 ;
TROLL Command: do var = reshape ( sin ( seq(40) * pi/10 ), 1a ) ;
TROLL Command: do doughnut = log ( var ) ;
WARNING 6001
NA(s) returned where operand values did not allow an operation.
The following problem(s) occurred during LOG:
 attempt to take log of a nonpositive number
TROLL Command: do prt. ( doughnut ) ;
DOUGHNUT:
DOUGHNUT = LOG(VAR)
Numeric scalar timeseries Time dimension: Periodicity 1,
Time dimension >
:
1.174359
:
0
:
1.174359
:
NA
:
NA
:
1.174359
:
0
:
1.174359
:
NA
:
NA
1A
5A
9A
13A
17A
21A
25A
29A
33A
37A
TROLL
1A to
TROLL
TROLL
Command:
10A 21A
Command:
Command:
1A to 40A
0.531394
0.050182
23.133512
NA
NA
0.531394
0.050182
22.0349
NA
NA
(40 observations)
0.211935
0.211935
NA
NA
NA
0.211935
0.211935
NA
NA
NA
0.050182
0.531394
NA
NA
NA
0.050182
0.531394
NA
NA
NA
do bounds (doughnut) ;
to 30A
bounds 1A to 10A 21A to 30A ;
lkbounds ;
fillin value:
TROLL Command: do prt.( nafill (doughnut) ) ;
NAFILL(DOUGHNUT):
Numeric scalar timeseries Time dimension: Periodicity 1,
1A to 40A
(40 observations)
1A
5A
9A
13A
17A
21A
25A
29A
33A
37A
NAFILL
also has a twoargument form, which allows you to specify a value to replace the missing values:
0.531394
0.050182
23.133512
2.651995
2.651995
0.531394
0.050182
22.0349
2.651995
2.651995
0.211935
0.211935
2.651995
2.651995
2.651995
0.211935
0.211935
2.651995
2.651995
2.651995
0.050182
0.531394
2.651995
2.651995
2.651995
0.050182
0.531394
2.651995
2.651995
2.651995
1A
5A
9A
13A
17A
21A
25A
29A
33A
37A
1A to 40A
0.531394
0.050182
23.133512
0
0
0.531394
0.050182
22.0349
0
0
(40 observations)
0.211935
0.211935
0
0
0
0.211935
0.211935
0
0
0
0.050182
0.531394
0
0
0
0.050182
0.531394
0
0
0
1A
5A
9A
13A
17A
21A
25A
29A
33A
37A
1A to 40A
0.531394
0.050182
23.133512
15.148365
7.163219
0.531394
0.050182
22.0349
105.477063
188.919226
(40 observations)
0.211935
0.211935
21.137225
13.152079
5.166932
0.211935
0.211935
42.895441
126.337603
209.779766
0.050182
0.531394
19.140939
11.155792
3.170646
0.050182
0.531394
63.755981
147.198144
230.640307
NAGROW(DOUGHNUT):
DOUGHNUT = LOG(VAR)
Numeric scalar timeseries Time dimension: Periodicity 1,
1A
5A
9A
13A
17A
21A
25A
29A
33A
37A
1A to 40A
(40 observations)
4A
0A
4A
8A
12A
16A
20A
24A
28A
32A
36A
40A
44A
4A to 45A
0.852876
0.336342
2.706925
3.593081
8.279755
0.852876
0.336342
2.597064
3.436136
7.913551
NA
NA
NA
(50 observations)
0.639229
0.31857
2.706925
4.183564
12.153936
0.639229
0.31857
2.597064
4.000462
11.604629
NA
NA
0.491967
0.345173
2.87721
5.020276
23.133512
0.491967
0.345173
2.755142
4.800554
22.0349
NA
NA
4A
0A
4A
8A
12A
16A
20A
24A
28A
32A
36A
40A
44A
4A to 45A
0.852876
1.174359
0
1.174359
8.279755
0.852876
1.174359
0
1.174359
7.913551
NA
NA
NA
(50 observations)
0.639229
0.531394
0.050182
23.133512
12.153936
0.639229
0.531394
0.050182
22.0349
11.604629
NA
NA
0.491967
0.211935
0.211935
5.020276
23.133512
0.491967
0.211935
0.211935
4.800554
22.0349
NA
NA
You will notice that some missing values remain. TROLL generously expanded the "HOLE" series to
extend 5 elements beyond "DOUGHNUT" at either end, and OVERLAY gave us the longest possible
combination of time periods. However, even the time span of the original "DOUGHNUT" series
(through 40A) has some missing values at the end. One way to take care of these missing values is to
supply an additional argument to OVERLAY. The additional argument represents another series used to fill
in the remaining NA values. In the following example, the third "series" is really a constant, which, as
we saw before, can represent a "timeless time series".
TROLL Command: do prt. ( overlay ( doughnut, hole, 99 ) ) ;
OVERLAY(DOUGHNUT,HOLE,99):
Numeric scalar timeseries Time dimension: Periodicity 1,
4A
0A
4A
8A
12A
16A
20A
24A
28A
32A
36A
40A
44A
4A to 45A
0.852876
1.174359
0
1.174359
8.279755
0.852876
1.174359
0
1.174359
7.913551
99
99
99
(50 observations)
0.639229
0.531394
0.050182
23.133512
12.153936
0.639229
0.531394
0.050182
22.0349
11.604629
99
99
0.491967
0.211935
0.211935
5.020276
23.133512
0.491967
0.211935
0.211935
4.800554
22.0349
99
99
certainly is not limited to three arguments (or even three hundred arguments, although I
wouldn't try that at home). The following example uses multiple moving averages to fill the doughnut
holes. It starts with a 5year average. If that's not available, it uses a 7year, then a 9year, and so on, up
to 19 years. Finally, it uses the NATRIM function to eliminate any remaining missing values from the
beginning or end of the result.
OVERLAY
)
)
)
)
)
)
)
)
;
;
;
;
;
;
;
;
NATRIM(OVERLAY(DOUGHNUT,H2,H3,H4,H5,H6,H7,H8,H9)):
Numeric scalar timeseries Time dimension: Periodicity 1, 8A to 39A (48 observations)
8A
4A
0A
4A
8A
12A
16A
20A
24A
28A
32A
36A
1.174359
1.174359
1.174359
0
1.174359
23.133512
1.174359
1.174359
0
1.174359
22.0349
22.0349
1.174359
1.174359
0.531394
0.050182
23.133512
23.133512
1.174359
0.531394
0.050182
22.0349
22.0349
22.0349
1.174359
1.174359
0.211935
0.211935
12.153936
23.133512
1.174359
0.211935
0.211935
11.604629
22.0349
22.0349
[1]:
[5]:
[9]:
[13]:
0.211935
0.211935
1.174359
0
0.050182
0.531394
0.531394
0.050182
[17]:
0.211935
0.531394
1.174359
22.0349
1A
5A
9A
13A
17A
21A
25A
29A
33A
37A
0.531394
0.050182
23.133512
7.825928
2.647465
0.531394
0.050182
22.0349
105.477063
188.919226
0.211935
0.211935
17.642704
5.968421
2.019081
0.211935
0.211935
42.895441
126.337603
209.779766
0.050182
0.531394
13.455155
4.551798
1.539846
0.050182
0.531394
63.755981
147.198144
230.640307
TROLL's array processing functions also provide virtually unlimited scope for alternative ways of
replacing missing values. This last example uses a spline:
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
COOKED:
COOKED = SETREP(RAWDATA,SUBSTITUTES,NADATES)
Numeric scalar timeseries Time dimension: Periodicity 1,
1A
5A
9A
13A
17A
21A
25A
29A
1A to 30A
0.531394
0.050182
23.133512
58.728138
23.320833
0.531394
0.050182
22.0349
(30 observations)
0.211935
0.211935
43.325329
53.220793
13.310803
0.211935
0.211935
0.050182
0.531394
55.105186
44.600608
5.487052
0.050182
0.531394
LHSMEAN
SR
There's more where that came from. After you run the regression, you can ask for the following diagnostics, using the
PRTDIAG command ("prtdiag [diagnostics you want]"):
(covariance ratio statistics based on row deletion)
(scaled differences between OLS estimates and estimates after row deletion)
DFFITS (scaled difference in predicted values due to row deletion)
FVARATIO (FIT variance ratio statistic based on row deletion)
HAT (diagonal elements of the hat matrix)
RESIDUAL (residuals)
RSTUDENT (studentized residuals)
VARDCOM (variance decomposition proportions)
COVRATIO
DFBETAS
One additional possibility that falls under the heading of OLS is the use of distributed lags. TROLL provides for both
unconstrained and polynomial distributed lags with the DLAG statement. DLAG associates a distributed lag specification
with a particular regressor, and that specification is then applied whenever that regressor appears. For example:
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
ESTIMATE
0.051537
0.238501
0.378106
0.109659
0.543028
2.162542
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.175188
0.348414
0.516787
0.501697
0.328478
1.075901
0.326409
0.040938
43.659002
29.717575
3.543671
TSTAT
0.294182
0.684534
0.731648
0.218576
1.653163
2.009982
PROB>T
0.772401
0.503434
0.474964
0.829744
0.117781
0.061605
This DLAG specification remains in effect until it is replaced with a new one or overridden with "dlag off". In the
present example, the DL keyword indicates that this is an unconstrained "Distributed Lag" rather than a "Polynomial
Distributed Lag" (PDL). The simple, unconstrained DLAG ("dlag dl") is really just a convenience, so you don't have to
specify the lag terms explicitly. When you specify a polynomial distributed lag, TROLL does quite a bit more work for
you. You give the degree, the length, and an optional endconstraint, and TROLL takes care of the rest:
OLS Command: dlag pdl p 8 2 tail ; /* 8 yr quadratic, zero at far end */
OLS Command: ols y r p, 1979a to 1996a ;
ORDINARY LEAST SQUARES
LHS VARIABLE:
ESTIMATE
R
P
P(1)
P(2)
P(3)
P(4)
P(5)
P(6)
P(7)
CONST
0.221856
0.442479
0.266317
0.124685
0.017581
0.054993
0.093038
0.096555
0.065542
1.544512
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.285606
0.053284
40.151855
34.553804
2.32592
TSTAT
0.309834
0.169597
0.112348
0.075265
0.060972
0.060879
0.060461
0.051857
0.032093
1.250489
PROB>T
0.716046
2.609003
2.370463
1.65662
0.28835
0.903319
1.538823
1.861947
2.042222
1.235126
0.485736
0.020613
0.032663
0.119828
0.777304
0.381637
0.146139
0.083733
0.060436
0.237111
Note that when you change the length of the DLAG, you may have to change the BOUNDS accordingly (as in the examples
above). If you forget what DLAG specification is in effect, you can find out with the LKDLAG command:
OLS Command: lkdlag ;
DLAG LIST ::
***** DLAG for direct INPUT *****
PDL P
8
2
TAIL
***** DLAG for model INPUT *****
EMPTY
You can also use nonlinear functional forms with OLS, provided they are linear in the coefficients. For the directinput
option, you specify a functional form by placing the formula for each regressor in quotations:
OLS Command: dlag off ;
OLS Command: ols y r "r**2" "log(1+p)" ;
ORDINARY LEAST SQUARES
LHS VARIABLE:
NOB = 18
NOVAR = 4 NCOEF = 4
RANGE: 1979A to 1996A
RSQ =
0.420367
F(3/14) =
3.384401
SER =
1.680959
DW(0) =
2.006018
MAX:HAT =
0.832954
DFFITS =
1.184315
COEF
R
R**2
LOG(1+P)
CONST
ESTIMATE
0.290962
0.01569
6.554528
8.530687
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.69574
0.042673
2.391115
3.540828
0.29616
0.048393
39.558705
33.474059
3.04094
TSTAT
0.418205
0.367684
2.741202
2.409235
PROB>T
0.682141
0.718608
0.015918
0.030327
Finally, you may want to store your results for future use. This you accomplish via the FILExxxx (permanent storage)
and SAVExxxx (first available  usually temporary  storage) commands, to wit:
Details on the use of these commands may be found in the Reference Manual. You don't always have to store your
results explicitly. TROLL automatically remembers OLS information until you either exit the task or estimate a new
equation. You can recall it with the RECALL command.
B. MODELINPUT OPTION
The modelinput option is similar in many respects to the directinput option, but it requires you to set up a model first.
This is useful when you already have a model specified, or when you want to estimate and simulate the same model.
Examples of OLS estimation using the modelinput option appeared in the introductory chapter and the chapter on
models. Here we'll redo the three examples from this chapter so far from a model. First set up the model:
OLS Command: usemod ;
New model: (nameless)
TROLL Command: addsym endogenous y,
Symboltype or ';': exogenous r p,
Symboltype or ';': coefficient a0 a1 a2 b0 b1 b2 c0 c1 c2 c3 ;
MODEDIT Command: addeq bottom y = a0 + a1*r + a2*p ,
[Lbl:] Equation: y = b0 + b1*r + b2* p ,
[Lbl:] Equation: y = c0 + c1*r + c2*r**2 + c3*log(1+p) ;
MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
Y
EXOGENOUS :
P R
COEFFICIENT :
A0 A1 A2 B0
B1
B2
C0
C1
C2
C3
FUNCTION :
LOG
Equations:
1:
2:
3:
Y = A0+A1*R+A2*P
Y = B0+B1*R+B2*P
Y = C0+C1*R+C2*R**2+C3*LOG(1+P)
Notice that the constant terms are explicit here. With the modelinput option, you explicitly include or exclude a
constant term by putting it in the equation or leaving it out. You might also notice that equations 1 and 2 are identical
except for the coefficient names. We're going to apply different DLAGs to the two equations. Under the modelinput
option, DLAGs apply to coefficients, not to variables. Therefore, we can use both DLAGs in the same model without having
to redefine the DLAG:
MODEDIT Command: dlag model dl a2 4,
Continue :: pdl b2 8 2 tail ;
Now that we've set up the model, we can estimate all three equations with one command:
MODEDIT Command: olsmod all ;
ORDINARY LEAST SQUARES
1 :
Y = A0+A1*R+A2*P
NOB = 18
NOVAR = 6 NCOEF = 6
RANGE: 1979A to 1996A
RSQ =
0.740101
F(5/12) =
6.83435
SER =
1.215783
DW(0) =
2.986075
MAX:HAT =
0.652754
DFFITS =
2.774067
COEF
A0
A1
A2[1]
A2[2]
A2[3]
A2[4]
ESTIMATE
1.343562
0.222638
0.488113
1.699054
0.052061
0.720465
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.63181
0.003099
17.73755
46.208266
2.035547
TSTAT
0.846532
0.249834
0.444887
0.702919
0.712405
0.429486
PROB>T
1.587136
0.891147
1.09716
2.41714
0.073077
1.677507
0.138467
0.390368
0.2941
0.032487
0.942949
0.119276
Y = B0+B1*R+B2*P
TAIL
NOB = 18
NOVAR = 10 NCOEF = 4
RANGE: 1979A to 1996A
RSQ =
0.411676
F(3/14) =
3.265465
SER =
1.693514
DW(0) =
2.264942
MAX:HAT =
0.406085
DFFITS =
1.149427
COEF
B0
B1
B2[1]
B2[2]
B2[3]
B2[4]
B2[5]
B2[6]
B2[7]
B2[8]
ESTIMATE
1.544512
0.221856
0.442479
0.266317
0.124685
0.017581
0.054993
0.093038
0.096555
0.065542
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.285606
0.053284
40.151855
34.553804
2.32592
TSTAT
1.250489
0.309834
0.169597
0.112348
0.075265
0.060972
0.060879
0.060461
0.051857
0.032093
PROB>T
1.235126
0.716046
2.609003
2.370463
1.65662
0.28835
0.903319
1.538823
1.861947
2.042222
0.237111
0.485736
0.020613
0.032663
0.119828
0.777304
0.381637
0.146139
0.083733
0.060436
Y = C0+C1*R+C2*R**2+C3*LOG(1+P)
NOB = 18
NOVAR = 4 NCOEF = 4
RANGE: 1979A to 1996A
RSQ =
0.420367
F(3/14) =
3.384401
SER =
1.680959
DW(0) =
2.006018
MAX:HAT =
0.832954
DFFITS =
1.184315
COEF
C0
C1
C2
C3
ESTIMATE
8.530687
0.290962
0.01569
6.554528
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
3.540828
0.69574
0.042673
2.391115
0.29616
0.048393
39.558705
33.474059
3.04094
TSTAT
2.409235
0.418205
0.367684
2.741202
PROB>T
0.030327
0.682141
0.718608
0.015918
You may recognize these numbers from before. If you want, of course, you can still estimate the equations one at a time.
Or you can estimate any subset that you like:
OLSMOD Command: olsmod 2 3 ;
ORDINARY LEAST SQUARES
2 :
Y = B0+B1*R+B2*P
TAIL
NOB = 18
NOVAR = 10 NCOEF = 4
RANGE: 1979A to 1996A
RSQ =
0.411676
F(3/14) =
3.265465
SER =
1.693514
DW(0) =
2.264942
MAX:HAT =
0.406085
DFFITS =
1.149427
COEF
ESTIMATE
B0
B1
B2[1]
B2[2]
B2[3]
B2[4]
B2[5]
B2[6]
B2[7]
B2[8]
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
1.544512
0.221856
0.442479
0.266317
0.124685
0.017581
0.054993
0.093038
0.096555
0.065542
0.285606
0.053284
40.151855
34.553804
2.32592
TSTAT
1.250489
0.309834
0.169597
0.112348
0.075265
0.060972
0.060879
0.060461
0.051857
0.032093
PROB>T
1.235126
0.716046
2.609003
2.370463
1.65662
0.28835
0.903319
1.538823
1.861947
2.042222
0.237111
0.485736
0.020613
0.032663
0.119828
0.777304
0.381637
0.146139
0.083733
0.060436
Y = C0+C1*R+C2*R**2+C3*LOG(1+P)
NOB = 18
NOVAR = 4 NCOEF = 4
RANGE: 1979A to 1996A
RSQ =
0.420367
F(3/14) =
3.384401
SER =
1.680959
DW(0) =
2.006018
MAX:HAT =
0.832954
DFFITS =
1.184315
COEF
ESTIMATE
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
C0
8.530687
C1
0.290962
C2
0.01569
C3
6.554528
OLSMOD Command: quit ;
3.540828
0.69574
0.042673
2.391115
0.29616
0.048393
39.558705
33.474059
3.04094
TSTAT
2.409235
0.418205
0.367684
2.741202
PROB>T
0.030327
0.682141
0.718608
0.015918
B. SERIAL CORRELATION
The assumptions underlying OLS are often inappropriate for time series data. Most commonly violated is the
assumption of independent residuals. Using syntax analogous to the OLS syntax, TROLL can estimate linear equations
with first and a secondorder autocorrelation. As with OLS, both the directinput option and the modelinput option are
available. The commands are SCC ("serial correlation correction") and SCCMOD (the modelinput option).
To use SCC or SCCMOD, you have to choose a correction procedure, either the CochraneOrcutt procedure or the
HildrethLu procedure. In conjunction with this, you choose either first or secondorder AR correction. The options are
CORC, CORC2, HILU, and HILU2. The next example does a CochraneOrcutt AR(2) correction  and demonstrates how
important the serial correlation correction can be for singleequation results.
This regression characterizes (crudely) the relationship between interest rates, inflation, and unemployment in the
United States during the period 1983 to 1996. Inflation is represented as a 24month quadratic distributed lag. (See the
description of distributed lags above in the section on OLS.)
TROLL
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
Command:
delaccess all ;
access usm type formdata id usm.frm ;
search usm ;
do i = 1200*log(p/p(1)); // inflation rate
dlag pdl i 24 2 ;
The dependent variable is the yield on oneyear treasury bills ("r"). The unemployment rate ("u") appears
contemporaneously on the righthand side. Because one would expect a lag in the effect of interest rates on economic
activity, this specification might seem to avoid the problem of simultaneity. The equation would be interpreted as
something like a central bank reaction function. However, when we fit the equation as a simple OLS, it must seem to
represent the behavior of a very perverse central bank:
TROLL Command: ols r u i, 1983m1 to 1996m12 ;
ORDINARY LEAST SQUARES
WARNING 2106
Condition number exceeds the current userset CONOPT CONDWARN.
LHS VARIABLE:
ESTIMATE
U
I
I(1)
I(2)
I(3)
I(4)
I(5)
I(6)
I(7)
I(8)
I(9)
I(10)
I(11)
I(12)
I(13)
I(14)
I(15)
I(16)
I(17)
I(18)
I(19)
I(20)
I(21)
I(22)
I(23)
CONST
STER
0.64689
0.154428
0.141953
0.12993
0.118359
0.10724
0.096574
0.086359
0.076596
0.067285
0.058426
0.050019
0.042064
0.034562
0.027511
0.020912
0.014765
0.00907
0.003827
0.000964
0.005303
0.00919
0.012625
0.015608
0.018139
1.47679
0.313015
0
505.622818
127.957926
2.375515
TSTAT
0.153506
0.026142
0.021979
0.018427
0.015553
0.013423
0.012066
0.011418
0.011309
0.011512
0.011824
0.012096
0.012234
0.012191
0.011957
0.01156
0.011071
0.010622
0.010418
0.01072
0.011758
0.013634
0.016319
0.019723
0.023761
1.104433
PROB>T
4.214103 4.14105108e005
5.907268
0
6.458624
0
7.051028
0
7.610079
0
7.989313
0
8.003915
0
7.563307
0
6.773247
0
5.844629
0
4.941184 1.89936035e006
4.135303 5.66077332e005
3.43845
0.000743
2.835099
0.005162
2.300786
0.022671
1.80897
0.072298
1.333632
0.184185
0.853867
0.394432
0.367329
0.71385
0.089917
0.928463
0.451005
0.652586
0.674023
0.501252
0.773633
0.440268
0.791339
0.429896
0.763371
0.446345
1.337148
0.183037
The inflation coefficients have the expected positive signs, but the unemployment coefficient is also positive  and
rather large at that. Does the Fed react to high unemployment by raising interest rates? Fortunately for Paul Volcker's
reputation, the corrected version of the equation produces a very different result:
OLS Command: scc corc2 r u i ;
CORCHANEORCUTT PROCEDURE
ITER
****
0
1
2
3
4
LHS VARIABLE:
RHO1
****
0
1.09027
1.132757
1.134197
1.134489
RHO2
****
0
0.14464
0.154291
0.154013
0.153789
SSR
***
504.359547
20.379287
19.224439
19.218949
19.218407
0.97329
0
SER =
DW(0) =
MAX:HAT =
DFFITS =
COEF
U
I
I(1)
I(2)
I(3)
I(4)
I(5)
I(6)
I(7)
I(8)
I(9)
I(10)
I(11)
I(12)
I(13)
I(14)
I(15)
I(16)
I(17)
I(18)
I(19)
I(20)
I(21)
I(22)
I(23)
CONST
RHO1
RHO2
0.347664
1.94502
0.142365
0.898984
ESTIMATE
0.551017
0.006714
0.002782
0.000829
0.004121
0.007094
0.009746
0.012079
0.014092
0.015786
0.01716
0.018214
0.018949
0.019363
0.019459
0.019234
0.01869
0.017826
0.016642
0.015139
0.013316
0.011174
0.008711
0.005929
0.002828
9.638232
1.134489
0.153789
SSR =
COND =
RSTUDENT =
STER
0.16901
0.011917
0.011672
0.012141
0.013068
0.014215
0.01541
0.016543
0.017544
0.01837
0.018994
0.0194
0.019578
0.019521
0.019229
0.018704
0.017952
0.016988
0.015832
0.014524
0.013128
0.011756
0.010603
0.009966
0.010184
1.900343
0.078172
0.076976
19.218407
20.744596
3.195323
TSTAT
3.260257
0.563343
0.238372
0.068319
0.315375
0.499018
0.632451
0.730183
0.803287
0.859351
0.903423
0.938849
0.967858
0.991919
1.011942
1.02836
1.041093
1.049356
1.051177
1.042361
1.014364
0.950433
0.821566
0.594933
0.277643
5.071838
14.512801
1.997878
PROB>T
0.001362
0.573995
0.8119
0.945617
0.75289
0.618457
0.528
0.466353
0.423008
0.39144
0.367668
0.349233
0.334585
0.322744
0.313103
0.305342
0.299413
0.295607
0.294772
0.298827
0.31195
0.343335
0.412554
0.552734
0.781647
0
0
0.047435
That unemployment coefficient makes a lot more sense. Note (below) that TROLL has entered the SCC task, from which
we will now QUIT.
SCC Command: quit ;
TROLL Command:
polynomial distributed lag. We do this using a function called SCRAMBLE'F, which calculates the polynomial regressors
for a variable given a specified degree and maximum lag. We're not directly interested in these scrambled variables;
they will only serve as preliminary regressors in the twostage least squares. Thus:
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
The dependent variable is the inflation rate averaged over the next twelve months starting next month:
TROLL Command: do i.future = movavg (i(1), 0, 11);
NOB = 144
NOVAR = 4 NCOEF = 4
RANGE: 1985M01 to 1996M12
RSQ =
0.967096
F(3/140) =
1371.59591
SER =
0.309666
DW(0) =
1.936652
MAX:HAT =
0.102138
DFFITS =
0.938015
COEF
ESTIMATE
I.FUTURE
R(1)
R(2)
CONST
0.058964
1.183192
0.227411
0.062719
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.026129
0.081318
0.079341
0.108851
0.966391
0
13.425009
56.499042
4.333775
TSTAT
PROB>T
2.256674
14.550114
2.866258
0.576189
0.025577
0
0.004795
0.565413
The inflation coefficient in the OLS regression suffers from a severe downward bias, because of the negative correlation
between that independent variable (observed inflation) and the error term (the surprise element of inflation not
anticipated by the bond market  or whenever set of agents is reacting to prospective inflation). Even so, the coefficient
has the expected sign, and it is (a little bit) statistically significant. However, it is quite small: less than 5 percent, which,
taken at face value, would imply a trivial influence of inflation on the interest rate. However, just like in the movies,
everything always works out for the best in a user's guide. Twostage least squares rides in on a white horse and saves
the day:
OLS Command: tsls r i.future r(1) r(2);
TWOSTAGE LEAST SQUARES
RHS_Y
FIRST_STAGE RSQ
I.FUTURE :
0.617885
LHS VARIABLE:
NOB = 144
NOVAR = 4 NCOEF = 4
RANGE: 1985M01 to 1996M12
RSQ =
0.96411
F(3/140) =
1253.603972
SER =
0.323522
DW(0) =
1.692912
MAX:HAT =
0.098873
DFFITS =
0.931006
COEF
I.FUTURE
ESTIMATE
0.152478
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.037256
0.963341
0
14.653345
57.225162
4.210519
TSTAT
PROB>T
4.092755 7.16764608e005
R(1)
R(2)
CONST
1.12988
0.198332
0.097672
0.086178
0.083265
0.121753
13.111017
2.38194
0.802217
0
0.018566
0.423787
Although the inflation coefficient is still not huge, it now seems to indicate that the bond market (or whatever set of
agents we imagine) does care about prospective inflation. The coefficient is highly statistically significant, and the value
seems reasonable. (Note again that TROLL has entered a new task, from which we now QUIT.)
TSLS Command: quit ;
TROLL Command:
For most problems, alternative (better) starting values for some of the coefficients will be obvious. For example, if a
coefficient must be negative, then 0.5 is clearly not a good starting value. A closer look at the underlying theory may
also provide some relevant insight. Usually, preliminary empirical analysis can generate an even better set of starting
coefficients. Many nonlinear models can be approximated first with linear models that can be estimated analytically to
provide starting values. Also, many complicated nonlinear models can be approximated first with simpler nonlinear
models that can be solved more reliably.
also provides a default set of convergence criteria and tuning parameters. These parameters are more serviceable
than the starting coefficient values, but they also can benefit from adjustment to the conditions of the particular problem
 and the preferences of the particular user. In some cases convergence will fail with the default criteria, but some
adjustment (and a modicum of patience) will produce satisfactory results. Some estimations require greater precision
and therefore tighter convergence criteria. Estimations that require less precision may be expedited by loosening
convergence criteria. Advanced and/or curious users may also be able to improve results by adjusting algorithm tuning
parameters.
NLS
The following example will demonstrate the use of NLS by estimating several forms for the aggregate Japanese
production function over the years 1974 to 1997.
The series for capital represents the utilized portion of the capital stock:
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
The series for labor is generated on the assumption that the fraction of "employed" labor which is actually utilized is
proportional to the capacity utilization rate for capital:
TROLL Command: do labor = lf*(1unr/100)*cu/100 ;
Although NLS operates on one equation at a time, it requires a "model" in order to operate. In this example we create a
"model" consisting of several alternative production function specifications. The equations do not represent
simultaneous processes, as in the usual concept of a model, but alternative descriptions of the same process. It is
convenient to put them all in the same TROLL "model" so that each one can be estimated as part of the same project
without having to create new models. The first equation represents the CobbDouglas production function:
TROLL Command: bounds 1974a to 1997a ;
TROLL Command: usemod ;
The fourth equation represents a form of the constantreturnstoscale Constant Elasticity of Substitution production
function:
MODEDIT Command: addeq bottom, ceshom1: gdp = scale'c * (
Arguments or ')': ( (1alpha)**(1+power'c) ) * labor**power +
Continue eq: (
alpha**(1+power)
) * capital**power ) ** (1/power) ;
In the form presented here, this function is a generalization of the first three equations. With power = 1, it reduces to the
linear function (equation 2), where betak = scale*alpha**2 and betal = scale*(1alpha)**2 . As power approaches
zero, the function approaches to CobbDouglas function (equation 1) with cdscale = scale*(1alpha)**
(1alpha)*alpha**alpha. Finally, as power approaches negative infinity, the function approaches the Leontief function
(equation 3) with ck = scale*alpha and cl = scale*(1alpha).
The last equation, equation 5, represents a further generalization  the general Constant Elasticity of Substitution
production function:
MODEDIT Command: addeq bottom, cesgenl: gdp = scale * (
Arguments or ')': ( (1alpha)**(1+power) ) * labor**power +
Continue eq: ( alpha**(1+power) ) * capital**power ) ** (homogeneity'c/power) ;
BETAL
CDSCALE
CK
CL
HOMOGENEITY
POWER
SCALE
FUNCTION :
MIN
Equations:
1:
2:
3:
4:
COBBDOUG
LINEAR
LEONTIEF
CESHOM1
5: CESGENL
GDP = CDSCALE*CAPITAL**ALPHA*LABOR**(1ALPHA)
GDP = BETAK*CAPITAL+BETAL*LABOR
GDP = MIN(CK*CAPITAL,CL*LABOR)
GDP = SCALE*((1ALPHA)**(1+POWER)*LABOR**POWER+ALPHA**(1+POWER)*
CAPITAL**POWER)**(1/POWER)
GDP = SCALE*((1ALPHA)**(1+POWER)*LABOR**POWER+ALPHA**(1+POWER)*
CAPITAL**POWER)**(HOMOGENEITY/POWER)
Before beginning NLS estimation, we can estimate equation 1 by OLS, since it transforms easily into a linear form:
MODEDIT Command: ols "log(gdp/labor)" "log(capital/labor)" ;
ORDINARY LEAST SQUARES
LHS VARIABLE:
LOG(GDP/LABOR)
NOB = 24
NOVAR = 2 NCOEF = 2
RANGE: 1974A to 1997A
RSQ =
0.995685
F(1/22) =
5076.876527
CRSQ =
PROB>F =
0.995489
0
SER =
DW(0) =
MAX:HAT =
DFFITS =
0.01083
0.200333
0.183795
0.818187
COEF
SSR =
COND =
RSTUDENT =
ESTIMATE
LOG(CAPITAL/LABOR)
CONST
COEF
0.00258
28.985184
2.09651
STER
0.509261
2.793665
TSTAT
0.007147
0.032076
71.252204
87.094358
PROB>T
LOG(CAPITAL/LABOR)
CONST
0
0
In the case of the CobbDouglas function, the default starting coefficient values of 0.5 are fairly reasonable (although it
may depend upon the scale of the problem). Here we will estimate using both the default starting values and starting
values derived from the OLS result.
OLS Command: nls 1 ;
Relative SSR and coefficient convergence
Iterations in current NLS estimation : 5
1 : GDP = CDSCALE*CAPITAL**ALPHA*LABOR**(1ALPHA)
NOB = 24
NOVAR = 2 NCOEF = 2
RANGE: 1974A to 1997A
RSQ =
0.999878
F(2/22) =
NA
SER =
4.43999
DW(0) =
0.202875
MAX:HAT =
0.197192
DFFITS =
0.966967
COEF
ESTIMATE
CDSCALE
ALPHA
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.064597
0.521639
0.999872
NA
433.697293
43.1632
2.121894
TSTAT
0.00329
0.011742
PROB>T
19.633061
44.423699
0
0
ESTIMATE
CDSCALE
ALPHA
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.064597
0.521639
0.00329
0.011742
0.999872
NA
433.697293
43.163332
2.12187
TSTAT
19.633002
44.423601
PROB>T
0
0
As expected, the two produce the same result. The result is not quite the same as the one produced by OLS, because OLS
and NLS are not minimizing the same thing. OLS minimizes the sum of the squared residuals in log (gdp/labor),
whereas NLS minimizes the sum of the squared residuals in gdp. If the fit were perfect, the two would be identical; as it
is, we have two slightly different statistical models of the same functional form. The advantage of the NLS version is that
the units of the residuals are the same as those of the variable gdp, so that we can compare the SSR (and other
residualbased statistics) to models of other functional forms that have gdp as the dependent variable.
Next we estimate the linear model (equation 2) using OLS, OLSMOD, and NLS. The three are exactly equivalent, and in this
case we can be confident that NLS will produce the correct result, since it is only minimizing a simple quadratic without
any unpleasant features such as false minima.
NLS Command: ols gdp capital labor nocon ;
ORDINARY LEAST SQUARES
LHS VARIABLE:
NOB = 24
GDP
NOVAR = 2
NCOEF = 2
ESTIMATE
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.999967
NA
110.370417
7.304086
2.701244
TSTAT
0.280364
0.002247
0.002998 2.90641970e005
PROB>T
124.786341
103.148512
0
0
GDP = BETAK*CAPITAL+BETAL*LABOR
NOB = 24
NOVAR = 2 NCOEF = 2
RANGE: 1974A to 1997A
RSQ =
0.999969
F(2/22) =
NA
SER =
2.23983
DW(0) =
0.621879
MAX:HAT =
0.16683
DFFITS =
0.780433
COEF
BETAK
BETAL
ESTIMATE
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.999967
NA
110.370417
7.304086
2.701244
TSTAT
0.280364
0.002247
0.002998 2.90641970e005
PROB>T
124.786341
103.148512
0
0
ESTIMATE
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.999967
NA
110.370417
7.304086
2.738142
TSTAT
0.280364
0.002247
0.002998 2.90641970e005
PROB>T
124.786341
103.148512
0
0
Looking at these results, we can say that this model fits better than the CobbDouglas model, since the SSR is smaller
(and, equivalently, the Rsquared is larger). For the linear model, there is no particular advantage to using NLS, except to
show that works.
Now we estimate the Leontief model. This is where things start to get tricky. Although there may be no obvious reason
to think that the default starting coefficients will be bad, neither is there any reason to think they will be good. The
Leontief production function turns out to be very particular about its starting coefficients, and a quick look at the
empirical data can provide much more reasonable starting values. First, though, let's just take a shot in the dark.
NLS Command: nls 3 ;
Singular convergence
Iterations in current NLS estimation : 2
ERROR 2138
NLS: Coefficients are not unique.
WARNING 2061
Covariance matrix not calculated.
3 :
GDP = MIN(CK*CAPITAL,CL*LABOR)
NOB = 24
NOVAR = 2 NCOEF = 2
RANGE: 1974A to 1997A
RSQ =
0.9849
F(2/22) =
NA
CRSQ =
PROB>F =
0.984214
NA
SER =
DW(0) =
MAX:HAT =
DFFITS =
COEF
CK
CL
49.307748
0.019981
NA
NA
SSR =
COND =
RSTUDENT =
53487.588783
NA
NA
ESTIMATE
0.503585
0.5
There are any number of problems here. NLS has numerous complaints; the estimated coefficients are suspiciously close
to the starting coefficients; and, most important, the fit is dismal. (Compare the SSR with the other equations.) To help
generate a better set of starting coefficients, let's look at some summary statistics for output/capital ratios and
output/labor ratios. If the Leontief function were a perfect fit, then the capital coefficient would have to equal the
maximum output/capital ratio, and the labor coefficient would have to equal the maximum output/labor ratio. These
maxima might be reasonable guesses for starting coefficients. Since we know the fit won't be perfect, the average ratios
might also be reasonable guesses. Here they are:
NLS Command: do qlratio = gdp/labor ;
NLS Command: do qkratio = gdp/capital ;
NLS Command: do stats (qkratio, qlratio) ;
QKRATIO:
NVals:
Min:
QLRATIO:
NVals:
Min:
24
Mean:
0.449189 Max:
Standard Deviation:
0.557227
0.736798
0.088534
24
Mean:
0.00473
Max:
Standard Deviation:
0.006337
0.008053
0.001017
Let's try both the maxima and the averages as starting coefficients:
NLS Command: do ck = 0.557227, cl = 0.006337 ;
NLS Command: nls 3 ;
Relative SSR and coefficient convergence
Iterations in current NLS estimation : 3
3 : GDP = MIN(CK*CAPITAL,CL*LABOR)
NOB = 24
NOVAR = 2 NCOEF = 2
RANGE: 1974A to 1997A
RSQ =
0.993802
F(2/22) =
NA
SER =
31.591184
DW(0) =
0.087298
MAX:HAT =
0.153558
DFFITS =
0.684548
COEF
CK
CL
ESTIMATE
0.608044
0.007211
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.99352
NA
21956.064594
1
1.842262
TSTAT
0.018623
0.000145
PROB>T
32.650726
49.610848
0
0
ESTIMATE
0.608044
0.007211
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.018623
0.000145
0.99352
NA
21956.064594
1
1.842262
TSTAT
32.650726
49.610848
PROB>T
0
0
Looks good! The error messages are gone, and the two sets of starting coefficients produce the same results. The fit is
still pretty bad, but now we can confidently interpret this bad fit to mean that the functional form may not be appropriate
for this data set.
Now we estimate the CES (Constant Elasticity of Substitution) function with constant returns to scale (equation 4).
Since that function is generalization of the ones we already estimated, we can use each of our previous estimates
(approximately, since some are only limiting cases) as a starting value. Since the linear equation was the best fit, let's
start with that. First we need to transform the coefficients of the linear equation into the space of equation 4. The
transformation requires solving a quadratic: we won't reproduce the algebra here. The result is: alpha =.906283, scale
=.341346. The power coefficient is 1.0 in the linear case. Thus we set the starting parameters as follows:
NLS Command: do scale = 0.341346, alpha = 0.906283, power = 0.999 ;
NLS
WARNING 2106
Condition number exceeds the current userset CONOPT CONDWARN.
Coefficient convergence
Iterations in current NLS estimation : 3
4 : GDP = SCALE*((1ALPHA)**(1+POWER)*LABOR**POWER+ALPHA**(1+POWER)*CAPITAL*
*POWER)**(1/POWER)
NOB = 24
NOVAR = 3 NCOEF = 3
RANGE: 1974A to 1997A
RSQ =
0.999969
F(3/21) =
NA
SER =
2.289339
DW(0) =
0.626473
MAX:HAT =
0.175807
DFFITS =
1.139234
COEF
ESTIMATE
SCALE
ALPHA
POWER
0.345009
0.909196
1.032347
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.002451
0.000876
0.004072
0.999966
NA
110.062542
16.188672
2.639811
TSTAT
140.774837
1038.367606
253.500175
PROB>T
0
0
0
This result is not as pleasant as one might hope. NLS has had to divide by zero during the course of its optimization,
probably because it tried the case where power = 0. This in itself does not indicate that the estimate is a bad one: in fact,
the fit is slightly better than the raw linear fit, and the coefficients seem to be far enough away from zero to make the
"division by zero" problem less worrisome. From a theoretical point of view, the value of the power coefficient is
unacceptable, since it implies anticomplementarity between labor in capital. In principle one would want to estimate
subject to a constraint that alpha cannot exceed 1.0. NLS does not provide a direct way to incorporate inequality
constraints. In this case, however, it seems likely that an equality constraint at 1.0 would produce the correct result. That
constraint simply leaves us with the linear equation, which we have already estimated.
Nonetheless, for completeness, we should try some alternatives. When we do so, we know we can expect to run into the
"division by zero" problem again  not to mention other possible problems like "invalid exponentiation". One way to
avoid these problems is to specify the equation in a "robust" form that treats special cases and extreme values
appropriately. TROLL's IF  THEN  ELSE operator makes such a robust specification possible:
NLS Command:
Arguments or
Arguments or
Arguments or
Arguments or
Arguments or
Arguments or
Continue eq:
Continue eq:
Arguments or
Arguments or
Arguments or
Arguments or ')':
// full Leontief
Arguments or ')':
min (alpha*capital, (1alpha)*labor) ) ) ) else (
Arguments or ')':
// general case
Arguments or ')':
((1alpha)**(1+power)*labor**power
Continue eq:
+alpha**(1+power)*capital**power ) **(1/power)
Continue eq:
) ) ) ;
MODEDIT Command: print equation 6 ;
Equations:
6: ROBUST
Estimating with the new equation produces the same results as with the old equation, as expected, although the
coefficients are reported in a different order, and of course the "division by zero" warning is gone.
MODEDIT Command: nls 6 ;
WARNING 2106
Condition number exceeds the current userset CONOPT CONDWARN.
Coefficient convergence
Iterations in current NLS estimation : 3
6 : GDP = SCALE*(IF (ABSV(POWER) < 0.0001) THEN (IF (ABSV(ALPHA) < 0.0001)
THEN LABOR ELSE (IF (ABSV(1ALPHA) < 0.0001) THEN CAPITAL ELSE
(SCALE*ALPHA**ALPHA*(1ALPHA)**(1ALPHA)*LABOR**(1ALPHA)*CAPITAL**ALPHA)))
ELSE (IF (POWER < 30) THEN (IF (ABSV(ALPHA) < 0.0001) THEN 0 ELSE (IF
(ABSV(1ALPHA) < 0.0001) THEN 0 ELSE (MIN(ALPHA*CAPITAL,(1ALPHA)*LABOR))))
ELSE (((1ALPHA)**(1+POWER)*LABOR**POWER+ALPHA**(1+POWER)*CAPITAL**POWER)**(1
/POWER))))
NOB = 24
NOVAR = 3 NCOEF = 3
RANGE: 1974A to 1997A
RSQ =
0.999969
F(3/21) =
NA
SER =
2.289339
DW(0) =
0.626473
MAX:HAT =
0.175807
DFFITS =
1.139234
COEF
SCALE
POWER
ALPHA
ESTIMATE
0.345009
1.032347
0.909196
CRSQ =
PROB>F =
SSR =
COND =
RSTUDENT =
STER
0.999966
NA
110.062542
16.188672
2.639811
TSTAT
0.002451
0.004072
0.000876
PROB>T
140.774837
253.500175
1038.367606
0
0
0
We'll also try starting with the CobbDouglas coefficients, although there's not much indication that the path is likely to
be fruitful. (The "division by zero" problem probably means that the algorithm has already covered this territory where power approaches zero.) The alpha in the CobbDouglas function is the same as in the CES function, so only the
scale coefficient has to be transformed, and the transformation is relatively straightforward, although we won't
reproduce it here. The result is as follows:
NLS Command: do scale = 0.129073, alpha = 0.521639, power = 0.01 ;
NLS Command: nls 6 ;
WARNING 2106
Condition number exceeds the current userset CONOPT CONDWARN.
Coefficient convergence
Iterations in current NLS estimation : 48
6 : GDP = SCALE*(IF (ABSV(POWER) < 0.0001) THEN (IF (ABSV(ALPHA) < 0.0001)
THEN LABOR ELSE (IF (ABSV(1ALPHA) < 0.0001) THEN CAPITAL ELSE
(SCALE*ALPHA**ALPHA*(1ALPHA)**(1ALPHA)*LABOR**(1ALPHA)*CAPITAL**ALPHA)))
ELSE (IF (POWER < 30) THEN (IF (ABSV(ALPHA) < 0.0001) THEN 0 ELSE (IF
(ABSV(1ALPHA) < 0.0001) THEN 0 ELSE (MIN(ALPHA*CAPITAL,(1ALPHA)*LABOR))))
ELSE (((1ALPHA)**(1+POWER)*LABOR**POWER+ALPHA**(1+POWER)*CAPITAL**POWER)**(1
/POWER))))
NOB = 24
NOVAR = 3 NCOEF = 3
RANGE: 1974A to 1997A
RSQ =
0.999969
F(3/21) =
NA
CRSQ =
PROB>F =
0.999966
NA
SER =
DW(0) =
MAX:HAT =
DFFITS =
COEF
SCALE
POWER
ALPHA
2.289351
0.626437
0.175747
1.137233
ESTIMATE
0.34501
1.032344
0.909198
SSR =
COND =
RSTUDENT =
STER
0.002447
0.004057
0.000873
110.063697
16.142543
2.635747
TSTAT
140.986177
254.440593
1041.949823
PROB>T
0
0
0
1. Purists may prefer to cast this situation as an "errors in variables" problem, since, arguably, the agent's response is not really a random response to the future
realization but a determined response to the agent's own (unobserved) expectations. In the present example, the fiction of perfect foresight is maintained.
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
3. Stacked Time
I. REPORTING AND SAVING RESULTS
1. Saving Results with SAVESIM and FILESIM
2. Printing Results with &PRTDSET
3. Plotting Results with &PLOT
A. STATIC SIMULATION
The "simplest" kind of model to simulate is a static, linear, singleequation model. Even with that kind of model,
TROLL may be able to save you some work. TROLL will find the endogenous variable for you, wherever in the
equation it may be buried. You need not do the algebra necessary to get a single instance of the endogenous variable
alone on the lefthand side. Just declare the variable as ENDOGENOUS when you set up the model.
The following "static multiplieraccelerator model" of national income determination provides an example. The model
is driven by export demand, which is "accelerated" via an investment demand effect and "multiplied" via a consumption
effect. The model also assumes that imports are a constant fraction of national income, thus inducing a "reverse
multiplier" effect as well. The model's one equation simply sets "total investment" (domestic investment plus exports)
equal to "total savings" (income plus imports minus private and public consumption).
SIMULATE Command: usemod ;
New model: (nameless)
TROLL Command: addsym exogenous x, policy g ;
MODEDIT Command: symcom x Export demand ;
MODEDIT Command: symcom g Government purchases ;
MODEDIT Command: addsym endogenous y ;
MODEDIT Command: symcom y National income/output ;
MODEDIT Command: addsym parameter t ;
MODEDIT Command: symcom t Tax rate ;
MODEDIT Command: addsym coefficient i c m ;
MODEDIT Command: symcom i Rate of investment "acceleration" as output increases ;
MODEDIT Command: symcom c Rate of consumption out of disposable income ;
MODEDIT Command: symcom m Fraction of national income spent on imports ;
MODEDIT Command: addeq bottom i*y + x = y + m*y  c*(yt*y)  g ;
MODEDIT Command: eqcom bottom Total investment equals total savings ;
MODEDIT Command: filemod static ;
TROLL Command: quit ;
TROLL Command: prtmod comment ;
Symbols:
ENDOGENOUS :
Y
 National income/output
EXOGENOUS :
X
 Export demand
POLICY :
G
 Government purchases
COEFFICIENT
C
I
M
:
 Rate of consumption out of disposable income
 Rate of investment "acceleration" as output increases
 Fraction of national income spent on imports
PARAMETER :
T
 Tax rate
Equations:
1:
Now we need some data with which to simulate. We'll use UK data starting in 1974.
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
Command:
Command:
delaccess all ;
delsave all ;
access ukdata type formdata id ukdata.frm ;
search after save ukdata ;
do m = 0.2, i = 0.1, c = 0.9 ;
do t = 0.2 ;
We are now ready to simulate. Begin by typing "simulate" to enter the simulation task. The simulator will perform its
model analysis and generate code for the simulation.
TROLL Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1974A to 1996A and must end by 1996A.
Before the actual simulation can begin, we must set a starting date (via the SIMSTART command). Also, if you want to see
output from the simulation, you must specify (via the LIST command) what output you want to see. (By default, TROLL
does not display simulation output.)
SIMULATE Command: simstart 1974a ;
SIMULATE Command: list solutions endogenous ;
Now the simulation can proceed. Just tell TROLL how many periods to stimulate (or, alternatively, specify the ending
date of the simulation with DOTIL.) Here we specify the number of periods with the DOSIM command.
SIMULATE Command: dosim 20 ;
Date:
What:
1974A
Solution: Y
1975A
Solution: Y
1976A
Solution: Y
1977A
Solution: Y
1978A
Solution: Y
1979A
Solution: Y
1980A
Solution: Y
1981A
Solution: Y
1982A
Solution: Y
1983A
Solution: Y
1984A
Solution: Y
1985A
Solution: Y
1986A
Solution: Y
1987A
Solution: Y
1988A
Solution: Y
1989A
Solution: Y
1990A
Solution: Y
1991A
Solution: Y
1992A
Solution: Y
1993A
Solution: Y
Value:
643.443592
651.818011
677.637951
676.814024
681.66083
697.070937
696.426682
683.491315
687.672408
710.637351
732.549304
743.408065
764.769522
783.888975
783.10673
816.017512
851.495137
854.515142
879.90721
896.346203
These results now exist in the simulator's temporary workspace. (Later you'll see how to make a permanent or
semipermanent copy.) The database still contains the original values of y, which might be interesting for comparison:
SIMULATE Command: do prtdata ( y[1974a::1993a] ) ;
Y[1974A::1993A]:
Numeric array 1 space dimension: 20
[ 1]:
[ 5]:
[ 9]:
[13]:
[17]:
490.503754
522.430111
556.528875
662.724722
663.012122
502.090007
515.689569
577.426575
677.189007
676.796721
Now you might want to try an experiment. Suppose we raise the tax rate from 20 percent to 30 percent.
SIMULATE Command: do t = 0.3 ;
Before we can simulate with the new tax rate, we have to inform the simulator that the data have changed. For this
purpose, use the NEWVALS command. You can select which variable(s) and time period(s) to reload. In this case we want
to reload "t", and the question of time period is moot, since "t" is a constant. However, the syntax requires that you
specify a time period, so try "all".
SIMULATE Command: newvals all t ;
Value:
520.230989
527.001796
547.877492
547.211339
551.130033
563.589268
563.068381
552.609999
555.990458
574.557858
592.273906
601.053329
618.324294
633.782576
633.150122
659.758839
688.442876
690.884583
711.41434
724.70544
A typical experiment would be to "shock" a POLICY variable and observe the effect on the simulation. Suppose, for
example, that government purchases had been 10 percent higher.
SIMULATE
SIMULATE
SIMULATE
SIMULATE
Date:
1974A
1975A
1976A
1977A
1978A
1979A
1980A
1981A
1982A
1983A
1984A
1985A
1986A
1987A
1988A
1989A
1990A
1991A
1992A
1993A
Command:
Command:
Command:
Command:
do g = 1.1*g ;
newvals all g ;
simstart 1974a ;
dosim 20 ;
What:
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Solution: Y
Value:
551.841974
559.870577
581.028232
578.806674
582.684785
595.504226
594.985724
583.66317
587.179967
607.169085
625.030223
633.108868
650.851969
666.170466
665.323164
693.143793
723.069976
725.990454
747.084652
760.470976
Interesting (perhaps). Since taxes and imports are fixed fractions of income, they damp the effect of the higher
government spending, and we see a "dividerdecelerator" effect in this perverse twist on John Maynard Keynes.
B. DYNAMIC SIMULATION
To make the model more interesting let's add some dynamics. Specifically, we will make two changes. First, let
investment depend on lagged output rather than current output. That way we have a true accelerator model. Second, let
consumption depend in part on past as well as present disposable income. We will introduce a new coefficient to control
its relative dependence on past and present income.
SIMULATE Command: addsym coefficient h ;
MODEDIT Command: symcom h
Comment or ';': Fraction of consumption based on prioryear income ;
MODEDIT Command: changeq /i*y/i*y(1)/ bottom ;
MODEDIT Command: changeq/(yt*y)/((1h)*(yt*y)+h*(y(1)t*y(1)))/bottom;
 Government purchases
COEFFICIENT
C
H
I
M
:

PARAMETER :
T
 Tax rate
Equations:
1:
Simulation proceeds as before. Note that we can no longer simulate for 1974, because a lagged data point is required,
and we do not have data for 1973.
TROLL Command: do h = 0.5 ;
TROLL Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1975A to 1996A and must end by 1996A.
SIMULATE Command: list solutions endogenous ;
SIMULATE Command: simstart 1975a ;
SIMULATE Command: dosim 20 ;
Date:
What:
Value:
1975A
Solution: Y
522.751796
1976A
Solution: Y
553.700863
1977A
Solution: Y
567.033893
1978A
Solution: Y
575.345666
1979A
Solution: Y
586.051342
1980A
Solution: Y
590.796155
1981A
Solution: Y
587.008016
1982A
Solution: Y
587.099335
1983A
Solution: Y
597.757846
1984A
Solution: Y
612.241481
1985A
Solution: Y
623.323596
1986A
Solution: Y
637.943184
1987A
Solution: Y
652.933944
1988A
Solution: Y
659.51353
1989A
Solution: Y
677.37367
1990A
Solution: Y
701.641764
1991A
Solution: Y
714.572707
1992A
Solution: Y
731.838938
1993A
Solution: Y
747.044653
1994A
Solution: Y
776.61174
C. MULTIPLEEQUATION SIMULATION
OK, enough of this single equation nonsense! We're going to make the model "more complicated" by adding more
equations, but the new model may be easier to understand than the old one. In particular, by dividing the existing model
into separate equations, each of whose meaning may be understood without explicit reference to the others, we clarify
the underlying behavioral assumptions. Given that TROLL is quite comfortable with "large" models, it is often
advantageous to isolate specific relationships in specific equations, so that the meaning remains (or becomes) clear. To
put it differently, solving models is TROLL's job, and it will seldom be with your while (or that of your readers,
colleagues, supervisors, assistants, etc.) to do part of TROLL's job for it.
We started out with a system of one equation in one endogenous variable. To divide the model into several equations,
we need to create more endogenous variables, since we must end up with the number of equations equal to the number
of endogenous variables. In TROLL's language, we need to add ENDOGENOUS symbols to the model; thus,
SIMULATE Command: addsym endogenous cons dominvest import totinvest totsave ;
MODEDIT Command: symcom cons Personal consumption ;
MODEDIT Command: symcom dominvest Domestic investment ;
MODEDIT Command: symcom import Total imports ;
MODEDIT Command: symcom totinvest Total investment ;
MODEDIT Command: symcom totsave Total saving ;
Now each of these variables can have its own equation, leaving a simple, selfexplanatory equation to embody the
fundamental identity.
MODEDIT Command: repeq 1 IS: totinvest = totsave ;
MODEDIT Command: addeq bottom TOTINV: totinvest = dominvest + x ;
MODEDIT Command: eqcom bottom Identity for "total investment" ;
MODEDIT Command: addeq bottom TOTSAV: totsave = y + import  cons  g ;
MODEDIT Command: eqcom bottom Identity for "total saving" ;
MODEDIT Command: addeq bottom CONS: cons=c*((1h)*(yt*y)+h*(y(1)t*y(1)));
MODEDIT Command: eqcom bottom Consumption function ;
MODEDIT Command: addeq bottom IMPORT: import = m*y ;
MODEDIT Command: eqcom bottom Import function ;
MODEDIT Command: addeq bottom INVEST: dominvest = i*y(1) ;
MODEDIT Command: eqcom bottom Investment function ;
MODEDIT Command: filemod simultaneous1 ;
TROLL Command: quit ;
TROLL Command: prtmod comment ;
Symbols:
ENDOGENOUS :
CONS
DOMINVEST IMPORT
TOTINVEST TOTSAVE
Y

Personal consumption
Domestic investment
Total imports
Total investment
Total saving
National income/output
EXOGENOUS :
X
 Export demand
POLICY :
G
 Government purchases
COEFFICIENT
C
H
I
M
:

PARAMETER :
T
 Tax rate
Equations:
Total investment equals total savings
1: IS
TOTINVEST = TOTSAVE
Identity for "total investment"
2: TOTINV
TOTINVEST = DOMINVEST+X
Identity for "total saving"
3: TOTSAV
TOTSAVE = Y+IMPORTCONSG
Consumption function
4: CONS
CONS = C*((1H)*(YT*Y)+H*(Y(1)T*Y(1)))
Import function
5: IMPORT
IMPORT = M*Y
Investment function
6: INVEST
DOMINVEST = I*Y(1)
We can simulate the model just as before, but, to save space, we'll list the solutions only for y, instead of including all
the new ENDOGENOUS symbols.
TROLL Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1975A to 1996A and must end by 1996A.
SIMULATE Command: list solutions y ;
SIMULATE Command: simstart 1975a ;
SIMULATE Command: dosim 20 ;
Date:
1975A
1976A
1977A
1978A
1979A
1980A
1981A
1982A
1983A
1984A
1985A
1986A
1987A
1988A
1989A
1990A
1991A
1992A
1993A
1994A
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
Solution:
What:
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Y
Value:
522.751796
553.700863
567.033893
575.345666
586.051342
590.796155
587.008016
587.099335
597.757846
612.241481
623.323596
637.943184
652.933944
659.51353
677.37367
701.641764
714.572707
731.838938
747.044653
776.61174
You might recognize those numbers. (Hint: Look at the previous simulation results.) Be aware that things don't always
turn out quite so neatly. Sometimes you can simulate two entirely equivalent models and get different results, due to
such phenomena as roundoff error, false convergence, and numerical instability. With linear models, that experience is
unlikely. With nonlinear models, life can get difficult.
Before we introduce nonlinearity into this model, we're going to add some more equations to model the role of foreign
exchange markets. First, the export demand equation makes total exports (previously exogenous) depend on the
exchange rate and on U.S. national income (a cheap substitute for "the rest of the world" in this simplified example).
Second, the exchange market equation states an (ad hoc) equilibrium condition in terms of the exchange rate and
relative interest rates (again with the U.S. as a cheap proxy for "the rest of the world").
SIMULATE Command: addsym policy r, exogenous yus rus, coefficient j f a b e0 ;
MODEDIT Command: addsym endogenous e ;
MODEDIT Command: changesym endogenous x ;
MODEDIT Command: symcom r Interest rate ;
MODEDIT Command: symcom e Exchange rate (US$ per Pound Sterling) ;
MODEDIT Command: symcom yus U.S. income ;
MODEDIT Command: symcom rus U.S. interest rate ;
MODEDIT Command: symcom j Investment sensitivity to interest rate ;
MODEDIT Command: symcom f Export sensitivity to foreign income ;
MODEDIT Command: symcom b Export sensitivity to exchange rate ;
MODEDIT Command: symcom a Exchange rate sensitivity to interest rate differential ;
MODEDIT Command: symcom e0 Parity exchange rate ;
MODEDIT Command: changeq /)/)  j*r/ invest ;
MODEDIT Command: addeq bottom EXPORT: x = f*yus  b*(ee0) ;
MODEDIT Command: eqcom bottom Export demand ;
MODEDIT Command: addeq bottom FOREX: r = rus + a*(ee0) ;
MODEDIT Command: eqcom bottom International financial market equilibrium ;
MODEDIT Command: filemod simultaneous2 ;
TROLL Command: quit ;
TROLL Command: prtmod comment ;
Symbols:
ENDOGENOUS :
CONS
DOMINVEST E
IMPORT
TOTINVEST TOTSAVE
X
Y

Personal consumption
Domestic investment
Exchange rate (US$ per Pound Sterling)
Total imports
Total investment
Total saving
Export demand
National income/output
EXOGENOUS :
RUS
 U.S. interest rate
YUS
 U.S. income
POLICY :
G
R
 Government purchases
 Interest rate
COEFFICIENT
A
B
C
E0
:

F
H
I
J
M
PARAMETER :
T
 Tax rate
Equations:
Total investment equals total savings
1: IS
TOTINVEST = TOTSAVE
Identity for "total investment"
2: TOTINV
TOTINVEST = DOMINVEST+X
Identity for "total saving"
3: TOTSAV
TOTSAVE = Y+IMPORTCONSG
Consumption function
4: CONS
CONS = C*((1H)*(YT*Y)+H*(Y(1)T*Y(1)))
Import function
5: IMPORT
IMPORT = M*Y
Investment function
6: INVEST
DOMINVEST = I*Y(1)J*R
Export demand
7: EXPORT
X = F*YUSB*(EE0)
International financial market equilibrium
8: FOREX
R = RUS+A*(EE0)
Again, the mechanics of using the simulator are unchanged. In the following example, we'll go back to listing all
endogenous solutions, since y by itself wouldn't really give much of the model's flavor.
TROLL Command: do j = 0.1, f = 0.03, a = 5, b = 50, e0 = 1 ;
TROLL Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1975A to 1996A and must end by 1996A.
SIMULATE Command: list solutions endogenous ;
SIMULATE Command: simstart 1975a ;
SIMULATE Command: dosim 20 ;
Date:
What:
Value:
1975A
Solution: X
83.896938
Y
511.081772
CONS
312.415561
DOMINVEST
47.054032
IMPORT
102.216354
TOTINVEST
130.95097
TOTSAVE
130.95097
E
1.879667
1976A
Solution: X
73.55765
Y
515.179463
CONS
323.272289
DOMINVEST
49.996094
IMPORT
103.035893
TOTINVEST
123.553743
TOTSAVE
123.553743
E
2.229333
1977A
Solution: X
117.450262
Y
557.999289
CONS
338.051307
DOMINVEST
50.749696
IMPORT
111.599858
TOTINVEST
168.199958
TOTSAVE
168.199958
E
1.482667
1978A
Solution: X
135.512193
Y
598.157684
CONS
364.189447
DOMINVEST
54.949512
IMPORT
119.631537
TOTINVEST
190.461705
TOTSAVE
190.461705
E
1.263334
1979A
Solution: X
123.93998
Y
605.512244
CONS
379.156027
DOMINVEST
58.518352
IMPORT
121.102449
TOTINVEST
182.458332
TOTSAVE
182.458332
1980A
Solution:
1981A
Solution:
1982A
Solution:
1983A
Solution:
1984A
Solution:
1985A
Solution:
1986A
Solution:
1987A
Solution:
1988A
Solution:
1989A
Solution:
1990A
Solution:
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
1.581
100.722194
582.328086
374.169704
58.889142
116.465617
159.611336
159.611336
2.037332
157.210333
630.542523
382.054242
56.841559
126.108505
214.051892
214.051892
0.9775
136.024024
630.192206
397.13144
61.825419
126.038441
197.849443
197.849443
1.334833
143.654636
647.199658
402.378437
62.006471
129.439932
205.661107
205.661107
1.3035
165.744856
681.004001
418.384153
63.725632
136.2008
229.470488
229.470488
1.084167
128.359624
650.258858
419.347801
66.876067
130.051772
195.235691
195.235691
1.953167
131.803753
642.63843
407.262646
63.931636
128.527686
195.735389
195.735389
1.992833
147.560188
656.192877
409.131862
63.29401
131.238575
210.854198
210.854198
1.784667
157.310428
672.239752
418.456278
64.586371
134.44795
221.896799
221.896799
1.732333
142.701582
669.935449
422.785188
65.835559
133.98709
208.53714
208.53714
2.154667
130.191574
661.876334
1991A
Solution:
1992A
Solution:
1993A
Solution:
1994A
Solution:
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
419.520712
65.517212
132.375267
195.708786
195.708786
2.454
139.934399
672.273649
420.257245
65.039383
134.45473
204.973782
204.973782
2.2215
145.532451
686.993255
428.169075
66.274865
137.398651
211.807316
211.807316
2.218667
182.505872
736.642441
448.445244
68.111992
147.328488
250.617864
250.617864
1.575167
206.02714
790.910505
481.179178
73.114077
158.182101
279.141218
279.141218
1.251
D. NONLINEAR SIMULATION
Before adding nonlinearities to the model, let's clarify what we mean by "nonlinear". From the point of view of
simulation, we are concerned only with nonlinearities in the calculated (endogenous) variables. Nonlinearities with
respect to other kinds of symbols are merely minor arithmetic problems, irrelevant to how the model will be solved.
(Note that variables designated by lagged ENDOGENOUS symbols are "exogenous" with respect to the current period.)
TROLL tells whether a model is linear by taking the first partial derivative of each equation with respect to each
endogenous variable. If any of those derivatives contains an endogenous variable, then the model is nonlinear.
More subtleties appear when the model is divided into minimal blocks of simultaneous equations. A given variable may
be endogenous with respect to the full model but exogenous with respect to a given block. If a variable appears
nonlinearly only in blocks where it is exogenous, then this nonlinearity is inconsequential. From TROLL's point of
view, a model containing only such "outofblock" nonlinearities is still a linear model. The model can be solved block
by block without any of the difficulties that nonlinearities could introduce. (You could solve such a model analytically
using only arithmetic and linear algebra.)
The following brief example introduces such "pseudononlinearities". The investment function becomes nonlinear in r,
but r is a POLICY symbol, exogenous to the model, so we still have a "linear model". The export equation becomes
nonlinear in e. Even though e is an ENDOGENOUS symbol, the exponent applied thereto does not fundamentally change the
characteristics of the solution procedure. Before solving the export demand equation (for a given year), you can
calculate the value of e from the foreign exchange market equation, in which it appears linearly. Thus, if we were to
simulate this new model, it would simply be another example of "linear simulation".
SIMULATE Command: addsym coefficient p s ;
MODEDIT Command: symcom p Investment function power parameter ;
MODEDIT Command: symcom s Export demand function power parameter ;
MODEDIT Command: changeq /j*r/j*r**p/ invest ;
MODEDIT Command: changeq /(e/(e**s/ export ;
MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
CONS DOMINVEST
EXOGENOUS :
IMPORT
TOTINVEST
TOTSAVE
RUS
YUS
POLICY :
G R
COEFFICIENT :
A B C E0
PARAMETER :
T
Equations:
1:
2:
3:
4:
5:
6:
7:
8:
IS
TOTINV
TOTSAV
CONS
IMPORT
INVEST
EXPORT
FOREX
TOTINVEST = TOTSAVE
TOTINVEST = DOMINVEST+X
TOTSAVE = Y+IMPORTCONSG
CONS = C*((1H)*(YT*Y)+H*(Y(1)T*Y(1)))
IMPORT = M*Y
DOMINVEST = I*Y(1)J*R**P
X = F*YUSB*(E**SE0)
R = RUS+A*(EE0)
... And now for something completely nonlinear... We'll revise the consumption function to incorporate a more
sophisticated habitformation specification with income in the denominator. Since there is no way to compute the
consumption function without solving simultaneously, TROLL is forced to deal with the nonlinearity.
MODEDIT Command: repeq cons cons: cons/cons(1)1 = c*(hcons(1)/(yt*y));
MODEDIT Command: filemod nonlinear ;
TROLL Command: quit ;
TROLL Command: prtmod comment ;
Symbols:
ENDOGENOUS :
CONS
DOMINVEST E
IMPORT
TOTINVEST TOTSAVE
X
Y

Personal consumption
Domestic investment
Exchange rate (US$ per Pound Sterling)
Total imports
Total investment
Total saving
Export demand
National income/output
EXOGENOUS :
RUS
 U.S. interest rate
YUS
 U.S. income
POLICY :
G
R
 Government purchases
 Interest rate
COEFFICIENT
A
B
C
E0
F
H
I
J
M
P
S
:

PARAMETER :
T
 Tax rate
Equations:
Total investment equals total savings
1: IS
TOTINVEST = TOTSAVE
Identity for "total investment"
2: TOTINV
TOTINVEST = DOMINVEST+X
Identity for "total saving"
3: TOTSAV
TOTSAVE = Y+IMPORTCONSG
Consumption function
4: CONS
CONS/CONS(1)1 = C*(HCONS(1)/(YT*Y))
Import function
5: IMPORT
IMPORT = M*Y
Investment function
6: INVEST
DOMINVEST = I*Y(1)J*R**P
Export demand
7: EXPORT
X = F*YUSB*(E**SE0)
International financial market equilibrium
8: FOREX
R = RUS+A*(EE0)
TROLL Command: do p = 0.5, j = 0.2, c = 0.3, h = 0.9, s = 1.2 ;
TROLL Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1975A to 1996A and must end by 1996A.
SIMULATE Command: list solutions endogenous ;
SIMULATE Command: simstart 1975a ;
SIMULATE Command: dosim 20 ;
Date:
What:
Value:
1975A
Solution: X
71.253316
Y
489.293848
CONS
298.534253
DOMINVEST
47.433453
IMPORT
97.85877
TOTINVEST
118.686768
TOTSAVE
118.686768
E
1.879667
1976A
Solution: X
54.172418
Y
477.473086
CONS
299.143536
DOMINVEST
48.262426
IMPORT
95.494617
TOTINVEST
102.434845
TOTSAVE
102.434845
E
2.229333
1977A
Solution: X
111.374754
Y
523.847198
CONS
306.701039
DOMINVEST
47.192962
IMPORT
104.76944
TOTINVEST
158.567716
TOTSAVE
158.567716
E
1.482667
1978A
Solution: X
132.488984
Y
553.410654
CONS
316.66425
DOMINVEST
51.801482
IMPORT
110.682131
TOTINVEST
184.290465
TOTSAVE
184.290465
E
1.263334
1979A
Solution: X
116.356004
Y
550.003093
CONS
324.026701
DOMINVEST
54.620672
IMPORT
110.000619
TOTINVEST
170.976676
TOTSAVE
170.976676
E
1.581
1980A
Solution: X
85.141184
Y
525.138779
CONS
325.827751
DOMINVEST
54.184936
IMPORT
105.027756
TOTINVEST
139.32612
TOTSAVE
139.32612
E
2.037332
1981A
Solution: X
157.432279
Y
588.531106
CONS
336.492265
DOMINVEST
51.767889
IMPORT
117.706221
TOTINVEST
209.200168
TOTSAVE
209.200168
E
0.9775
1982A
Solution: X
132.05543
Y
579.182492
CONS
343.561781
DOMINVEST
58.152016
IMPORT
115.836498
TOTINVEST
190.207446
TOTSAVE
190.207446
E
1.334833
1983A
Solution: X
140.106456
Y
598.112668
CONS
351.746925
1984A
Solution:
1985A
Solution:
1986A
Solution:
1987A
Solution:
1988A
Solution:
1989A
Solution:
1990A
Solution:
1991A
Solution:
1992A
Solution:
1993A
Solution:
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
57.281775
119.622534
197.388231
197.388231
1.3035
164.861604
629.947203
362.544273
59.180606
125.989441
224.042209
224.042209
1.084167
114.368359
589.369787
364.853336
62.294911
117.873957
176.66327
176.66327
1.953167
117.069346
592.10352
367.011408
58.27539
118.420704
175.344735
175.344735
1.992833
136.600252
612.011237
371.780331
58.587509
122.402247
195.187761
195.187761
1.784667
147.249073
626.452471
377.600924
60.558343
125.290494
207.807416
207.807416
1.732333
124.824368
616.460476
380.427974
61.900018
123.292095
186.724386
186.724386
2.154667
106.059993
605.564892
380.718187
60.877586
121.112978
166.937579
166.937579
2.454
120.70905
621.351579
383.536721
59.878772
124.270316
180.587822
180.587822
2.2215
126.364834
633.187816
387.527124
61.517906
126.637563
187.88274
187.88274
2.218667
175.013668
684.017869
398.065871
62.834082
136.803574
237.84775
1994A
Solution:
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
237.84775
1.575167
203.161924
726.626058
412.084461
67.932674
145.325212
271.094599
271.094599
1.251
E. USING FUNCTIONS
You can use any of the following functions in TROLL simulations:
ABSV
ARCTAN
LOG
MIN
SIGN
ARCCOS
COS
LOG10
MINARG
SIN
ARCCOT
COTAN
MAX
PNORM
SQRT
ARCSIN
EXP
MAXARG
SELECT
TAN
CEILING
FLOOR
ROUND
ROUNDUP
TRUNCATE
Basically those are the standard arithmetic functions (the trigonometric functions, logarithms, exponential, and square
root) plus the normal probability function and several interesting nonsmooth functions (ABSV, SIGN, MIN, MAX, MINARG,
MAXARG, SELECT, CEILING, FLOOR, ROUND, ROUNDUP, and TRUNCATE). As you might expect, the nonsmooth functions can
make models difficult (often impossible) to solve, but they can also be very useful. Economists frequently find
themselves in the position of trying to model phenomena that either are inherently nonsmooth or exhibit critical
inequality constraints that cannot easily be captured with smooth functional forms. A classic example is the nominal
interest rate, which cannot go below zero even when conditions might seem to warrant it.
In the following example, we place such an inequality constraint on domestic investment, and we recast the exchange
rate as a logarithm.
SIMULATE Command: changeq ?ee0?log(e/e0)? forex ;
MODEDIT Command: changeq ?e**se0?log(e**s/e0)? export ;
MODEDIT Command: repeq invest invest: dominvest = max ( 0, i*y(1)  j*r**p ) ;
MODEDIT Command: filemod functions ;
TROLL Command: quit ;
TROLL Command: prtmod comment ;
Symbols:
ENDOGENOUS :
CONS
DOMINVEST E
IMPORT
TOTINVEST TOTSAVE
X

Personal consumption
Domestic investment
Exchange rate (US$ per Pound Sterling)
Total imports
Total investment
Total saving
Export demand
 National income/output
EXOGENOUS :
RUS
 U.S. interest rate
YUS
 U.S. income
POLICY :
G
R
 Government purchases
 Interest rate
COEFFICIENT
A
B
C
E0
F
H
I
J
M
P
S
:

PARAMETER :
T
 Tax rate
FUNCTION :
LOG MAX
Equations:
Total investment equals total savings
1: IS
TOTINVEST = TOTSAVE
Identity for "total investment"
2: TOTINV
TOTINVEST = DOMINVEST+X
Identity for "total saving"
3: TOTSAV
TOTSAVE = Y+IMPORTCONSG
Consumption function
4: CONS
CONS/CONS(1)1 = C*(HCONS(1)/(YT*Y))
Import function
5: IMPORT
IMPORT = M*Y
Investment function
6: INVEST
DOMINVEST = MAX(0,I*Y(1)J*R**P)
Export demand
7: EXPORT
X = F*YUSB*LOG(E**S/E0)
International financial market equilibrium
8: FOREX
R = RUS+A*LOG(E/E0)
TROLL Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1975A to 1996A and must end by 1996A.
SIMULATE Command: list solutions endogenous ;
SIMULATE Command: simstart 1975a ;
SIMULATE Command: dosim 20 ;
Date:
What:
Value:
1975A
Solution: X
75.100272
Y
492.974353
CONS
299.103903
DOMINVEST
47.433453
IMPORT
98.594871
TOTINVEST
122.533724
TOTSAVE
122.533724
E
2.410096
1976A
Solution: X
61.264358
Y
485.088512
CONS
300.822057
DOMINVEST
48.630477
IMPORT
97.017702
TOTINVEST
109.894835
TOTSAVE
109.894835
E
3.418948
1977A
Solution: X
112.623594
Y
526.97903
CONS
308.448855
DOMINVEST
47.954505
IMPORT
105.395806
TOTINVEST
160.578099
TOTSAVE
160.578099
E
1.62039
1978A
Solution: X
132.878862
1979A
Solution:
1980A
Solution:
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
555.368951
318.311144
52.114665
111.07379
184.993527
184.993527
1.301261
118.130002
553.073823
325.741751
54.816502
110.614765
172.946504
172.946504
1.787825
90.348872
531.679348
328.161673
54.492009
106.33587
144.840882
144.840882
2.821679
WARNING 15046
Expression cannot be evaluated.
In residual for equation 8:
LOG'F(E'N/E0'C)
Date: 1981A; Block: 2; Iteration: 2;
 attempt to take log of a nonpositive number
(This WARNING will not be repeated during this block.)
1981A
Solution:
1982A
Solution:
1983A
Solution:
1984A
Solution:
1985A
Solution:
1986A
Solution:
1987A
Solution:
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
157.435419
590.882661
338.656935
52.421946
118.176532
209.857364
209.857364
0.97775
132.675743
581.576213
345.578776
58.387172
116.315243
191.062915
191.062915
1.397706
140.619644
600.304881
353.625021
57.521147
120.060976
198.14079
198.14079
1.354591
164.903193
631.58498
364.248795
59.399827
126.316996
224.30302
224.30302
1.08781
118.827961
595.042316
367.036991
62.458689
119.008463
181.28665
181.28665
2.59391
121.875437
598.842809
369.725211
58.842643
119.768562
180.718079
180.718079
2.69887
139.713523
617.593648
374.692023
1988A
Solution:
1989A
Solution:
1990A
Solution:
1991A
Solution:
1992A
Solution:
1993A
Solution:
1994A
Solution:
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
X
Y
CONS
DOMINVEST
IMPORT
TOTINVEST
TOTSAVE
E
59.261438
123.51873
198.974961
198.974961
2.191676
149.987155
631.70768
380.610851
61.116584
126.341536
211.10374
211.10374
2.079926
131.154916
625.21199
384.073723
62.425539
125.042398
193.580455
193.580455
3.172965
115.651588
618.292702
385.524813
61.752737
123.65854
177.404325
177.404325
4.2802
127.719407
632.765209
388.949938
61.151553
126.553042
188.870961
188.870961
3.392272
133.345785
644.872959
393.426982
62.659269
128.974592
196.005054
196.005054
3.382674
176.754206
691.1097
403.667015
64.002597
138.22194
240.756803
240.756803
1.777426
203.51714
731.800002
417.228794
68.641857
146.36
272.158997
272.158997
1.28531
Take a close look at 1980. Obviously there was a problem. The solution algorithm found itself wandering into
arithmetically impossible territory  an inevitable hazard when you work with functions, such as logarithms, that have
limited domains. In this case the algorithm was able to recover and find a solution. (As it happens, the algorithm ended
up with the correct solution in this case; the illegal values were an irrelevant detour.) There is no general presumption
that the algorithm will be able to recover in that kind of situation. A later chapter discusses what to do when it can't.
F. FORWARDLOOKING SIMULATION
Everything so far has simply been a prelude. We're now ready for the main event: forwardlooking simulation. Forwardlooking simulation makes sure that the implicit expectations of agents in the model are consistent with the model itself.
Thus one avoids the danger that changes in policy would render the model invalid by changing the way agents form
expectations. In our model, we'll introduce forwardlooking behavior by replacing the ad hoc foreign exchange market
equation with one that has a rational basis  namely, the interest parity condition.
SIMULATE Command: repeq forex forex: (1+r/100) = (e/e(+1))*(1+rus/100) ;
MODEDIT Command: filemod forward ;
Personal consumption
Domestic investment
Exchange rate (US$ per Pound Sterling)
Total imports
Total investment
Total saving
Export demand
National income/output
EXOGENOUS :
RUS
 U.S. interest rate
YUS
 U.S. income
POLICY :
G
R
 Government purchases
 Interest rate
COEFFICIENT
A
B
C
E0
F
H
I
J
M
P
S
:

PARAMETER :
T
 Tax rate
FUNCTION :
LOG MAX
Equations:
Total investment equals total savings
1: IS
TOTINVEST = TOTSAVE
Identity for "total investment"
2: TOTINV
TOTINVEST = DOMINVEST+X
Identity for "total saving"
3: TOTSAV
TOTSAVE = Y+IMPORTCONSG
Consumption function
4: CONS
CONS/CONS(1)1 = C*(HCONS(1)/(YT*Y))
Import function
5: IMPORT
IMPORT = M*Y
Investment function
6: INVEST
DOMINVEST = MAX(0,I*Y(1)J*R**P)
Export demand
7: EXPORT
X = F*YUSB*LOG(E**S/E0)
International financial market equilibrium
8: FOREX
1+R/100 = E/E(+1)*(1+RUS/100)
If you try to simulate the model now using the simple SIMULATE command, you won't get a true forwardlooking
simulation. Without the explicit STACK option, TROLL will simply treat ENDOGENOUS symbols with leads as if they were
exogenous. What you get is a "perfectly empirical foresight" simulation, which could be interesting, but probably not
very useful for studying policy.
TROLL Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
WARNING 15081
'STACK' not specified for ForwardLooking simulation  'NOFL' assumed.
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1975A to 1995A and must end by 1995A.
Never mind that. Here's what a real forwardlooking simulation looks like:
[1991A]
[1992A]
[1993A]
[1994A]
IMPORT [1975A]
[1976A]
[1977A]
[1978A]
[1979A]
[1980A]
[1981A]
[1982A]
[1983A]
[1984A]
[1985A]
[1986A]
[1987A]
[1988A]
[1989A]
[1990A]
[1991A]
[1992A]
[1993A]
[1994A]
TOTINVEST [1975A]
[1976A]
[1977A]
[1978A]
[1979A]
[1980A]
[1981A]
[1982A]
[1983A]
[1984A]
[1985A]
[1986A]
[1987A]
[1988A]
[1989A]
[1990A]
[1991A]
[1992A]
[1993A]
[1994A]
TOTSAVE [1975A]
[1976A]
[1977A]
[1978A]
[1979A]
[1980A]
[1981A]
[1982A]
[1983A]
[1984A]
[1985A]
[1986A]
[1987A]
[1988A]
[1989A]
[1990A]
[1991A]
[1992A]
[1993A]
[1994A]
E [1975A]
[1976A]
[1977A]
[1978A]
[1979A]
[1980A]
[1981A]
[1982A]
[1983A]
[1984A]
[1985A]
[1986A]
[1987A]
[1988A]
[1989A]
[1990A]
[1991A]
[1992A]
[1993A]
64.886537
66.293179
68.370267
70.153609
95.802009
98.138854
99.212223
101.353656
103.443659
104.530337
105.619519
105.821131
109.066826
112.52092
114.275324
117.341488
120.062112
122.951169
127.145287
131.128507
133.820862
137.709933
141.245444
145.53403
107.984283
117.373374
128.62792
137.590971
143.568178
145.680038
152.518915
149.729533
156.860219
170.444955
178.397719
187.34387
197.010446
207.669582
217.544586
225.196572
229.323341
239.566902
249.876906
260.625513
107.984283
117.373374
128.62792
137.590971
143.568178
145.680038
152.518915
149.729533
156.860219
170.444955
178.397719
187.34387
197.010446
207.669582
217.544586
225.196572
229.323341
239.566902
249.876906
260.625513
3.071473
2.948854
2.785738
2.723305
2.690258
2.621081
2.50451
2.506983
2.469606
2.435576
2.426253
2.323235
2.219281
2.139909
2.068888
1.964006
1.839591
1.73881
1.642073
[1994A]
1.597469
Notice that this simulation makes foresight completely endogenous during the simulation period. Given that we are
simulating over 20 years of annual data, the option "stack 20" implies that the entire time period will be solved as a
unit. No empirical values can creep in to the endogenous variables (except for the terminal value, of course).
Forwardlooking simulation makes it possible to evaluate policy alternatives without fear of the Lucas critique. The
simplest way to examine the implications of a particular policy shock is to begin with an artificial, easily understood set
of baseline data. After simulating with the baseline data, you can apply a policy shock and compare the resulting
simulation. In the following example we begin with a passive interestrate policy that simply tracks the U.S.
interestrate.
SIMULATE
SIMULATE
SIMULATE
SIMULATE
SIMULATE
SIMULATE
Date:
1975A
Command:
Command:
Command:
Command:
Command:
Command:
do r = rus ;
newvals 1974a to 1995a r ;
simstart 1975a ;
delist solutions all ;
list solutions e ;
dosim 20 ;
What:
Value:
Solution: E [1975A]
1.578466
[1976A]
1.578466
[1977A]
1.578466
[1978A]
1.578466
[1979A]
1.578466
[1980A]
1.578466
[1981A]
1.578466
[1982A]
1.578466
[1983A]
1.578466
[1984A]
1.578466
[1985A]
1.578466
[1986A]
1.578466
[1987A]
1.578466
[1988A]
1.578466
[1989A]
1.578466
[1990A]
1.578466
[1991A]
1.578466
[1992A]
1.578466
[1993A]
1.578466
[1994A]
1.578466
SIMULATE Command: savesim fixedrate : e ;
The last statement saves these results for future use. (Saving simulation results will be covered in greater detail later.)
The pattern in these results is obvious. The reason should be fairly obvious, too. Our foreign exchange market equation
implies that agents will set exchange rates so as to effect interestrate parity, but our artificial data has interestrate parity
built in. Accordingly, the equilibrium exchange rate is always whatever it is anticipated to be in the future. With perfect
foresight, there is never any reason for the exchange rate to change.
Now for the shock. We will raise the interest rate by one percentage point during the 19801983 period.
SIMULATE
SIMULATE
SIMULATE
SIMULATE
Date:
1975A
Command:
Command:
Command:
Command:
Since we still have "stack 20", the shock is "fully anticipated": all exchange rate values are endogenous, and agents
have perfect foresight. Consequently, they set the initial exchange rate high enough to allow for the exchange rate
decline that must take place during the shock period.
You might be interested in studying unanticipated shocks. Unfortunately, simulating with unanticipated shocks is in
general rather difficult, and certainly beyond the scope of "basic simulation". However, we can do a simple "myopic
foresight" simulation by changing the STACK parameter and using the baseline results as input data.
The STACK parameter causes values for ENDOGENOUS symbols with leads to be taken as exogenous (that is, taken from the
input data) at regular intervals. Thus far we have been setting STACK to its maximum value so that only the terminal
values are exogenous. (Obviously, exogenous terminal values are unavoidable, although there are ways to set terminal
values logically.) Normally one might choose a lower STACK value either to speed up the calculations or to prevent the
logic of the dynamic model from being carried too far. As the following example shows, you can also use the STACK
parameter to prevent agents from anticipating a particular shock.
We begin by making the results of the baseline simulation available as the preferred data source. As a result,
"exogenous" values for ENDOGENOUS symbols with leads will be the values that would have resulted from static
expectations.
SIMULATE Command: search first save_fixedrate ;
Then we set the STACK parameter equal to the number of years before the shock begins. Instead of anticipating the shock,
agents will anticipate baseline results for the year prior to the shock.
SIMULATE Command: simulate stack 5 ;
Constructing stackedtime incidence matrix and code.
Simulations can start from 1975A to 1993A and must end by 1993A.
SIMULATE Command: list solutions e ;
SIMULATE Command: simstart 1975a ;
The simulation must end by 1993 because it applies a lead to data from the baseline simulation, which ended in 1994.
The length of the simulation period must be a multiple of the STACK parameter, so the maximum is 15 years.
SIMULATE Command: dosim 15 ;
Date:
What:
1975A
Solution: E [1975A]
[1976A]
[1977A]
[1978A]
[1979A]
1980A
Solution: E [1980A]
[1981A]
[1982A]
[1983A]
[1984A]
1985A
Solution: E [1985A]
[1986A]
[1987A]
[1988A]
[1989A]
Value:
1.578466
1.578466
1.578466
1.578466
1.578466
1.636049
1.621498
1.607401
1.593
1.578466
1.578466
1.578466
1.578466
1.578466
1.578466
This is the familiar "currency market overshooting" pattern that should result from unanticipated interestrate shocks. In
this particular model the interest rate is a discretionary policy variable, so it is not really meaningful to talk about a new
equilibrium that gets "overshot". However, the basic pattern is there.
For contrast, here's what the simulation looks like using empirical data instead of the contrived baseline case:
SIMULATE Command: delsave r fixedrate_e ;
SIMULATE Command: delsearch save_fixedrate ;
SIMULATE Command: newvals 1974a to 1995a all ;
WARNING 9020
NEWVALS assumes daterange is ALL for constant symbols:
A B C E0 F H I J M P S T
SIMULATE Command: simstart 1975a ;
SIMULATE Command: dosim 15 ;
Date:
What:
1975A
Solution: E [1975A]
[1976A]
[1977A]
[1978A]
Value:
2.726016
2.617189
2.472418
2.417008
1980A
Solution:
1985A
Solution:
[1979A]
E [1980A]
[1981A]
[1982A]
[1983A]
[1984A]
E [1985A]
[1986A]
[1987A]
[1988A]
[1989A]
2.387678
1.400427
1.338144
1.339465
1.319494
1.301312
2.204761
2.111147
2.016683
1.944557
1.88002
Personal consumption
Domestic investment
Exchange rate (US$ per Pound Sterling)
Total imports
Total investment
Total saving
Export demand
National income/output
EXOGENOUS :
RES_CONS  Add factor for consumption
RES_DOMINVEST
 Add factor for domestic investment
RES_E
 Add factor for exchange rate
RES_IMPORT Add factor for imports
RES_X
 Add factor for exports
RUS
 U.S. interest rate
YUS
 U.S. income
POLICY :
G
R
 Government purchases
 Interest rate
COEFFICIENT :
A
B
C
E0
F
H
I
J
M
P
S
PARAMETER :
T
 Tax rate
FUNCTION :
LOG MAX
Equations:
Total investment equals total savings
1: IS
TOTINVEST = TOTSAVE
Identity for "total investment"
2: TOTINV
TOTINVEST = DOMINVEST+X
Identity for "total saving"
3: TOTSAV
TOTSAVE = Y+IMPORTCONSG
Consumption function
4: CONS
(CONSRES_CONS)/CONS(1)1 = C*(HCONS(1)/(YT*Y))
Import function
5: IMPORT
IMPORT = RES_IMPORT+M*Y
Investment function
6: INVEST
DOMINVEST = RES_DOMINVEST+MAX(0,I*Y(1)J*R**P)
Export demand
7: EXPORT
X = RES_X+F*YUSB*LOG(E**S/E0)
International financial market equilibrium
8: FOREX
1+R/100 = (ERES_E)/E(+1)*(1+RUS/100)
To keep the add factors in units that we understand, we have added them directly to the variables being determined,
rather than to the equations. An alternative approach would be to have the add factors as additional terms in each
equation (as they are in all except the consumption and exchange rate equations here).
To calculate the add factors, we'll temporarily change them from EXOGENOUS to ENDOGENOUS and change the
corresponding ENDOGENOUS variables to EXOGENOUS.
TROLL Command: changesym endogenous res_* ;
MODEDIT Command: changesym exogenous cons dominvest e import x ;
Initially, we set the add factors to zero to provide starting values for the calculation.
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
Command:
Command:
Command:
Command:
Command:
do
do
do
do
do
res_cons = 0 ;
res_import = 0 ;
res_dominvest = 0 ;
res_x = 0 ;
res_e = 0 ;
Finally, we ask TROLL to solve for the add factors. We could use the SIMULATE command, but that command would
cause TROLL to solve the equations simultaneously, which isn't really necessary. For efficiency, we'll use the FORECAST
command instead, to get nonsimultaneous solutions.
MODEDIT Command: forecast ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1975A to 1995A and must end by 1995A.
Also for efficiency, we choose the SIMPER option, which causes TROLL to use input data for lags and leads instead of
solving for them.
SIMULATE Command: simper 1 ;
The rest of the add factor calculation process is like an ordinary simulation.
We save the calculated add factors (from the current "simulation" results) for use in future simulations and direct
TROLL to look for them in the saved location.
SIMULATE Command: savesim calculated : res_* ;
SIMULATE Command: search first save_calculated ;
Now we can do simulations using the add factors. First we reload the original model (where the add factors were
EXOGENOUS).
SIMULATE Command: usemod addfactors ;
In the new baseline simulation, the results will approximately equal the empirical data. Partly because of statistical
discrepancies and partly because of imprecise modelling, the results don't match exactly.
TROLL Command: simulate stack 20 ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Constructing stackedtime incidence matrix and code.
Simulations can start from 1975A to 1994A and must end by 1994A.
SIMULATE Command: simstart 1975a ;
SIMULATE Command: list solutions e y ;
SIMULATE Command: dosim 20 ;
Date:
What:
Value:
1975A
Solution: Y [1975A]
492.09025
[1976A]
508.299805
[1977A]
520.927206
[1978A]
539.619642
[1979A]
555.603511
[1980A]
545.435939
[1981A]
539.426739
[1982A]
549.257392
[1983A]
569.960853
[1984A]
583.524897
[1985A]
604.830771
[1986A]
630.335845
[1987A]
659.821161
[1988A]
691.783625
[1989A]
707.28617
[1990A]
711.124786
[1991A]
698.609401
[1992A]
695.817307
[1993A]
710.077871
[1994A]
739.986593
E [1975A]
2.221809
[1976A]
1.806206
[1977A]
1.745512
[1978A]
1.919495
[1979A]
2.121552
[1980A]
2.326282
[1981A]
2.027905
[1982A]
1.750519
[1983A]
1.516993
[1984A]
1.336333
[1985A]
1.296331
[1986A]
1.467006
[1987A]
1.638902
[1988A]
1.781361
[1989A]
1.639703
[1990A]
1.784713
[1991A]
1.769367
[1992A]
1.765524
[1993A]
1.502019
[1994A]
1.531605
SIMULATE Command: savesim baseline : e y ;
SIMULATE Command: do prtdata (e, y) ;
E:
E = ER
Numeric scalar timeseries Time dimension: Periodicity 1,
1974A:
1978A:
2.221809
2.121552
1.806206
2.326282
1.745512
2.027905
1982A:
1986A:
1990A:
1994A:
1.750519
1.467006
1.784713
1.531605
1.516993
1.638902
1.769367
1.578466
1.336333
1.781361
1.765524
1.56174
1.296331
1.639703
1.502019
Y:
Y = GDP
Numeric scalar timeseries Time dimension: Periodicity 1,
1974A:
1978A:
1982A:
1986A:
1990A:
1994A:
477.250849
533.975668
543.892823
631.143779
666.540362
725.266102
490.503754
522.430111
556.528875
662.724722
663.012122
742.300049
502.090007
515.689569
577.426575
677.189007
676.796721
Now we will apply a shock to the data and observe the result. Specifically we will raise the interest rate by five
percentage points during the years 1983 through 1986.
SIMULATE
SIMULATE
SIMULATE
SIMULATE
SIMULATE
Date:
1975A
Command:
Command:
Command:
Command:
Command:
Interestingly, the impact on output in this model is minimal  no larger than the discrepancy that already existed in the
output series.
H. CHOOSING AN ALGORITHM
TROLL offers a choice of solution algorithms. In most situations, the defaults do just fine. However, if you plan to do a
lot of nonlinear simulation, it will probably be worthwhile to familiarize yourself with the options. This section
describes them very briefly.
1. NewtonRaphson
The default NewtonRaphson algorithm works by repeatedly solving the model's linear approximation using
partial derivatives. This procedure converges very quickly in the neighborhood of the model's solution, and it
avoids the need to normalize the model (associate specific variables with specific equations), thus avoiding
possible nonassignability issues and other difficulties that can plague normalization attempts. Unless your
model is highly nonlinear and you expect the solutions to contain precipitous jumps from one time period to the
next (so that a starting guess based on the previous period will often be far from the current period's solution),
the default algorithm is probably the best.
3. Stacked Time
There is OLDSTACK and NEWSTACK (the default). NEWSTACK is usually better.
You can also use the FairTaylor macro (&FT), but why bother?
variables. Then you can refer to an archive called "save_results" (if, as by default, the SAVE database was your
first writable SEARCH rule), which will contain the simulated values.
FILESIM
operates similarly, but it saves the results to a permanent file. For details, see the Reference Manual.
2.339042
2.221809
1.806206
1.745512
1.919495
2.121552
2.326282
2.027905
1.750519
1.516993
1.336333
1.296331
1.467006
1.638902
1.781361
1.639703
1.784713
1.769367
1.765524
1.502019
1.531605
1.578466
1.56174
BASELINE
NA
2.221809
1.806206
1.745512
1.919495
2.121552
2.326282
2.027905
1.750519
1.516993
1.336333
1.296331
1.467006
1.638902
1.781361
1.639703
1.784713
1.769367
1.765524
1.502019
1.531605
NA
NA
SHOCKED
NA
2.587473
2.157272
2.077159
2.243709
2.441832
2.638326
2.326071
2.048979
1.811003
1.555662
1.448927
1.544328
1.638902
1.781361
1.639703
1.784713
1.769367
1.765524
1.502019
1.531605
NA
NA
480.713658
477.250849
490.503754
502.090007
519.448436
533.975668
522.430111
515.689569
524.60376
543.892823
556.528875
577.426575
602.162089
631.143779
662.724722
677.189007
679.875902
666.540362
663.012122
676.796721
706.007872
725.266102
BASELINE
NA
492.09025
508.299805
520.927206
539.619642
555.603511
545.435939
539.426739
549.257392
569.960853
583.524897
604.830771
630.335845
659.821161
691.783625
707.28617
711.124786
698.609401
695.817307
710.077871
739.986593
NA
SHOCKED
NA
483.325809
496.443967
507.992739
526.698394
542.83232
532.898726
525.851682
534.016605
552.810554
567.023138
590.364488
619.443691
652.745565
685.811252
702.207385
706.825493
694.974416
692.712447
707.413774
737.692827
NA
If you use the Windows "GUI" version of TROLL, you can plot your results using the &PLOT macro. The
following description is taken from MACROS.TXT (an "undocumented documentation file" included in the
standard TROLL installation):
===============================================================================
&PLOT
Displays timeseries in graphical representation in a separate window.
(&PLOT is only available in the TROLLforWindows GUI version. There
are different versions of &PLOT for the 1.x GUI and the 2.x GUI. This
description applies to the 1.x GUI, although most of the information
is also relevant for the 2.x GUI; see TRGraphics.pdf for the complete
manual for the more flexible &PLOT for the 2.x GUI.)
Format:
keyword =
VALUE
ER
FD
PCER
PCFD
COMPlete
ALPHA
NAFILL
argument =
DSETs aliasname... or
ARCHive aliasname... or
PREFIX aliasname...
RANGE rangespec...
VARIables varspec...
rangespec =
varspec =
variable
symboltype
@varlist
ALL
variable =
a variable name
varlist =
Usage:
Utility macro
The keyword FD (first difference) computes the absolute difference between the
current value for a variable and its value in the previous time period. PCFD
computes the relative first difference, i.e., the percent first difference,
using the previous value as the divisor, multiplied by 100. ER and PCER compute
the difference between the values stored in two ARCHIVEs for a given variable on
a given date. ER and PCER are valid only if two or more ARCHIVEs are named in
the ARCHIVE argument. The first ARCHIVE named in the argument is used as the
base; subsequent ARCHIVEs are compared to this base. The keyword ER computes
the absolute difference (error) between the values. PCER computes the relative
error, i.e., the percent error, using the value in the base DSET as the divisor,
multiplied by 100.
In displaying the keyword values, the ER and PCER values are associated with the
ARCHIVE argument, and the FD and PCFD values are associated with the VARIABLES
argument.
Notes:
1. variable MUST be a time series.
2. Observations for specified variables in varspec within the specified data
RANGE can not have NA values (&PLOT macro can't display gaps in the graph).
Use the NAFILL keyword to replace NAs with zeros.
3. &PLOT macro is available only in the GUI version of TROLL for Windows.
4. If VARIables are specified by symbol type (e.g., "endogenous"), symboltype
(e.g., "'n"), or "ALL", the symbolnames are taken from the CURRENT model,
not the "ARCHIVE".
5. RANGEs may use "::" in place of "TO"; for example,
"1987Q1::1989Q4" is the same as "1987Q1 TO 1989Q4"
6. Namelists in variable specification are supported; for example,
VARIABLES VAR1 @VARLIST VAR2 ...
includes names of variables in the 'varlist' array. Namelists are case
sensitive, and variable names normally must be in capitals.
7. Each plot will be available for the number of seconds defined by
PLOT_TIMER.. variable, (See Example below) or until user selects exit from
the "Parameters of the Graphic" window, whatever comes first.
Default
value for PLOT_TIMER.. is set to 3600 seconds.
Examples:
1. &PLOT VARI JA_G , RANGE 1990A::1999A, ARCHIVES ST MULTJ ;
2. DO PLOT_TIMER.. = 60 ;
&PLOT NAFILL, VARI KLEIN_C KLEIN_K, RANGE ALL, ARCHIVES KLEINPIN ;
Example 1 displays two timeseries as a graph.
Variable JA_J is taken from two
different databases with alias names MULTJ and ST and displayed as two lines on
graph within bounds from 1990a to 1999a.
Example 2 sets PLOT_TIMER.. to sixty
seconds and displays the graph in the range of all available dates.
NA values
are displayed as zeros.
===============================================================================
A. DATE RANGE
One choice that does not get made by default is the choice of a time period over which to simulate. The simulator will
tell you the range of possible dates, but you have to choose some or all of that range explicitly as your simulation
period. You can do so by specifying dates in the SIMSTART and DOTIL commands. Alternatively you can specify only a
starting date (in SIMSTART), and then specify the number of periods to simulate via the DOSIM command. In that case the
simulation will end in whatever time period happens to finish the number specified. When you thus allow the ending
date to be implicit, you must be careful to avoid going beyond the feasible date range.
If you are doing a "forwardlooking" simulation using the (default) stacked time method, there is a third possibility for
specifying date ranges. Since the stacked time simulator works by stacking a specified number of periods at a time, you
can specify the number of sets of stacked periods to simulate instead of the total number of periods. (The stacked time
algorithm will be discussed in greater detail later.) So, for example, if you have set the stacked time simulator to stack
and solve 5 periods at a time, you can use the command "dostack 3" in place of "dosim 15". In practice it usually makes
sense only to solve the entire stacked model at once, so remember the command, "dostack 1;"!
Also note that date ranges continue in sequence until you issue another SIMSTART command. Moreover, you can mix date
specification methods within the same sequence. Accordingly, after first issuing a SIMSTART command, you could issue a
DOTIL command followed by a DOSIM command followed by a DOSTACK command, and the TROLL simulator would
continue to process time periods in sequence. If you forget the ending date for the feasible date range (or if you forget
the starting date when you wish to issue a new SIMSTART command) you can retrieve the feasible date range via LKDATES.
B. ALGORITHM
Another choice involved in TROLL simulation is the choice of solution algorithm. Generally TROLL will make this
choice for you (and probably make it well) if you don't make it explicitly. The default solution algorithm in TROLL's
simulator is the NewtonRaphson algorithm.
Other possibilities are the GaussSeidel and Jacobi relaxation algorithms. You can specify one of these algorithms as an
option to the SIMULATE command, as in, "simulate gauss" or "simulate jacobi." You can also switch between them
using the SIMALG command (e.g., "simalg gauss"). You cannot, however, switch to or from the default NewtonRaphson
algorithm using SIMALG command.
If your model contains endogenous leads (in other words, if it is "forwardlooking", containing one or more ENDOGENOUS
symbols followed by a positive number in parentheses), then none of those algorithms can solve it directly. You must
therefore specify STACK, OLDSTACK, or NOFL with the SIMULATE command. STACK and OLDSTACK represent different versions
of the stacked time algorithm, which solves the model by treating multiple ("stacked") periods as if they were
simultaneous. NOFL instructs TROLL to solve the model as if all the leads were exogenous  in other words, to use input
data for variables with positive leads instead of solving for their values.
An alternative option for solving forwardlooking models is to use the &FT macro provided with TROLL. &FT simulates
using the FairTaylor algorithm and can also be used to combine that algorithm with the stacked time algorithm. The
syntax for &FT is described in the file ft.doc.
C. SYMBOL TYPES
A number of choices related to simulation take place at the modelling stage, which is not specifically the subject of this
chapter. The choice of symboltypes is a special case because these can be directly modified as part of the simulation
task (via the DROP command), and also because some symboltype choices really affect the way the simulation is done
rather than the structure of the model itself.
1. Types of Symboltypes
The most critical choice relating to symboltypes is the decision about which variables to read from the data (i.e.,
take as exogenous) and which variables to generate as simulation solutions (i.e., make endogenous). Since the
words "ENDOGENOUS" and "EXOGENOUS" refer to specific symboltypes, let's use the terms "known variable" and
"calculated variable" for the more general concepts in the previous sentence. Naturally, ENDOGENOUS symbols
represent "calculated variables", but so do DEFINITION symbols. EXOGENOUS symbols represent "known
variables", and so do POLICY symbols. The remaining symboltypes  COEFFICIENT and PARAMETER  represent
"constants" rather than "variables".
When you declare a variable as ENDOGENOUS, you retain the option of making it exogenous during part of a
simulation by using the DROP command. When you make a variable exogenous, you must also remove an
equation from the model. With the DROP command, TROLL automatically removes an equation. (You have
indirect control  via the RENORM command  over TROLL's decision about which equation to remove, and you
can use LKORD to see TROLL's pairing between variables and equations; this topic will be discussed later in
greater detail.) The following example shows the usage of DROP.
SIMULATE Command: usemod ;
New model: (nameless)
TROLL Command: addeq bottom x'n + y'n = x(1) ;
MODEDIT Command: addeq bottom 2*x + 3*y = y(1) ;
MODEDIT Command: do x = reshape ( seq(20), 1a ), y = x ;
MODEDIT Command: do prtdata( x ) ; /* the data values for x */
X:
X = RESHAPE(SEQ(20),1A)
1A
5A
9A
13A
17A
:
:
:
:
:
2
6
10
14
18
3
7
11
15
19
4
8
12
16
20
If you use the DROP command, you can use LKDROP to show which variables have been DROPped and DELDROP
(e.g., "deldrop x;", "deldrop all;") to reverse the effects of DROP.
2. Symboltype Details
A subsidiary choice concerning symboltypes is which type of calculated variable, or which type of known
variable, to use. For a solution variable, the safest course is always to create a series (possibly a dummy series)
for the variable and declare its symbol as ENDOGENOUS. Some increase in efficiency is possible by using
DEFINITION symbols when they are feasible, but considerable care is necessary to avoid errors, especially in a
large and complicated model.
If you wish to take advantage of the efficiency of DEFINITION symbols, there are several important things to
remember. First, a DEFINITION symbol must be defined by an "identity equation" containing no asyetundefined
DEFINITION symbols on the righthand side. Second, a DEFINITION symbol must appear alone on the lefthand
side of its defining identity equation. Third, a DEFINITION symbol can never appear with a lead (i.e., positive
number in parentheses) in any equation. Finally, the identity equation for a given DEFINITION symbol must
appear in the model before that symbol is used in another equation.
The difference between the two types of "known variables" (EXOGENOUS and POLICY) is less consequential. From
a strictly computational point of view, the two are identical, so the choice is largely a matter of personal
convenience. It is conventional to use EXOGENOUS symbols for variables whose values will not be altered and to
use POLICY symbols for variables subject to "shock" in the context of "whatif experiments". You may find it
useful to apply the two different symboltypes to variables that you expect to use differently, since many
commands allow you to reference to all variables of a given symboltype.
The remaining symboltypes  COEFFICIENT and PARAMETER  refer to "constants" rather than "variables".
Technically it is never "necessary" to use such "constant" symboltypes in simulation. For example, all PARAMETER
symbols could be replaced with EXOGENOUS symbols without affecting the results. (The reverse is NOT true!)
However, the distinction between "constant" and "variable" symbols can make a model easier to understand.
Also, COEFFICIENT symbols have a special status in the context of estimation tasks. It is conventional to use
PARAMETER symbols for values that you might expect to change to examine variations on the model.
2. Dynamic Leads
TROLL treats leads differently than lags. There is no default "refresh interval" for leads. Instead, when you
invoke the simulator with the "STACK" option, you must explicitly specify the number of periods to stack. (The
number of periods to stack is analogous to the refresh interval for lags.) If you want to perform a "fully
dynamic" forwardlooking simulation, you must specify the number of periods to stack as the total number of
periods you wish to simulate. For example,
SIMULATE Command: usemod ;
New model: (nameless)
TROLL Command: addeq bottom iccanobif'n = iccanobif(1) + iccanobif(2) ;
MODEDIT Command: do iccanobif = crseries ( 1a::20a, 1 ) ;
MODEDIT Command: simulate stack 18 ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Constructing stackedtime incidence matrix and code.
Simulations can start from 1A to 18A and must end by 18A.
SIMULATE Command: simstart 1a ;
SIMULATE Command: list solutions all ;
SIMULATE Command: dosim 18 ;
Date:
What:
Value:
1A
Solution: ICCANOBIF [1A]
6765
[2A]
4181
[3A]
2584
[4A]
1597
[5A]
987
[6A]
[7A]
[8A]
[9A]
[10A]
[11A]
[12A]
[13A]
[14A]
[15A]
[16A]
[17A]
[18A]
610
377
233
144
89
55
34
21
13
8
5
3
2
The only way to solve a forwardlooking model consistently is with such a "fully dynamic" simulation.
However, for large models with many endogenous leads, there may be considerations that outweigh the need for
a technically correct solution. For one thing, when there are many endogenous leads involved, stacking an entire
simulation period can be very expensive computationally. Second, you need to specify the "stack length" when
you invoke the simulation task  before the simulator has a chance to calculate the feasible date range. Third, by
stacking the entire simulation period, you may maximize the impact of instabilities that make the model difficult
or impossible to solve. Finally, a "fully dynamic" forwardlooking simulation over many time periods stretches
rational expectations methodology to its limits: there is no opportunity for judgment or empirical data to temper
the cumulative effects of abstract model features that are inevitably an imperfect description of reality.
Consequently, you may get strange results.
On the other hand, if your objective is to scrutinize the longterm behavior of the model rather than to produce a
reasonablelooking simulation, then you want to stack as many time periods as possible. TROLL places no
explicit limits on the "stack length", and TROLL's use of symbolic derivatives and sparse matrix techniques
makes it feasible (though seldom easy) to solve large forwardlooking models with full dynamic effects. At the
simplest and most abstract level, the following "partially dynamic" simulation of the Iccanobif sequence (in
comparison with the simulation above) illustrates the difference between "full stacking" and "partial stacking":
SIMULATE Command: simulate stack 6 ;
Constructing stackedtime incidence matrix and code.
Simulations can start from 1A to 18A and must end by 18A.
SIMULATE Command: simstart 1a ;
SIMULATE Command: list solutions all ;
SIMULATE Command: dosim 18 ;
Date:
What:
Value:
1A
Solution: ICCANOBIF [1A]
21
[2A]
13
[3A]
8
[4A]
5
[5A]
3
[6A]
2
7A
Solution: ICCANOBIF [7A]
21
[8A]
13
[9A]
8
[10A]
5
[11A]
3
[12A]
2
13A
Solution: ICCANOBIF [13A]
21
[14A]
13
[15A]
8
[16A]
5
[17A]
3
[18A]
2
Note that the "stack length" choice places an important restriction on the choice of date range: the number of
periods to simulate must be an integer multiple of the number of periods to stack. So the following command
doesn't work:
SIMULATE Command: simstart 1a ;
SIMULATE Command: dosim 17 ;
ERROR 15084
The number of periods you simulate must be a multiple of the number you STACKed.
You requested 17 periods but specified "STACK 6".
You can avoid this problem by using DOSTACK instead of DOSIM or DOTIL. You still have to make sure that the
number of stacked sets (argument to DOSTACK) times the size of a stacked set (argument to SIMULATE STACK) is
less than or equal to the number of periods available for simulation (reported  in the form of a date range  by
F. SIMULATION PARAMETERS
TROLL's simulation algorithms have a number of tunable parameters. You can use the CONOPT command, described in
the TROLL Reference Manual. Algorithm tuning is too advanced a topic to discuss at this point, but it will come up in
the next chapter.
A. MODEL
TROLL imposes the following requirements on a simulation model:
The model to be simulated must be TROLL's working model (i.e., the model contained in the model file
"CURRENT"). As such, it must be a valid TROLL model.
The number of variables to be calculated (i.e., the total number of ENDOGENOUS and DEFINITION symbols in the
model) must equal the number of equations in the model.
DEFINITION variables must be defined before they are used. This means that the first place each DEFINITION
variable appears in the equations must be alone on the lefthandside of its "identity equation", and it may not
appear on the righthandside of that equation.
The identity equations which define DEFINITION variables must not contain any leads (positive numbers in
parentheses) on ENDOGENOUS symbols.
SUM and PRODUCT operators may not be nested.
Subscripts may only be applied to COEFFICIENT or PARAMETER symbols, not to expressions or timeseries symbols,
and there can only be one subscript on a symbol. (The simulator only allows scalars and onedimensional
vectors for constants.)
Lags, leads and subscripts must be integers or simple expressions consisting of integers, index symbols (inside a
SUM or PRODUCT), and the '+' and '' operators.
The equations may only use the following functions:
ABSV
ARCTAN
LOG
MIN
SIGN
ARCCOS
COS
LOG10
MINARG
SIN
ARCCOT
COTAN
MAX
PNORM
SQRT
ARCSIN
EXP
MAXARG
SELECT
TAN
CEILING
FLOOR
ROUND
ROUNDUP
TRUNCATE
These conditions are necessary but not sufficient for TROLL to simulate a model. The sufficient conditions would be
very difficult to describe. In general, if a model is wellformulated and makes sense, and if it meets the conditions
above, it is likely that TROLL can, in principle, simulate it. Even so, with a given set of data, an otherwise
wellformulated model may be unstable, and a meaningful simulation may be impossible. Methods for diagnosing and
revising various kinds of problematic and/or unstable models will be covered in the next two chapters.
B. DATA
TROLL imposes the following requirements on the data used for a simulation:
The data for the simulation must be located where TROLL will find them using the current SEARCH rules. All the
usual precautions apply: for example, if two variables have the same name, TROLL will use the first one it finds
as it goes down the SEARCH list.
The values for ENDOGENOUS, EXOGENOUS, and POLICY variables must be scalar timeseries and/or scalar constants.
All timeseries used in the simulation must have the same periodicity.
The date ranges of the timeseries must overlap, and the overlapping date range must be long enough to provide
data for all lags and leads in the model (so that at least one observation has all the required lags and leads). This
requirement does not apply to constants, which are assumed to overlap as necessary with any timeseries.
Values for COEFFICIENT and PARAMETER symbols must be constants (i.e., not timeseries) and may have no more
than one space dimension. Usually they are scalar, but they can be onedimensional vectors. If a constant symbol
appears subscripted in the model (for example, in a distributed lag SUM expression), then the corresponding data
object must be a onedimensional vector.
Variables cannot take the value NA during the simulation range, including any necessary lags and leads. This
requirement applies even to information that will not be used directly in the simulation. For example, even if the
simulation only uses the first observation for an ENDOGENOUS variable, none of the observations in the simulation
range can have the value NA.
Before you simulate a model, make sure the model is what you think it is. Various minor careless errors, such as
forgetting to issue a USEMOD command or issuing it at the wrong time, can lead to unpleasant surprises and confusion at
simulation time. If you are about to enter the SIMULATE task from the TROLL command level or from a task other than
MODEDIT, you can type "prtmod;" to see TROLL's working model. If you are about to enter SIMULATE directly from
MODEDIT, you can type "print;".
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
As noted above, TROLL will compare this value to CONCR for each ENDOGENOUS variable in a block of equations
and will finish with the block if each variable gives a value less than CONCR.
TROLL will also terminate a simulation under either of the following conditions:
The number of iterations reaches the value STOP.
The convergence rate exceeds DIVCR and the number of iterations is at least START.
The largest of the initial residuals (before beginning iterations) is less than TINYRES.
Furthermore, if an iteration passes the usual convergence test but the largest residual is greater than or equal to
then iteration continues despite the convergence test.
BIGRES,
2. Choosing Parameters
a. CONCR
represents directly the level of precision required. The default value is 0.001, which (in
combination with the default GAMMA of 1.0) is a "reasonable generalpurpose value". To be considered
convergent, a variable can change either by less than 0.001 in absolute value or by less than 0.1 percent
of its absolute value from one iteration to the next. That should be sufficient precision for any nottooexacting application and sufficient practicability for any nottoodifficult model.
CONCR
However, some applications do require greater precision, and some models are quite difficult to solve.
Whether your application falls into the former category is largely a matter of personal judgement (once
you understand the convergence criterion). If, on the other hand, your model falls into the latter category,
this will become apparent: first (using the default value for STOP), TROLL will terminate the simulation
without converging; then (if you increase the value of STOP), you will wait a long time for any results.
The course of action is clear: if you need more precision, reduce the value of CONCR; if you need a
quicker result, increase the value of CONCR. But you should also read the rest of this section and consider
the possibilities.
b. STOP
If you are trying to solve a difficult model using the default parameters, STOP will be in your face before
you can say, "Jack Robinson". By default TROLL will give up after 10 iterations. This default value is
really more of a safety valve than an optimum. If the iterations are slow  and in particular if an error is
causing the iterations to be extremely slow  then giving up after 10 iterations saves you from waiting
indefinitely for a result that probably isn't right anyway.
If you find you are waiting an unreasonable amount of time for those 10 iterations to complete,
something is probably wrong. Check for errors in your model. Check for strange values in your data. If
you are convinced there are no errors, try a different solution algorithm. Consider a higher value for
CONCR. Try simpler variations on your model to see if they have the same problem. Call user support. For
Heaven's sake, trade in your 80386 for a Pentium IV.
For serious work, you will most likely have to increase the value of STOP. How much to increase it
depends largely on how long you're willing to wait to find out whether the simulation succeeded. In
principle, the "correct" value of STOP is Infinity. If there are no problems with the model, data, software,
or hardware, then failure to converge simply indicates that your model is a difficult one, so that the
tradeoff between precision and efficiency is an unpleasant one. Then you have to decide between a less
precise solution (Increase CONCR!) and a slow one (Wait!).
c. GAMMA
The GAMMA parameter allows you to adjust between an absolute convergence criterion and a relative
convergence criterion. Generally you should change CONCR at the same time, since any change in GAMMA
will change the units of the convergence criterion.
As an example, suppose that you are simulating the U.S. economy, and that your endogenous variables
are things like national income, consumption expenditures, private domestic investment, and such. The
typical values for these variables will depend on the units in which they are expressed. In any case, the
value 1.0 will have no particular economic meaning. Consequently, an absolute convergence criterion
will simply be comparing differences to arbitrary values. GAMMA should be near zero, to give a relative
convergence criterion. Depending on the units used, the default value of 1.0 might be close enough to
zero; but if you express investment in trillions of dollars, consider specifying "conopt gamma 0 ;".
Alternatively, suppose that you are simulating asset returns, and that your endogenous variables are
things like interest rates, risk premia, and excess returns. These variables are inherently expressed in
absolute units. Moreover, there is no presumption that excess return variables will be either positive and
negative. In this situation, a relative convergence criterion could get you into trouble. For example, if the
true value of a given excess return variable is exactly zero, it might never converge according to a "pure"
relative convergence criterion (GAMMA = 0). Even the default value GAMMA = 1 could be problematic if the
endogenous variables are expressed in basis points. The default GAMMA would require extreme precision
for the variables whose true values are near zero, while allowing considerable laxity for other variables.
You might instead choose "conopt gamma 1e6, concr 1e3;", which would effectively set the precision
level for all endogenous variables to one tenth of a basis point.
Often (perhaps always) you will have some variables that need to be interpreted in absolute terms and
others that need to be interpreted in relative terms. Unfortunately you cannot set a separate GAMMA value
for each endogenous variable. Usually you can find a value that will give reasonable results. As a last
resort it may be necessary to respecify your model so that some variables are expressed in different
units.
d. DIVCR and START
Sometimes you just can't win. Some problems just never move toward a solution. When a simulation
result diverges, TROLL will eventually reach its maximum number of iterations (the "STOP" value) and
give up. But this approach might not be optimal, because it does not distinguish between divergence (no
hope of solution) and tooslow convergence (solution to arrive eventually). For this reason TROLL also
provides divergence checking: starting with iteration START, TROLL will terminate the simulation with a
divergence condition if the convergence rate (actually more likely a divergence rate) exceeds DIVCR for
any of the endogenous variables. By default START is 3, and DIVCR is 10. Occasionally the particulars of
your problem may require changes in these values.
e. DAMP
Although DAMP is not technically a convergence parameter, it can be useful in situations where
convergence is a problem. DAMP determines the length of the Newton step during the NewtonRaphson
iteration process. Normally the step is one, which is equivalent to the "neutral" prior assumption that the
residuals are linear in the endogenous variables over the relevant range in the neighborhood of the
solution. If the residuals are highly concave and the relevant range is very large (i.e., the starting value is
far from the solution), the linearity assumption may produce screwy results.
If you find that the simulator is iterating into insanity at the beginning of the solution process, you can
fix the problem by DAMPing the iterations  use CONOPT to set DAMP to a value less than 1. This change will
replace the usual "neutral" process with a more conservative one. Although convergence will be slower
in the neighborhood of the solution, it will also avoid going haywire at the beginning. You may have to
experiment to find a value that works. (DAMP must be greater than zero, of course; otherwise there would
be no iterations at all.)
On the other hand, if the residuals are highly convex, the "neutral" linearity assumption may cause
convergence to be unnecessarily slow. At the risk of causing an otherwise stable solution process to
diverge, you can try setting DAMP to a value greater than 1. (The maximum allowed value is 2, although
higher values are theoretically possible.)
Changing the association between variables and equations is accomplished via the RENORM command. The
concept of "normalization" will be discussed in greater detail in the section on model analysis. TROLL's choice
of "normalization" (association between variables and equations) is largely arbitrary, but RENORM will force
TROLL to associate specific variables with specific equations. Before you use RENORM, use LKORD to display the
current normalization, as in the following example, which attempts to simulate the earlier "functions" model
(with the current parameter values) using GaussSeidel:
SIMULATE Command: usemod functions ;
TROLL Command: simulate gauss ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1975A to 1996A and must end by 1996A.
SIMULATE Command: list solutions e y ;
SIMULATE Command: simstart 1975a ;
SIMULATE Command: dosim 20 ;
Date:
What:
Value:
1975A
Solution: Y
492.957497
E
2.410096
1976A
Solution: Y
485.080642
E
3.418948
1977A
Solution: Y
526.978676
E
1.62039
1978A
Solution: Y
555.348039
E
1.301261
1979A
Solution: Y
553.042643
E
1.787825
1980A
Solution: Y
531.660764
E
2.821679
WARNING 15046
Expression cannot be evaluated.
In residual for equation 8:
LOG'F(E'N/E0'C)
Date: 1981A; Block: 2; Iteration: 1;
 attempt to take log of a nonpositive number
(This WARNING will not be repeated during this block.)
1981A
Solution:
1982A
Solution:
1983A
Solution:
1984A
Solution:
1985A
Solution:
1986A
Solution:
Y
E
Y
E
Y
E
Y
E
Y
E
Y
E
590.880397
0.97775
581.545267
1.397706
542.621671
3.682161
562.381479
2.956975
517.513578
7.050979
514.345946
7.336289
WARNING 15046
Expression cannot be evaluated.
In residual for equation 8:
LOG'F(E'N/E0'C)
Date: 1987A; Block: 2; Iteration: 1;
 attempt to take log of a nonpositive number
(This WARNING will not be repeated during this block.)
1987A
Solution:
1988A
Solution:
1989A
Solution:
1990A
Solution:
1991A
Solution:
1992A
Solution:
1993A
Solution:
1994A
Solution:
Y
E
Y
E
Y
E
Y
E
Y
E
Y
E
Y
E
Y
E
585.16586
2.191675
606.308763
2.079926
603.066024
3.172965
598.923158
4.2802
615.723507
3.392272
629.825442
3.382674
677.592062
1.777426
719.504999
1.28531
Block
Size
Eqn
Var
DOMINVEST
TOTINVEST
TOTSAVE
3
4
5
Y
CONS
IMPORT
In this example the GaussSeidel simulation encounters the same arithmetic failure that NewtonRaphson
encountered earlier. In earlier versions of TROLL, this would have caused GaussSeidel to terminate. As it is,
the algorithm proceeds, but one may wonder if the process can be accomplished without encountering the failure
at all. One way to get a different result from GaussSeidel is to change the normalization, which we display
above using "lkord all". We'll try the simulation again, this time forcing TROLL to associate y with equation 4.
SIMULATE Command: renorm 4 y ;
TROLL Command: simulate gauss ;
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from 1975A to 1996A and must end by 1996A.
SIMULATE Command: simstart 1975a ;
SIMULATE Command: list solutions y e ;
SIMULATE Command: dosim 20 ;
Date:
What:
Value:
ERROR 15011
Divergence occurred:
Date: 1975A; Block: 6; Iteration: 5
Worst Variable: Y
Last iteration value: 9.76238e+007; Relative Change: 6826.61
Maximum Residual: Equation: 5; Value: 1.95219e+007
Out of the frying pan and into the fire. Obviously this renormalization didn't help. We could try some others.
SIMULATE Command: lkord all ;
The model has 6 blocks, including 1 simultaneous block.
The largest block has 3 equations and the next largest has 1.
Block
Size
Eqn
Var
DOMINVEST
TOTINVEST
TOTSAVE
3
4
5
CONS
Y
IMPORT
Value:
ERROR 15011
Divergence occurred:
Date: 1975A; Block: 6; Iteration: 441
Worst Variable: Y
Last iteration value: 1.#INF; Relative Change: 1.#INF
Maximum Residual: Equation: 3; Value: 8.4284e+307
SIMULATE Command: lkord all ;
The model has 6 blocks, including 1 simultaneous block.
The largest block has 3 equations and the next largest has 1.
Block
Size
Eqn
Var
DOMINVEST
TOTINVEST
TOTSAVE
3
4
5
IMPORT
CONS
Y
Well, renormalization didn't work for this example. Sometimes it does help.
TROLL Command:
TROLL Command:
Horizon:
Min
Max
0
0
0
0
0
0
1
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
usemod addfactors ;
symtab all ;
Symboltype
COEFFICIENT
COEFFICIENT
COEFFICIENT
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
COEFFICIENT
COEFFICIENT
POLICY
COEFFICIENT
COEFFICIENT
ENDOGENOUS
COEFFICIENT
FUNCTION
COEFFICIENT
FUNCTION
COEFFICIENT
POLICY
EXOGENOUS
EXOGENOUS
EXOGENOUS
EXOGENOUS
EXOGENOUS
EXOGENOUS
COEFFICIENT
PARAMETER
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
ENDOGENOUS
EXOGENOUS
Symbolname
A
B
C
CONS
DOMINVEST
E
E0
F
G
H
I
IMPORT
J
LOG
M
MAX
P
R
RES_CONS
RES_DOMINVEST
RES_E
RES_IMPORT
RES_X
RUS
S
T
TOTINVEST
TOTSAVE
X
Y
YUS
B. INCIDENCE MATRIX
TROLL's first step in analyzing a model is to generate the "incidence matrix". This matrix shows which endogenous
variables occur in which equations. If a model has N equations with N endogenous variables, you can construct an NbyN
matrix in which element i,j is 1 if variable j appears in equation i, and 0 otherwise. That matrix is (one representation
of) the model's incidence matrix.
Remember that lagged ENDOGENOUS symbols are EXOGENOUS in the current period. So the incidence matrix generally
does not include references to lagged symbols. If variable j appears only with a lag in equation i, then element i,j of
the incidence matrix will still be 0.
TROLL gives information about a model's incidence matrix in response to the LKXREF command. Rather than printing
out the entire matrix, LKXREF simply identifies the nonzero elements. To see a full list, type "lkxref all;".
Alternatively, you can display particular "columns" of the incidence matrix by giving LKXREF a variable specification as
an argument.
TROLL Command: lkxref endogenous ;
Analyzing Model's Incidence Matrix
Variable
CONS
DOMINVEST
E
IMPORT
TOTINVEST
TOTSAVE
X
Y
4
6
8
5
2
3
7
4
(A related command, LKSYM, provides information about all  rather than just unlagged  occurrences of specified
variables within equations.)
C. BLOCK ORDERING
Once the incidence matrix has been established, the next step is to partition the model into blocks that can be solved
separately (i.e., sequentially). A block is either a single equation or a set of equations that are "truly simultaneous" in the
sense that they cannot be solved sequentially. (Note that the partitioning of a model is unique, although the sequence in
which the blocks are solved may not be.) Consider the following model:
TROLL Command: usemod ;
New model: (nameless)
TROLL Command: addeq bottom y
MODEDIT Command: addeq bottom
MODEDIT Command: addeq bottom
MODEDIT Command: addeq bottom
MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
X1 X2 X3
X4
EXOGENOUS :
Y
Equations:
1:
2:
3:
4:
Y = X1+X2+X4
Y = Y(1)+X1*X2
X3 = X4**2
X4 = 0.9*X1(1)
First consider equation 4. Since x1(1) is a lagged symbol, it is predetermined with respect to the current period.
Therefore equation 4 can be solved for x4 without using the other equations. Thus equation 4 may be considered a
separate block. Although x4 also appears in equation 1, it is not necessary to solve equation 1 to get the value of x4.
Once the value of x4 is known, equation 3 may be solved for x3 without using the other equations. Equation 3 may
therefore also be considered a separate block.
Equations 1 and 2 are truly simultaneous. There is no way to solve one equation without solving the other at the same
time. On the other hand, once we have solved equation 4 (separately) for x4, we can solve equations 1 and 2 without
using any other equations. Equations 1 and 2 therefore constitute a block. Such a block, containing more than one
equation, is called a "simultaneous block."
In sum, we may say that the model contains three blocks, of which one is simultaneous. When TROLL divides a model
into blocks, it also numbers the blocks to indicate the order in which they will be solved. (The combined process is
known as "block ordering.") In the present example, equation 4 must be solved first, but the remaining two blocks may
be solved in either order. Once we know x4, we can use it to solve either equation 3 or equations 1 and 2. When such a
choice exists, TROLL will usually decide based on the equation numbers. The LKORD command displays information
about TROLL's block ordering:
MODEDIT Command: lkord all ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
The model has 3 blocks, including 1 simultaneous block.
The largest block has 2 equations and the next largest has 1.
Block
Size
Eqn
Var
X4
1
2
X2
X1
X3
(Note that LKORD also forces TROLL to do a block ordering if it has not already done one. Once the block ordering is
done, it becomes part of the model until the model is changed.) LKORD can also be used in other ways. With no argument,
LKORD describes the blocks without listing them:
TROLL Command: lkord ;
The model has 3 blocks, including 1 simultaneous block.
The largest block has 2 equations and the next largest has 1.
"lkord block" followed by a block number (or several block numbers) will display the contents of a specific block (or
blocks). There is also "lkord equation" (which block contains a given equation?) and "lkord symbol" (which blocks
contain a given symbol?). You can also ask LKORD to display only the simultaneous blocks:
TROLL Command: lkord simultaneous ;
The model has 3 blocks, including 1 simultaneous block.
The largest block has 2 equations and the next largest has 1.
Block
Size
Eqn
1
2
Var
X2
X1
D. NORMALIZATION
The next step after block ordering is "normalization"  the process of pairing equations with variables. Usually several
different normalizations are possible for a given simultaneous block, and it is difficult to know in advance which
normalization will produce the best results. (Note, however, that the choice of normalization is irrelevant when the
default NewtonRaphson solution method is used.) The information that LKORD reports about any equation includes the
name of the variable associated with that equation. As discussed earlier, it is possible to revise the normalization via the
RENORM command.
E. SIMULATION CODE
After normalizing the equations, TROLL generates "simulation code," which consists of the symbolic partial derivatives
of each equation with respect to each endogenous variable in the corresponding block. Like the normalization, the
simulation code becomes part of the model until the model is changed. The same simulation code can be used to
simulate the model with any set of data, since the simulation code contains only symbolic derivatives, the form of which
does not depend on the data (or on the simulation parameters). At each step of the solution process for a particular set of
data, TROLL can compute the values of the derivatives by plugging numbers into the symbolic derivatives and
evaluating them. Thus there is no need for the timeconsuming process of estimating derivatives numerically.
Unlike block ordering and normalization, the codegeneration step always takes place during the simulation task. There
is no command to force code generation before entering SIMULATE. Thus, the first time you simulate a model (or the first
time you simulate a revised version), TROLL actually adds something to the model file. To avoid later duplication of
effort, it may be useful at this point to save the simulation code in a permanent model file by issuing a FILEMOD
command.
Normally you won't see the simulation code, but you should know that it exists. Occasionally you may find it useful to
check the symbolic derivatives by using the DERIV function. Another possibility is to invoke SIMULATE with the ROOTS
option and then issue "lkroots symjacobian outlvl 4;" after the SIMSTART command. (The use of LKROOTS is described
later under "Eigenanalysis".)
G. EIGENANALYSIS
What does the structure of a dynamic model imply about its long term behavior? In the absence of shocks, will it
converge to a stable equilibrium, will it cycle between two alternatives, or will it behave explosively? If it doesn't
behave well, how can you change it to improve its convergence characteristics? With a linear model, these questions are
normally approached by expressing the model in matrix form and calculating eigenvalues.
Unfortunately a nonlinear model cannot easily be expressed in matrix form. However, with a given set of data, at a
given point in time, the model can be approximated with a linear model by taking partial derivatives with respect to the
endogenous variables. The eigenvalues from the linearized model will not give perfectly reliable answers as to the long
term behavior of the original model, but they will sure beat the heck out of just guessing.
Since the partial derivatives already exist in a TROLL model's simulation code when TROLL is ready to simulate the
model, linearization simply consists of evaluating those derivatives at a point in time. You specify such a point in time
when you issue the SIMSTART command. With the LKROOTS command, TROLL provides a facility for analyzing the
eigenvalues of the resulting linear model.
To take advantage of LKROOTS, you must first issue the SIMULATE command with the ROOTS option. Then, after specifying
a SIMSTART date, you can look at the eigenvalues:
TROLL Command: simulate roots ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Constructing stackedtime incidence matrix and code.
Simulations can start from 1975A to 1994A and must end by 1994A.
SIMULATE Command: simstart 1975a ;
SIMULATE Command: lkroots ;
Statespace eigenanalysis of ADDFACTORS linearized around 1975A:
There are 3 eigenvalues with modulus between 0.001 and 1000,
consisting of 3 real roots and 0 complexconjugate pairs.
There are 0 eigenvalues with modulus larger than 1.0
(including 0 larger than 1000) for 1 lead variable.
1:
2:
3:
Real
0.96007806
0.87155043
0.08193955
+Imaginary
Magnitude
0.96007806
0.87155043
0.08193955
Period
Subject, of course, to the inherent limitations of a linear approximation localized in time, the interpretation of the
eigenvalues is fairly straightforward:
In a backwardlooking model, any root with a magnitude greater than 1.0 indicates an explosive growth mode
wherein the model will fail to equilibrate.
In a forwardlooking model, there should be one root greater than 1.0 for each independent lead variable. Any
additional roots greater than 1.0 would indicate an explosive growth mode.
A root equal to 1.0 indicates a mode in which shocks are reflected permanently in the model's longrun behavior.
Note, however, that this condition may not be very meaningful when relevant variables enter the model
nonlinearly, since the specific required value of the root depends on the evaluation of the partial derivatives,
which will most likely change over time.
A negative real root normally indicates a twoperiod cycling mode. If the magnitude is less than 1.0, the cycles
should die out. If the magnitude is greater than 1.0, the cycles should become ever wider.
A complex root  one with a nonzero imaginary component (and usually listed with an explicit "period") indicates a cycling mode (with a period as specified). Again, if the magnitude is less than 1.0, the cycles should
die out, and if the magnitude is greater than 1.0, the cycles should become ever wider. (Note that complex roots
always appear in conjugate pairs, and TROLL will display only one of the conjugates for each pair.)
Roots with magnitudes less than 1.0 indicate modes in which shocks will have only temporary effects  in other
words, stable equilibria.
Roots with magnitudes near 1.0 are in general worthy of attention, since, in a nonlinear model, they can easily
"cross the line" into (or out of) an explosive mode.
In general, the number of roots (including complex conjugates) should equal the total number of independent
endogenous variables, but this includes endogenous leads as well as auxiliary variables used to represent lags and leads
greater than one. Moreover, it may not be apparent how many of the endogenous variables are "independent" in the
relevant sense. Trying to count roots is often more trouble than it's worth.
Even if you trust the roots from the linearized model, simply knowing them won't by itself solve the problem of unstable
dynamics. To help you apply the information from the roots, LKROOTS can also provide elasticities, which show the
relative percent response of roots to changes in (the linearized) coefficients. (These elasticities, of course, must be
interpreted with caution, since they are really loglinear coefficients derived from a linearized version of a model that is
probably neither linear nor loglinear. The elasticities are valid for small changes relative to the values of the variables at
the specific point in time. Beyond that they are merely rough approximations.)
SIMULATE Command: lkroots elasticity ;
Statespace eigenanalysis of ADDFACTORS linearized around 1975A:
There are 3 eigenvalues with modulus between 0.001 and 1000,
consisting of 3 real roots and 0 complexconjugate pairs.
There are 0 eigenvalues with modulus larger than 1.0
(including 0 larger than 1000) for 1 lead variable.
Real
0.96007806
0.87155043
0.08193955
1:
2:
3:
+Imaginary
Magnitude
0.96007806
0.87155043
0.08193955
Period
0.00000000i
1.0000
1.0000
0.00000000i
0.1746
0.1609
1.1562
0.9815
0.1746
0.00000000i
0.9815
0.9815
0.9815
0.9815
0.1609
0.9815
0.8043
0.1609
0.1609
0.9815
0.9815
Here we see, for example, that the second root depends largely on the "coefficient" on consumption in equation 4, so
that a change in that "coefficient" (actually a partial derivative) has a more than proportional effect on the value of the
root. If you are adventurous, you can actually look at those symbolic partial derivatives that TROLL is using to
calculate the "coefficients", as shown below. More detailed descriptions of the options available in LKROOTS may be
found in the TROLL Reference Manual.
SIMULATE Command: lkroots symjacobian outlvl 4 ;
Statespace eigenanalysis of ADDFACTORS linearized around 1975A:
There are 3 eigenvalues with modulus between 0.001 and 1000,
consisting of 3 real roots and 0 complexconjugate pairs.
There are 0 eigenvalues with modulus larger than 1.0
(including 0 larger than 1000) for 1 lead variable.
Real
0.96007806
0.87155043
0.08193955
1:
2:
3:
+Imaginary
Magnitude
0.96007806
0.87155043
0.08193955
Period
Variable
DOMINVEST
Y
E
E
Lag
Derivative
0
1
1.00000000
0.10000000
0
1
0.58561992
0.60997115
Symbolic derivative
1
(SELECT'F(MAXARG'F(0,I'C*Y'N(1)J'C*
R'POL**P'C),0,I'C))
(1/E'N(+1)*(1+RUS'X/100))
(((E'NRES_E'X)/E'N(+1))/E'N(+1)*(1+
RUS'X/100))
7
2
1
3
E
X
DOMINVEST
X
TOTINVEST
TOTINVEST
TOTSAVE
TOTSAVE
Y
CONS
IMPORT
Y
CONS
CONS
Y
IMPORT
0
0
0
0
0
0
0
0
0
0
0
0
27.00501688
1.00000000
1.00000000
1.00000000
1.00000000
1.00000000
1.00000000
1.00000000
1.00000000
1.00000000
1.00000000
0.00055535
1
0.00250697
0
0
0
0.00338816
0.20000000
1.00000000
B'C*S'C*E'N**(S'C1)/E'N**S'C
1
1
1
1
1
1
1
1
1
1
(C'C*(((CONS'N(1)*(1T'P)/(Y'NT'P
*Y'N))/(Y'NT'P*Y'N))))
((CONS'NRES_CONS'X)/CONS'N(1))/
CONS'N(1)C'C*1/(Y'NT'P*Y'N)
1/CONS'N(1)
M'C
1
The other shortcoming is just the opposite: the forwardlooking approach, at least in its strict "perfect foresight" form,
ignores what is often the most interesting aspect of economic behavior  systematic mistakes. In particular, if one is
trying to profit from the mistakes of others, one cannot hope to accomplish much by assuming away those mistakes.
Note, however, that forwardlooking models can still be useful in studying such "boundedly rational" behavior. For
example, by assuming that some fraction of all agents is forwardlooking, one can parametrize the degree of
irrationality.
The great advantage of forwardlooking simulation, from the point of view of policy analysis, is that a forwardlooking
simulation can anticipate any possible source of information about a policy action or its ultimate results. A backwardlooking simulation does not allow the analyst to distinguish between consequences that result from agents' reaction to a
wellunderstood policy action and those that result from agents' (assumed) misunderstanding of a policy action. History
(according to the conventional interpretation) suggests that policymakers are often tempted to exploit that
misunderstanding, even when its appearance in the simulation actually reflects the incompleteness of the model. In a
world where you can't fool all of the people all of the time, the most conservative assumption is that you can never fool
anyone. The only way to incorporate that assumption fully into a simulation is to assume forwardlooking behavior.
Okay, enough about the Lucas critique, the meaning of life, and all that! It's time to play Jeopardy. When you prepare to
play Jeopardy with TROLL, you must remember that you will be in the position of the host, not the contestant. TROLL
will find the questions for you, but first you have to give it the answers. Fortunately, TROLL will also help you find the
answers in the first place. However, you have to know what questions to ask initially. The challenge is to recast your
model in a form that allows you to draw conclusions about the long run before you have conclusive results for the short
run. In the process you may discover that your model doesn't quite make sense in the long run, in which case the best
course of action is usually to revise the original model. In general, you'll have to make some decisions (or assumptions)
about what kind of long run is relevant (e.g., which variables are constant in your long run).
We'll divide the model into three parts, representing the technology, behavioral equations, and "accounting" (including
definitions, which unfortunately in this case had to be implemented with ENDOGENOUS symbols). The technology is quite
simple: a CobbDouglas production function (with a timedependent scale factor or "Solow residual") and a standard
capital growth equation (which may look a little strange because of the discretetime correction  a minor technicality
which you can safely ignore). There is also a "Marginal Product of Capital" equation, which is just the partial derivative
of the production function.
MODEDIT Command: //
TECHNOLOGY
MODEDIT Command: addeq bottom produce: log(y) =
Continue eq: capshr*log(k) + (1capshr)*log(l) + tech ;
MODEDIT Command: eqcom produce Production Function ;
MODEDIT Command: addeq bottom mpk: mpk=capshr*y/k ;
MODEDIT Command: eqcom mpk Marginal Product of Capital ;
MODEDIT Command: addeq bottom accum: k =
Continue eq: k(1)  depr*(kk(1))/log(k/k(1)) + i(1);
MODEDIT Command: // note: "(kk(1))/log(k/k(1))" is "k(1)"
MODEDIT Command: //
with a discretetime correction
MODEDIT Command: eqcom accum Capital Accumulation ;
In case you're interested, the discretetime correction factor allows us to specify growth rates in continuous time, so that
we can later use logs in the steadystate version instead of saying "*(1+gr)" all the time. Even so, the discrete
approximation might have been close enough for practical purposes.
The behavioral section of the model  where most of the action is  begins with the components of demand:
investment, consumption, imports, and exports. Investment is a kinked linear function of the real interest rate. The
consumption function is "partially forwardlooking" and exhibits some inertia (or habit). Imports and exports both
exhibit inertia as well.
MODEDIT Command: //
BEHAVIOR
MODEDIT Command: addeq bottom invest: i=y*max(0,i1*(mpkrr)) ;
MODEDIT Command: eqcom invest Investment Demand ;
MODEDIT Command: addeq bottom consume: log(c) =
Continue eq: c1*log(y) + c2*log(y(+1)) + c3*log(c(1)) ;
MODEDIT Command: eqcom consume Consumption Demand ;
MODEDIT Command: addeq bottom import: log(im/y) =
Continue eq: im0 + im1*log(im(1)/y(1))  im2*log(er);
MODEDIT Command: eqcom import Import Demand ;
MODEDIT Command: addeq bottom export: log(x/yw) =
Continue eq: x0+x1*log(x(1)/yw(1))+(1x1)*log(y(1)/yw(1))+x2*log(er);
MODEDIT Command: eqcom export Export Demand ;
Note that export demand depends on foreign income in the short run but not in the long run. Because there is no
longrun relationship, it is possible to have a stable equilibrium in which the foreign growth rate differs from the
domestic growth rate.
The next two equations are the money demand function and the interest rate parity condition. Both are straightforward
and conventional.
MODEDIT
MODEDIT
MODEDIT
MODEDIT
Command:
Command:
Command:
Command:
addeq
eqcom
addeq
eqcom
The final behavioral equation is the Phillips curve, which has a widelyused nonlinear form.
MODEDIT Command: addeq bottom phil: log(p(+1)/p(1))/2 =
Continue eq: pc1/u  pc0 + (infl(2)+infl(+1))/2 ;
MODEDIT Command: eqcom phil Phillips Curve ;
The remaining substantive equation is the national income identity. The rest are definitions. (Note that our definition of
the real exchange rate assumes a constant price level abroad, which could be realized empirically by expressing the
nominal exchange rate in terms of a synthetic uninflating currency.)
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
//
//
//
addeq
eqcom
//
addeq
eqcom
ACCOUNTING
Warning:
NIPA identity ignores capital services and terms of trade.
bottom income: y=c+i+gov+xim ;
income National Income Identity ;
Note: "Definitions" below do NOT use DEFINITION symbols!
bottom employ: u = 1l/lf ;
employ Definition of Unemployment ;
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
Command:
Command:
Command:
Command:
Command:
Command:
addeq
eqcom
addeq
eqcom
addeq
eqcom
EXOGENOUS :
LF
 labor force
RW
 world interest rate
TECH
 total factor productivity
YW
 world income
POLICY :
GOV
MS
COEFFICIENT :
C1 C2 C3 I1
IM0
IM1
IM2
MD0
MD1
MD2
PC0
PC1
X0
X1
X2
PARAMETER :
CAPSHR
 capital share
DEPR
 depreciation rate
FUNCTION :
LOG MAX
Equations:
Production Function
1: PRODUCE LOG(Y) = CAPSHR*LOG(K)+(1CAPSHR)*LOG(L)+TECH
Marginal Product of Capital
2: MPK
MPK = CAPSHR*Y/K
Capital Accumulation
3: ACCUM
K = K(1)DEPR*(KK(1))/LOG(K/K(1))+I(1)
Investment Demand
4: INVEST
I = Y*MAX(0,I1*(MPKRR))
Consumption Demand
5: CONSUME LOG(C) = C1*LOG(Y)+C2*LOG(Y(+1))+C3*LOG(C(1))
Import Demand
6: IMPORT
LOG(IM/Y) = IM0+IM1*LOG(IM(1)/Y(1))IM2*LOG(ER)
Export Demand
7: EXPORT
LOG(X/YW) = X0+X1*LOG(X(1)/YW(1))+(1X1)*LOG(Y(1)/YW(1))+X2*
LOG(ER)
Money Demand
8: MONEY
LOG(MS/P) = MD0MD1*LOG(R)+MD2*LOG(Y)
Interest Rate Parity
9: PARITY
RW = RLOG(E(+1)/E)
Phillips Curve
10: PHIL
LOG(P(+1)/P(1))/2 = PC1/UPC0+(INFL(2)+INFL(+1))/2
National Income Identity
11: INCOME
Y = C+I+GOV+XIM
Definition of Unemployment
12: EMPLOY
U = 1L/LF
Definition of Real Exchange Rate
13: REALEX
ER = E/P
Definition of Real Interest Rate
14: REALRATE RR = RINFL
Definition of Inflation Rate
15: INFL
INFL = LOG(P(+1)/P)
1. Establishing Endpoints
Now that we have a model, we need some data. With a forwardlooking model, the problem of finding data
presents particular difficulties, because we need data not only for exogenous variables and initial conditions, but
also for terminal conditions. (There is also a formal requirement of data for contemporaneous endogenous
variables, but that data can simply be dummy values.) There are several possibilities as to data for terminal
conditions:
Use historical data. This may work well for counterfactual simulations that take place in the past.
However, obtaining reliable historical data for the future can be difficult.
Guess. If your simulation continues long after the period that interests you, then the terminal values may
not have much effect on the relevant simulation results, so you might just guess the terminal values.
Try various sets of values until you find one that has reasonable properties (smooth transition from the
last years of the simulation and reasonable results during those years). Unfortunately, there is no telling
how long this might take, and there will be room for question about whether your reasonable results are
reasonable enough. Moreover, the choice is not unique, and there is no objective way of choosing
between two equally reasonable value sets.
Create and simulate an analogous steadystate model in which you eliminate lags and leads by assuming
the values are the same as the contemporaneous values. If the resulting model can be solved (which is
not guaranteed, since constant values for some variables may imply nonconstant values for others), this
method is easy and straightforward. For most models, however, it's not very reasonable. One doesn't, for
example, imagine that national output will some day settle down to a constant value, even in an ideal
world without shocks.
Create and simulate an analogous "steady growth" model (or "steady state model with growth"). This
method is not always easy, but it avoids the shortcomings of the alternative methods. It also forces you to
be explicit about the longrun assumptions underlying your simulation. Once you have created a steady
growth model, it is relatively easy to make changes in that model to examine the effect of alternative
longrun assumptions. Some longrun assumptions may be implicit in your dynamic model, but may not
be readily apparent until you try to put the model in steadystate form.
Here we will use the last method, since it is usually considered the best, and since it is less straightforward than
the others. Converting a dynamic model into a steady growth model is to some extent an art rather than a
science. The following provides a rough description of the steps that may be involved:
1. Add parameter symbols to your model to represent growth rates for endogenous variables that contain
leads or lags. You have to decide which variables should have independent growth rates; typically, there
is one growth rate shared by most real variables, and one shared by most nominal variables. Some
variables  for example, the inflation rate, which already represents a growth rate  can be assumed
constant and therefore will not require new parameters.
2. Eliminate all endogenous leads and lags by rewriting the corresponding equations in terms of growth
rates.
3. If appropriate, simplify the resulting equations.
4. Delete any equations that have become trivial.
5. If necessary, complete the model either by deleting endogenous symbols (as many as the number of
equations you have deleted) or by adding new equations.
6. Differentiate (or first difference) the remaining equations of the model with respect to time to check for
consistency with growth rate assumptions.
7. If necessary for consistency, make some growth rates endogenous.
8. If you wish, make some exogenous variables endogenous, generated by parsimoniously parametrized
processes. (This may make it easier to specify alternative sets of longrun assumptions.)
9. Simulate the model over time, and check that all simulated values are consistent with assumed growth
rates.
10. If necessary, revise the model to provide internal consistency.
For our model, we're going to assume that all components of output grow at the same rate. (We'll require the
exogenous government purchases variable to grow at the same rate as the other components in the long run.)
Aside from government purchases, it is necessary and sufficient that the world interest rate and the real
exchange rate be constant. (We'll require the former and assume the latter.) We'll allow foreign output to grow at
a different (constant) rate than domestic output. On the nominal side, we'll assume a constant inflation rate.
Since inflation is already in the model, we need two new parameters, representing the domestic and foreign
growth rates. (To simplify some of the math in logarithmic equations, we use instantaneous growth rates rather
than periodic rates.)
TROLL Command: addsym parameter gr xgr ;
MODEDIT Command: symcom gr domestic growth rate ;
MODEDIT Command: symcom xgr foreign growth rate ;
Now to the equations. We can leave the first two alone (for now), since they have no leads or lags. In the capital
accumulation equation, there are lags for investment and capital. We set the lags equal to their corresponding
unlagged variables times exp(gr) and then simplify the equation. Except for the discretetime correction factor,
the result essentially says that the ratio of investment to the capital stock equals the depreciation rate plus the
growth rate. (For this particular equation, periodic growth rates  including a periodic depreciation rate  would
have simplified the arithmetic. We are being scrupulously consistent by using instantaneous growth rates. For a
periodic growth rate, we would use 1/(1+gr) instead of exp(gr).)
MODEDIT Command: changeq $k =$gr+depr =$ 3 ;
MODEDIT Command: changeq $k(1)depr*(kk(1))/log(k/k(1))+i(1)$
$oldstr$newstr$ [G] positionspec: (i/k)*(gr/(exp(gr)1))$ 3 ;
MODEDIT Command: // note: discretetime correction factor (gr/(exp(gr)1))
MODEDIT Command: //
is close to 1
MODEDIT Command: print equation 3 ;
Equations:
3: ACCUM
GR+DEPR = I/K*GR/(EXP(GR)1)
Next the consumption function, which contains a lead as well as lags. The procedure is the same, except that we
use exp(gr) (or 1+gr for a periodic growth rate) with leads instead of exp(gr) (or 1/(1+gr)). This time the
arithmetic is simpler because of the logs.
MODEDIT
MODEDIT
MODEDIT
MODEDIT
Command:
Command:
Command:
Command:
changeq $=$*(1c3)=$ 5 ;
changeq $c1$(c1+c2)$ 5 ;
changeq $c2*log(y(+1))+c3*log(c(1))$(c2c3)*gr$ 5 ;
print equation 5 ;
Equations:
5: CONSUME
LOG(C)*(1C3) = (C1+C2)*LOG(Y)+(C2C3)*GR
LOG(IM/Y)*(1IM1) = IM0IM2*LOG(ER)
The export equation contains a wrinkle, because it depends on foreign income, which grows at a different rate
than everything else. yw(1) becomes yw*exp(xgr).
MODEDIT Command: changeq $=$*(1x1)=$ 7 ;
MODEDIT Command: changeq $x1*log(x(1)/yw(1))+(1x1)*log(y(1)/yw(1))$
$oldstr$newstr$ [G] positionspec: xgrgr$ 7 ;
MODEDIT Command: changeq $yw$y$ 7 ;
MODEDIT Command: print equation 7 ;
Equations:
7: EXPORT
LOG(X/Y)*(1X1) = X0+XGRGR+X2*LOG(ER)
The next equation with a lag or lead is the interest rate parity condition. Since we don't have an assumption
explicitly about the growth rate of the nominal exchange rate, we need to do something different here. We start
with the assumption (noted earlier) that the real exchange rate is constant: in other words, er(+1) = er.
Combining this with the definition of the real exchange rate, applied both contemporaneously and with the lead,
we get rw = r + log(p(+1)/p). Substituting the definition of the inflation rate and then the definition of the real
interest rate, we get that the real interest rate is equal to the world interestrate.
MODEDIT Command: changeq $log(e(+1)/e)$r$ 9 ;
MODEDIT Command: print equation 9 ;
Equations:
9: PARITY
RW = RR
To put the Phillips curve in steadystate form, we simply apply the assumption of a constant inflation rate.
MODEDIT Command: changeq $+(infl(2)+infl(+1))/2$$ 10 ;
MODEDIT Command: changeq $log(p(+1)/p(1))/2$0$ 10 ;
MODEDIT Command: print equation 10 ;
Equations:
10: PHIL
0 = PC1/UPC0
Finally there is the definition of inflation. Technically, to put this equation into steadystate form, we would have
to substitute it into itself, which would result in a trivial statement. Therefore we delete this equation, which is
no longer necessary, since none of the other equations have lags or leads of the price level.
MODEDIT Command: deleq 15 ;
Unfortunately we end up with 15 endogenous variables and only 14 equations. We must either delete an
endogenous symbol or add a new equation. We still need all the endogenous symbols, so we have to add an
equation. But what? Let's take a look at what we have now.
MODEDIT Command: print equations all ;
Equations:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
PRODUCE
MPK
ACCUM
INVEST
CONSUME
IMPORT
EXPORT
MONEY
PARITY
PHIL
INCOME
EMPLOY
REALEX
REALRATE
LOG(Y) = CAPSHR*LOG(K)+(1CAPSHR)*LOG(L)+TECH
MPK = CAPSHR*Y/K
GR+DEPR = I/K*GR/(EXP(GR)1)
I = Y*MAX(0,I1*(MPKRR))
LOG(C)*(1C3) = (C1+C2)*LOG(Y)+(C2C3)*GR
LOG(IM/Y)*(1IM1) = IM0IM2*LOG(ER)
LOG(X/Y)*(1X1) = X0+XGRGR+X2*LOG(ER)
LOG(MS/P) = MD0MD1*LOG(R)+MD2*LOG(Y)
RW = RR
0 = PC1/UPC0
Y = C+I+GOV+XIM
U = 1L/LF
ER = E/P
RR = RINFL
We deleted an equation that related the inflation rate to the price level. That observation suggests that we need a
new equation relating those two variables. Looking at equations 8, 9, and 14  the only ones that now contain
the inflation rate, the price level, the nominal interest rate, and the nominal exchange rate  we can see that
these variables are undetermined, since we would need 4 equations to determine them even if all other variables
were known.
We have to make an educated guess about what to do next. What usually determines the inflation rate and the
price level in a longrun Keynesian model? Conceivably, government spending might determine inflation, but
we've already ruled that out by requiring the growth rate of government spending to equal that of the other
output components. The next answer is that growth of the money supply determines inflation. But notice, this
steadystate model doesn't say anything about money supply growth. To get money supply growth into the
model, we need to firstdifference the money demand equation. Notice also that the money demand equation
depends on log(p), so its first difference will depend on the inflation rate. Isn't that convenient!
First differencing the money demand equation, substituting y*exp(gr) for y(+1), rearranging, and substituting in
the definition of the inflation rate, we have:
MODEDIT Command: addeq bottom moneydif: log(ms(+1)/ms) = gr + infl ;
MODEDIT Command: eqcom moneydif Money First Difference ;
The steadystate model is now complete, but it's not yet internally consistent. To see that, first difference the
production function and substitute in the appropriate values for K(1) and Y(1). You get an equation that relates
the growth rate to changes in employed labor and the technology variable. The technology variable is
exogenous, and we have not yet imposed any requirements on its processes. Given the steady state Phillips
curve, the labor variable must be proportional to the labor force, which is also exogenous without any
restrictions.
We have a choice here. Either we can restrict one of the two exogenous variables to a specific process that is
consistent with an assumed growth rate, or we can make the growth rate endogenous and restrict the two
exogenous variables collectively to a class of processes that are consistent with a constant growth rate. The latter
possibility allows us to interpret the growth rate in terms of "truly exogenous" variables (changes in
endowments) instead of making it an arbitrary assumption. Moreover, the required restrictions on those
exogenous variables are rather weak: it is sufficient (but not necessary) that technology grow linearly and labor
grow exponentially. So here goes:
MODEDIT Command: changesym endogenous gr ; /* can't set gr arbitrarily */
MODEDIT Command: addeq bottom growth: gr =
Continue eq: (techtech(1))/(1capshr) + log(lf/lf(1));
MODEDIT Command: eqcom growth Growth Rate Depends on Labor and Technology;
The model is now complete and (as far as we know) consistent. But it could be more parsimonious. To simulate
the steadystate model we have to create data sets for the exogenous variables. Then, if we want to resimulate
with a new set of assumptions about the exogenous variables, we have to recreate the data sets. That's not a
problem technically, but it makes the results a little more difficult to talk about. It would be more convenient to
have a specific parametrization for the processes generating the exogenous variables. We might as well make
that parametrization part of the model.
By doing so, we will introduce dynamics into what should be a steady state model: not a problem as long as we
confine the dynamics to the datageneration processes. To make sure of that, let's examine the model now and
verify that it is a "steady state" model in the sense that there are no endogenous lags or leads. Once we're
satisfied with this "strictly steady state" part of the model, we can add some "conceptually exogenous"
dynamics.
MODEDIT Command: print comment all ;
Paradigm for Observing Nonlinear Dynamics
with Factor Redundancy, Overshooting, and Growth
Symbols:
ENDOGENOUS :
C
 real personal consumption
E
 nominal exchange rate (price of foreign currency)
ER
 real exchange rate (relative cost of imports)
GR
 domestic growth rate
I
 real private investment
IM
 real imports
INFL
 inflation rate
K
 capital stock
L
 employed labor
MPK
 marginal product of capital
P
 price level
R
 nominal interest rate
RR
 real interest rate
U
 unemployment rate
X
 real exports
Y
 real national income
EXOGENOUS :
LF
 labor force
RW
 world interest rate
TECH
 total factor productivity
YW
 world income
POLICY :
GOV
MS
COEFFICIENT :
C1 C2 C3 I1
PARAMETER :
IM0
IM1
IM2
MD0
MD1
MD2
PC0
PC1
X0
X1
X2
CAPSHR
DEPR
XGR
FUNCTION :
EXP LOG
 capital share
 depreciation rate
 foreign growth rate
MAX
Equations:
Production Function
1: PRODUCE LOG(Y) = CAPSHR*LOG(K)+(1CAPSHR)*LOG(L)+TECH
Marginal Product of Capital
2: MPK
MPK = CAPSHR*Y/K
Capital Accumulation
3: ACCUM
GR+DEPR = I/K*GR/(EXP(GR)1)
Investment Demand
4: INVEST
I = Y*MAX(0,I1*(MPKRR))
Consumption Demand
5: CONSUME LOG(C)*(1C3) = (C1+C2)*LOG(Y)+(C2C3)*GR
Import Demand
6: IMPORT
LOG(IM/Y)*(1IM1) = IM0IM2*LOG(ER)
Export Demand
7: EXPORT
LOG(X/Y)*(1X1) = X0+XGRGR+X2*LOG(ER)
Money Demand
8: MONEY
LOG(MS/P) = MD0MD1*LOG(R)+MD2*LOG(Y)
Interest Rate Parity
9: PARITY
RW = RR
Phillips Curve
10: PHIL
0 = PC1/UPC0
National Income Identity
11: INCOME
Y = C+I+GOV+XIM
Definition of Unemployment
12: EMPLOY
U = 1L/LF
Definition of Real Exchange Rate
13: REALEX
ER = E/P
Definition of Real Interest Rate
14: REALRATE RR = RINFL
Money First Difference
15: MONEYDIF LOG(MS(+1)/MS) = GR+INFL
Growth Rate Depends on Labor and Technology
16: GROWTH
GR = (TECHTECH(1))/(1CAPSHR)+LOG(LF/LF(1))
The only lags and leads are on ms, tech, and lf, all of which are either EXOGENOUS or POLICY symbols, so the
model appears to be acceptable. Let's proceed with the reparametrization. We'll begin with labor and
technology, and then proceed to money.
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
We're going to endogenize the money supply  but watch out! The model has a lead on the money supply. We
don't want to have to supply a terminal value for that, so let's rewrite the equation in terms of the growth rate.
MODEDIT Command: changeq $log(ms(+1)/ms)$mgr$ 15 ;
MODEDIT Command: print equation 15 ;
Equations:
15: MONEYDIF MGR = GR+INFL
MODEDIT Command: changesym endogenous ms ;
MODEDIT Command: addeq bottom moneys: ms = ms(1)*exp(mgr) ;
MODEDIT Command: eqcom moneys Money Supply Process ;
Now we'll parametrize the restofworld variables, yw and rw. In parametrizing yw explicitly, we also correct a
deficiency in the current model by forcing yw to behave in a manner consistent with the existing parameter xgr.
As for rw, we shall also enforce the requirement that it be constant, by making it a PARAMETER instead of an
EXOGENOUS variable. (A constant real interest rate was one of the necessary and sufficient conditions for the
components of output to grow at the same rates. TROLL does not allow PARAMETER symbols to vary over time.)
MODEDIT
MODEDIT
MODEDIT
MODEDIT
Command:
Command:
Command:
Command:
changesym endogenous yw ;
addeq bottom foreign: yw = exp(xgr)*yw(1) ;
eqcom foreign Growth of Output Abroad ;
changesym parameter rw ;
Now we're going to do something a little naughty. (Make sure your contentblocking program is disabled. No,
never mind.) The one remaining exogenous variable that we would like to parametrize is government purchases.
We have required that government purchases grow at the same rate as output. However, output (including the
level of output) is hopelessly endogenous. Moreover, it would seem rather strange to parametrize government
purchases with a starting value, when we don't know in advance what relationship that value would bear to the
level of output. How can we implement a more intuitive parametrization?
We could solve analytically for output as a function of the exogenous variables  but that would be rather a pain
in the buttocks. Instead, we're going to cheat and make government purchases depend endogenously on output.
(Mommy and Daddy don't get home for a few more hours; do they?) It could be dangerous to take a variable that
should be exogenous and move it right into the endogenous part of the model. To make sure we're safe, we'll use
the LKORD command to check for any equation blocks that might be altered by endogenizing government
purchases.
MODEDIT Command: print equations all ;
Equations:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
PRODUCE
MPK
ACCUM
INVEST
CONSUME
IMPORT
EXPORT
MONEY
PARITY
PHIL
INCOME
EMPLOY
REALEX
REALRATE
MONEYDIF
GROWTH
SOLOWRES
WORKERS
MONEYS
FOREIGN
LOG(Y) = CAPSHR*LOG(K)+(1CAPSHR)*LOG(L)+TECH
MPK = CAPSHR*Y/K
GR+DEPR = I/K*GR/(EXP(GR)1)
I = Y*MAX(0,I1*(MPKRR))
LOG(C)*(1C3) = (C1+C2)*LOG(Y)+(C2C3)*GR
LOG(IM/Y)*(1IM1) = IM0IM2*LOG(ER)
LOG(X/Y)*(1X1) = X0+XGRGR+X2*LOG(ER)
LOG(MS/P) = MD0MD1*LOG(R)+MD2*LOG(Y)
RW = RR
0 = PC1/UPC0
Y = C+I+GOV+XIM
U = 1L/LF
ER = E/P
RR = RINFL
MGR = GR+INFL
GR = (TECHTECH(1))/(1CAPSHR)+LOG(LF/LF(1))
TECH = TECH(1)+PROGRESS
LF = EXP(LGR)*LF(1)
MS = MS(1)*EXP(MGR)
YW = EXP(XGR)*YW(1)
Size
Eqn
Var
17
TECH
18
LF
16
GR
RR
10
12
1
2
3
4
Y
MPK
K
I
6
7
11
IM
ER
X
10
19
MS
11
15
INFL
12
14
13
14
13
15
20
YW
Our intention is to make government purchases depend on output. Look at the equation block that determines
output. None of the equations in that block (1,2,3, and 4) contains the gov variable, nor, for that matter, do any of
the earlier blocks. Therefore TROLL can solve for output without using any information about government
purchases. Moreover, once output is determined, if an equation specifies government purchases as a function of
output alone, then TROLL can solve that equation as a separate (nonsimultaneous) block. As far as the other
equation blocks are concerned, government purchases might as well have been exogenous. We will make it
endogenous, but don't tell our parents.
TROLL Command: // Don't try this kind of thing at home
TROLL Command: // unless you know what you're doing:
TROLL Command: changesym endogenous gov ;
MODEDIT Command: addsym parameter govfrac ;
MODEDIT Command: symcom govfrac public sector share of output ;
MODEDIT Command: addeq bottom govspend: gov = govfrac*y ;
/* endogenous */
MODEDIT Command: eqcom govspend Government Purchases ;
Now that we have a complete, consistent, and wellparametrized model, we name it, display it, and save it.
MODEDIT Command: modcom Paradigm for Observing Nonlinear Dynamic
Comment or ';': Model Analogue in the Steady State ;
MODEDIT Command: print comment all ;
Paradigm for Observing Nonlinear Dynamic
Model Analogue in the Steady State
Symbols:
ENDOGENOUS :
C
 real personal consumption
E
 nominal exchange rate (price of foreign currency)
ER
 real exchange rate (relative cost of imports)
GOV
 real government purchases
GR
 domestic growth rate
I
 real private investment
IM
 real imports
INFL
 inflation rate
K
 capital stock
L
 employed labor
LF
 labor force
MPK
 marginal product of capital
MS
 money supply
P
 price level
R
 nominal interest rate
RR
 real interest rate
TECH
 total factor productivity
U
 unemployment rate
X
 real exports
Y
 real national income
YW
 world income
COEFFICIENT :
C1 C2 C3 I1
PARAMETER :
CAPSHR
DEPR
GOVFRAC
LGR
MGR
PROGRESS
RW
XGR
FUNCTION :
EXP LOG
MAX
Equations:
IM0
IM1
IM2
MD0
MD1
MD2
capital share
depreciation rate
public sector share of output
labor force growth rate
money supply growth rate
rate of technological progress
world interest rate
foreign growth rate
PC0
PC1
X0
X1
X2
Production Function
1: PRODUCE LOG(Y) = CAPSHR*LOG(K)+(1CAPSHR)*LOG(L)+TECH
Marginal Product of Capital
2: MPK
MPK = CAPSHR*Y/K
Capital Accumulation
3: ACCUM
GR+DEPR = I/K*GR/(EXP(GR)1)
Investment Demand
4: INVEST
I = Y*MAX(0,I1*(MPKRR))
Consumption Demand
5: CONSUME LOG(C)*(1C3) = (C1+C2)*LOG(Y)+(C2C3)*GR
Import Demand
6: IMPORT
LOG(IM/Y)*(1IM1) = IM0IM2*LOG(ER)
Export Demand
7: EXPORT
LOG(X/Y)*(1X1) = X0+XGRGR+X2*LOG(ER)
Money Demand
8: MONEY
LOG(MS/P) = MD0MD1*LOG(R)+MD2*LOG(Y)
Interest Rate Parity
9: PARITY
RW = RR
Phillips Curve
10: PHIL
0 = PC1/UPC0
National Income Identity
11: INCOME
Y = C+I+GOV+XIM
Definition of Unemployment
12: EMPLOY
U = 1L/LF
Definition of Real Exchange Rate
13: REALEX
ER = E/P
Definition of Real Interest Rate
14: REALRATE RR = RINFL
Money First Difference
15: MONEYDIF MGR = GR+INFL
Growth Rate Depends on Labor and Technology
16: GROWTH
GR = (TECHTECH(1))/(1CAPSHR)+LOG(LF/LF(1))
Evolution of Total Factor Productivity
17: SOLOWRES TECH = TECH(1)+PROGRESS
Growth of Labor Force
18: WORKERS LF = EXP(LGR)*LF(1)
Money Supply Process
19: MONEYS
MS = MS(1)*EXP(MGR)
Growth of Output Abroad
20: FOREIGN YW = EXP(XGR)*YW(1)
Government Purchases
21: GOVSPEND GOV = GOVFRAC*Y
MODEDIT Command: filemod pondmass ;
Before we declare victory it's a good idea to check whether the steadystate model performs in a manner
consistent with a steadystate. In other words, if we simulate over time using a set of exogenous values that are
consistent with the restrictions we have placed on exogenous variables, then solutions generated from each
period in the simulation should be consistent with solutions generated from the next period. For example, if the
inflation rate is calculated as 10 percent in one period, the price level in the following period should be 10
percent higher (actually, not quite, since we're using instantaneous inflation rates in discrete time). Otherwise the
behavior of the model would be timedependent, which would contradict the definition of a steady state.
An easy way to implement this consistency check is to simulate the discrepancies directly as part of the model.
If all goes well, the results should all be zero. The following section of code adds a set of consistency checks to
the model.
TROLL Command: addsym endogenous res_p res_infl res_y res_c res_i res_k
Symbolname, ',' or ';': res_im res_x res_r res_er res_rr ;
MODEDIT Command: symcom res_p price level growth discrepancy ;
MODEDIT Command: symcom res_infl inflation acceleration discrepancy ;
MODEDIT Command: symcom res_c consumption growth discrepancy ;
MODEDIT Command: symcom res_i investment growth discrepancy ;
MODEDIT Command: symcom res_k capital growth discrepancy ;
MODEDIT Command: symcom res_r interest rate parity discrepancy ;
MODEDIT Command: symcom res_im import growth discrepancy ;
MODEDIT Command: symcom res_x export growth discrepancy ;
MODEDIT Command: symcom res_er real currency depreciation ;
MODEDIT Command: symcom res_rr change in real interest rate ;
MODEDIT Command: addeq bottom pverify: res_p = log(p/p(1))  infl(1) ;
MODEDIT Command: eqcom pverify Price Growth Verification ;
MODEDIT Command: addeq bottom infverif: res_infl = infl  infl(1) ;
MODEDIT Command: eqcom infverif Inflation Stability Verification ;
MODEDIT Command: addeq bottom yverify: res_y = log(y/y(1))  gr ;
MODEDIT Command: eqcom yverify Output Growth Verification ;
MODEDIT Command: addeq bottom cverify: res_c = log(c/c(1))  gr ;
MODEDIT Command: eqcom cverify Consumption Growth Verification ;
MODEDIT Command: addeq bottom iverify: res_i = log(i/i(1))  gr ;
MODEDIT Command: eqcom iverify Investment Growth Verification ;
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
Comment
MODEDIT
Now we generate a set of artificial data and simulate the model to check for consistency.
TROLL Command: // Steady State Parameters
TROLL Command: do xgr = 0.105, progress = 0.001, lgr = 0.1, mgr = 0.2 ;
TROLL Command: do capshr=0.25, depr=0.1, gr=0.1, govfrac=0.1, rw=0.1 ;
TROLL Command:
TROLL Command: // Starting Values
TROLL Command: do lf=1.5, tech=0.015, y=0.75, yw=5, ms=1 ;
TROLL Command:
TROLL Command: // Dummy Data (also used as to initialize iterations)
TROLL Command: do l=1, infl=0, p=1, c=.5, i=.2, im=.1, x=.1, e=1, k=.5 ;
TROLL Command: do u=.05, r=.1, rr=.1, mpk=.5, er=1, gov=.1 ;
TROLL Command: do res_p=0, res_infl=0, res_y=0, res_c=0, res_i=0, res_k=0 ;
TROLL Command: do res_r=0, res_er=0, res_rr=0, res_im=0, res_x=0 ;
TROLL Command:
TROLL Command: // Model Coefficients
TROLL Command: do c1=.2, c2=.2, c3=.6 ;
TROLL Command: do i1=.25 ;
TROLL Command: do im0 = .2, im1=.8, im2=.2 ;
TROLL Command: do md0=3, md1=.05, md2=1 ;
TROLL Command: do pc1=.01, pc0=.2 ;
TROLL Command: do x0=.5, x1=.8, x2=.2 ;
TROLL Command:
TROLL Command: lkord all ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
The model has 27 blocks, including 2 simultaneous blocks.
The largest block has 4 equations and the next largest has 3.
Block
Size
Eqn
Var
17
TECH
18
LF
16
GR
RR
10
12
1
2
3
4
Y
MPK
K
I
21
GOV
10
6
7
11
IM
ER
X
11
19
MS
12
15
INFL
13
14
14
15
13
16
20
YW
17
22
RES_P
18
23
RES_INFL
19
24
RES_Y
20
25
RES_C
21
26
RES_I
22
27
RES_K
23
28
RES_IM
24
29
RES_X
25
30
RES_R
26
31
RES_ER
27
32
RES_RR
RES_IM
RES_X
RES_R
RES_ER
RES_RR
7A
Solution: RES_P
RES_INFL
RES_Y
RES_C
RES_I
RES_K
RES_IM
RES_X
RES_R
RES_ER
RES_RR
8A
Solution: RES_P
RES_INFL
RES_Y
RES_C
RES_I
RES_K
RES_IM
RES_X
RES_R
RES_ER
RES_RR
9A
Solution: RES_P
RES_INFL
RES_Y
RES_C
RES_I
RES_K
RES_IM
RES_X
RES_R
RES_ER
RES_RR
10A
Solution: RES_P
RES_INFL
RES_Y
RES_C
RES_I
RES_K
RES_IM
RES_X
RES_R
RES_ER
RES_RR
11A
Solution: RES_P
RES_INFL
RES_Y
RES_C
RES_I
RES_K
RES_IM
RES_X
RES_R
RES_ER
RES_RR
SIMULATE Command: quit ;
2.08166817e016
5.9674488e016
3.05311332e016
4.4408921e016
0
9.71445147e017
0
1.9428903e016
4.0245585e016
4.0245585e016
1.9428903e016
1.4016566e015
9.99200722e016
1.3045121e015
1.33226763e015
0
3.0531133e016
0
2.08166817e016
4.02455846e016
2.08166817e016
2.08166817e016
1.40165657e015
1.4016566e015
1.70696790e015
1.4432899e015
0
9.71445147e017
0
2.08166817e016
1.9428903e016
2.08166817e016
0
8.0491169e016
1.40165657e015
9.0205621e016
6.66133815e016
0
9.7144515e017
0
2.08166817e016
4.02455846e016
0
0
5.96744876e016
9.9920072e016
7.07767178e016
5.5511151e016
0
7.07767178e016
0
4.0245585e016
4.0245585e016
1.9428903e016
4.0245585e016
4.0245585e016
1.9428903e016
7.0776718e016
0
0
Basta. Compared to the scale of the data, all those numbers are zero (except for the first year, when there are no
prioryear results with which to be consistent). In general it might be wise to try some other parameter values,
but we'll move on.
Simulating with artificial data can give us more confidence in the steadystate model, but it does not give us
meaningful terminal conditions. Presumably we will get the initial conditions from historical data, and the
terminal conditions must be consistent with that data. We need to simulate the steadystate model in the
historical context where we expect to use the dynamic model.
The situation here is even more problematic because the coefficient values are arbitrary  not estimated from
data or even calibrated informally based on some empirical context. We would need huge add factors to make
the model consistent with any specific historical data.
To solve (or at least mitigate) this problem, we undertake an ultraminimal calibration procedure. Essentially, we
begin with a few semiarbitrary assumptions about the coefficient values, and then we calculate the rest from
pointintime data as if that data represented a steady state. We cannot expect this procedure to produce a
realistic set of coefficients, but at least it gives us an anchor in the real world.
The historical context is Canada in 1996. We begin creating a file with empirical data for the variables in our
model:
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
We assume the following coefficients equal to the same values we originally used. The only justification is that
they seem vaguely reasonable.
TROLL Command: // Assumed coefficient values
TROLL Command: do im1=.8, im2=.2, x1=.8, x2=.2, md1=.05, md2=1, pc1=.01 ;
Given those assumptions and the data above, we solve the equations of the steadystate model for the following
coefficients:
TROLL Command: // Calculated coefficient values
TROLL Command: do i1=.6, im0=.14, x0=.26, md0=3.2, pc0=.1 ;
Finally, to identify the consumption function, we first require that the coefficients sum to unity. That
requirement comes from our definition of the steady state, which requires consumption to grow at the same rate
as income. Then, for no particular reason except to identify the coefficients, we assume that the coefficients on
current and future income are equal. We are now able to calculate the values from the steadystate equation.
TROLL Command: // Calculated subject to c1=c2 and c1+c2+c3=1
TROLL Command: do c1=.02, c2=.02, c3=.96 ;
We are now ready to construct the steady state solution that will give us our terminal values.
TROLL Command: usemod pondmass ;
TROLL Command: simulate ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from NA to NA.
SIMULATE Command: simstart 1997a ;
SIMULATE Command: list solutions all ;
SIMULATE Command: dosim 4 ;
Date:
What:
Value:
1997A
Solution:
INFL
P
Y
0.010537
0.871322
865.074203
1998A
Solution:
1999A
Solution:
2000A
Solution:
C
I
X
IM
E
ER
MPK
U
K
L
R
RR
LF
TECH
YW
MS
GOV
GR
INFL
P
Y
C
I
X
IM
E
ER
MPK
U
K
L
R
RR
LF
TECH
YW
MS
GOV
GR
INFL
P
Y
C
I
X
IM
E
ER
MPK
U
K
L
R
RR
LF
TECH
YW
MS
GOV
GR
INFL
P
Y
C
I
X
IM
E
ER
MPK
U
K
L
R
RR
LF
TECH
YW
MS
GOV
GR
547.543632
94.459097
348.676687
298.620055
1.25345
1.438561
0.211987
0.1
1346.663506
13662.9759
0.040537
0.03
15181.084333
1.995
51265.756026
36.065909
173.014841
0.019463
0.010537
0.880552
882.075767
558.304663
96.31553
355.529335
304.488914
1.266727
1.438561
0.211987
0.1
1373.12989
13827.919292
0.040537
0.03
15364.354768
1.99
52563.554819
37.164279
176.415153
0.019463
0.010537
0.88988
899.411484
569.277203
98.20845
362.516666
310.473132
1.280146
1.438561
0.211987
0.1
1400.11645
13994.853928
0.040537
0.03
15549.837697
1.985
53894.207544
38.2961
179.882297
0.019463
0.010537
0.899306
917.087905
580.465389
100.138572
369.641322
316.57496
1.293707
1.438561
0.211987
0.1
1427.633386
14163.803847
0.040537
0.03
15737.55983
1.98
55258.545904
39.46239
183.417581
0.019463
No complaints: looks like it worked. Now save these results to use as input data for dynamic simulations.
SIMULATE Command: filesim cass ;
2500A
2500A
2500A
0.010537
174.604746 15441150.478253
IM
1686048.583587
6223707.945126
5330221.420004
ER
MPK
1.438561
0.211987
0.1
RR
0.040537
0.03
YW
MS
5714086.297215
TECH
2500A
0.52
1.48279283e+010 1.29003238e+008
C
9773385.273894
E
251.179565
K
24037283.476966
LF
6348984.774683
GOV
3088230.095651
GR
2500A
0.019463
There are some very large numbers here, but nothing inappropriate for the year 2500, given that our model
includes continuing growth. (Seeing these numbers might lead one to question some aspects of the model or the
assumed exogenous processes. For example, is the labor force growth assumption consistent with finite natural
resources? A scrupulous modeller might be inclined to go back and change some assumptions. Here, since this is
only an example, we will merely wave our hands and trust that Godot will appear sometime during the
millennium with whatever can opener is required.)
1. Temporary Shocks
To make things interesting, we'll add a shock. In particular, we'll add a "temporary" shock  one that recedes
completely before the end of our simulation period. Because the shock is temporary, it will be consistent with an
economy that returns to the same steady state in the long run. Therefore the same terminal values will apply in
the "shocked" simulation.
Note that the same would not be true of a prominent shock. You could not model a permanent shock using the
same terminal values (unless for some reason the effect of the shock on all leaded variables decays to zero over
time). Instead, you would have to generate an alternative set of steadystate results to use as input data for the
"shocked" simulation. Or perhaps you could figure out analytically what the longrun effect of the shock would
be  in which case you could change the data series directly instead of running a new steadystate simulation.
For now, we'll keep things simple  a shock with no strings attached.
SIMULATE
SIMULATE
SIMULATE
SIMULATE
SIMULATE
SIMULATE
SIMULATE
Command:
Command:
Command:
Command:
Command:
Command:
Command:
delsearch cass ;
delsave all ;
search after save cass ;
do ms = cass_ms ;
do t = crseries ( 1996a, seq(150) ) ;
do shock = if (t > 20 and t < 71) then 1.1 else 1.0 ;
do prt.(shock);
SHOCK:
SHOCK = IF (T > 20 AND T < 71) THEN 1.1 ELSE 1
Numeric scalar timeseries Time dimension: Periodicity 1,
1996A:
2000A:
2004A:
2008A:
2012A:
2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:
2096A:
2100A:
2104A:
2108A:
2112A:
2116A:
2120A:
2124A:
2128A:
2132A:
2136A:
2140A:
2144A:
1
1
1
1
1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1.1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
This is a multiplicative shock, which could in principle be applied to any of our exogenous (EXOGENOUS or
POLICY) variables. We will apply it to the money supply. But first we will perform a baseline simulation with
which to compare the "shocked" results.
SIMULATE Command: usemod pondfrog ;
TROLL Command: simulate stack 100 ;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Constructing stackedtime incidence matrix and code.
Simulations can start from 1999A to 2499A and must end by 2499A.
SIMULATE Command: simstart 2000a ;
SIMULATE Command: dostack 1 ;
SIMULATE Command: savesim baseline ;
SIMULATE Command: quit ;
That was exciting! Wasn't it? Okay, so you're not quite on the edge of your seat yet. It's more interesting to look
at the results than to watch TROLL crunch the numbers.
TROLL Command: do prt.(shocked_e/baseline_e) ;
SHOCKED_E/BASELINE_E:
Numeric scalar timeseries Time dimension: Periodicity 1,
2000A:
2004A:
2008A:
2012A:
2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:
2096A:
0.999923
0.999767
1.00033
1.013019
1.093486
1.102248
1.100412
1.100297
1.100236
1.100195
1.100165
1.100146
1.100151
1.100153
1.099275
1.089569
1.033069
0.999252
1.000275
1.000093
1.000104
1.000086
1.000072
1.000057
1.000031
0.999899
0.999767
1.001397
1.026054
1.099684
1.100966
1.100437
1.100271
1.100225
1.100186
1.100158
1.100144
1.100157
1.100103
1.098371
1.082217
1.005152
0.998897
1.000237
1.000104
1.000098
1.000083
1.000068
1.000052
1.000021
0.999857
0.999768
1.003057
1.047172
1.103544
1.100407
1.100399
1.100257
1.100214
1.100179
1.100153
1.100144
1.100164
1.099993
1.09681
1.071205
1.005435
0.999507
1.000148
1.000111
1.000093
1.000079
1.000065
1.000046
1.00001
2000A:
2004A:
2008A:
2012A:
2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:
2096A:
0.999962
0.999861
0.999517
1.001138
0.985753
1.003821
0.999994
1.000188
1.000144
1.000133
1.000122
1.000112
1.000116
1.000185
1.000401
0.999815
0.99069
1.002301
1.000078
1.000052
1.000091
1.000076
1.000068
1.000058
1.000042
0.999921
0.999574
0.998089
0.99629
0.988285
1.002003
1.000174
1.000154
1.000143
1.00013
1.00012
1.000112
1.000128
1.000249
1.000595
0.999858
0.99234
0.998659
1.000337
1.000053
1.000086
1.000075
1.000066
1.000055
1.000031
0.999938
0.999717
0.999527
1.010834
0.997837
1.000485
1.000255
1.000142
1.00014
1.000128
1.000117
1.000111
1.000136
1.000277
1.000424
0.99723
1.010173
0.998289
1.000255
1.000074
1.000082
1.000073
1.000063
1.000052
1.000025
Time dimension:
2000A:
2004A:
2008A:
2012A:
2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:
2096A:
Periodicity 1,
0.099981
0.09988
0.099355
0.096874
0.105864
0.098325
0.100261
0.099973
0.100002
0.1
0.1
0.1
0.1
0.099991
0.099922
0.09988
0.105612
0.095945
0.100248
0.100001
0.099997
0.100001
0.1
0.099999
0.099998
0.100045
0.100314
0.102023
0.112552
0.112127
0.098588
0.100124
0.099994
0.1
0.1
0.1
0.099999
0.099991
0.099929
0.099553
0.097965
0.117618
0.099615
0.099889
0.100025
0.099997
0.1
0.1
0.100001
0.100007
0.099945
0.099724
0.098509
0.095914
0.106932
0.099583
0.100001
0.100005
0.099999
0.1
0.1
0.100001
0.099998
0.09997
0.099847
0.10085
0.09738
0.101059
0.099842
0.100017
0.099999
0.1
0.1
0.099999
0.099996
Perhaps you don't find these results riveting. There are a couple of things you should notice, though. First, these
results don't in general look like much of a change from the baseline case. Bear in mind that this simulation
represents a fully anticipated and purely monetary shock, so changes in real variables can result only from
nominal rigidities and backwardlooking behavior. The shock is "fully anticipated" in the sense that all the
periods before and during the shock are stacked together (STACK=100), and there is enough time (16 years)
before the shock to allow full anticipation.
Note that our Phillips curve has a short backwardlooking horizon (with only one lag on the righthand side and
no structural mean reversion), so we shouldn't expect to see persistent deviations from baseline. What we do see
is noteworthy: the unemployment rate dips more than 2 percentage points below baseline in the first year of the
shock (2016).
Finally, you should notice that the pattern of the results is not simple. The shock itself simply starts in 2016 and
ends in 2066, with no other variation, but both the real exchange rate and the unemployment rate fluctuate above
and below baseline repeatedly. With only 15 equations, PONDFROG is a small model, but not a simple one.
To make it more interesting, let's look at what happens when the shock is not anticipated before it begins. Using
our steadystate data for initial conditions, we can start the simulation in 2016, when the shock begins, and
observe how the shock upsets the initial equilibrium.
TROLL Command: simulate stack 80 ;
Constructing stackedtime incidence matrix and code.
Simulations can start from 1999A to 2145A and must end by 2145A.
SIMULATE Command: simstart 2016a ;
SIMULATE Command: dostack 1 ;
SIMULATE Command: savesim suddenshock ;
SIMULATE Command: quit ;
TROLL Command:
TROLL Command: do prt.(suddenshock_e/baseline_e) ;
SUDDENSHOCK_E/BASELINE_E:
Numeric scalar timeseries Time dimension: Periodicity 1,
2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
1.095771
1.098387
1.097544
1.097951
1.098259
1.098536
1.098771
1.098975
1.099169
1.099328
1.098585
1.089003
1.09448
1.097995
1.097673
1.098025
1.098333
1.098598
1.098825
1.099024
1.099216
1.099314
1.097712
1.081682
1.0965
1.097607
1.097789
1.098103
1.098404
1.098658
1.098876
1.099072
1.099263
1.099238
1.096182
1.070701
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:
1.054357
1.001296
0.999745
0.999824
0.999879
0.999896
0.999917
0.999949
1.032621
0.99888
0.999962
0.99983
0.999883
0.999902
0.999924
0.999961
1.004725
0.99854
0.999937
0.999852
0.999887
0.999907
0.999931
0.999974
1.005029
0.999165
0.99986
0.99987
0.999891
0.999912
0.999939
0.99999
2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:
1.010088
1.001928
1.000047
0.999726
0.999465
0.999362
0.999332
0.99935
0.999407
0.999542
0.999828
0.999311
0.990249
1.001922
0.99975
0.999772
0.999852
0.999873
0.999897
0.999928
0.997717
1.002023
0.999918
0.999638
0.999431
0.999349
0.999333
0.999361
0.999435
0.999623
1.000039
0.999371
0.991912
0.998294
1.000022
0.999783
0.999857
0.99988
0.999905
0.999949
0.996913
1.001206
0.999872
0.999564
0.999403
0.99934
0.999337
0.999373
0.99946
0.999668
0.999886
0.99676
1.009762
0.997936
0.999952
0.999816
0.999861
0.999886
0.99991
0.999957
2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:
0.088715
0.100544
0.100047
0.099988
0.100003
0.1
0.100001
0.100001
0.1
0.099991
0.099923
0.09988
0.105612
0.095943
0.100249
0.100001
0.099997
0.100001
0.100001
0.100004
0.100801
0.099454
0.100099
0.09999
0.100002
0.100001
0.1
0.099999
0.099991
0.099929
0.099553
0.097964
0.117626
0.099615
0.099889
0.100025
0.099997
0.1
0.099998
0.099987
0.104343
0.099451
0.100055
0.099998
0.100001
0.100001
0.100001
0.100001
0.099998
0.09997
0.099847
0.10085
0.097381
0.101059
0.099842
0.100017
0.099999
0.100001
0.100002
0.100008
The first thing you should notice here is the initial response of the nominal exchange rate. In classic "Dornbusch
overshooting" fashion, the exchange rate (relative to baseline) rises by a greater proportion (10.5%) than the
shock to the money supply (10.0%). The next year, the exchange rate falls to a level below its new equilibrium,
which it then approaches hesitatingly. Unlike the fully anticipated case, the new equilibrium (around 1.0985) is
below the "parity" level of 1.01, so that the real exchange rate is below  rather than above  baseline.
You might have expected some fancy acrobatics from the unemployment rate in response to this unanticipated
shock. Actually, it seems to behave more sedately than in the fully anticipated case: although the initial dip is
slightly larger and it takes another year to recover, the unemployment rate subsequently remains essentially at
baseline until the end of the shock approaches. Apparently the financial markets' response to the unanticipated
shock serves to dampen the internal cyclical dynamics of the real sector.
Why does this model exhibit such strange dynamics? Why do fully anticipated shocks produce cyclical
responses? Why does the exchange rate seem to react against its initial response to an unanticipated shock? We
can't answer these questions here, but we can provide some clues. First of all,
TROLL Command: simulate roots ;
Constructing stackedtime incidence matrix and code.
Simulations can start from 1999A to 2145A and must end by 2145A.
SIMULATE Command: simstart 2016a ;
SIMULATE Command: lkroots elasticity ;
Statespace eigenanalysis of PONDFROG linearized around 2016A:
There are 10 eigenvalues with modulus between 0.001 and 1000,
consisting of 6 real roots and 2 complexconjugate pairs.
There are 4 eigenvalues with modulus larger than 1.0
(including 0 larger than 1000) for 4 lead variables.
1:
2+
4:
5:
6:
7:
8:
9+
Real
127.35671865
1.58323319
1.58026206
0.97678244
0.93004710
0.81572266
0.64401733
0.34533697
+Imaginary
0.21092621
0.45641323
0.00000000i
0.1649
0.3134
1.0168
1.0010
0.2180
0.2183
0.3048
0.3048
1.0090
0.1650
0.2166
0.6282
0.3054
0.3134
0.21092621i
0.1038
0.1371
0.1274
0.3756
0.2809
0.1826
0.1907
0.2889
0.5414
0.2526
0.00000000i
0.4568
0.4124
0.3740
0.2951
0.1097
0.1456
0.4686
0.1188
0.1809
0.4568
Magnitude
127.35671865
1.59722171
1.58026206
0.97678244
0.93004710
0.81572266
0.64401733
0.57233789
Period
47.43993418
2.00000000
6.80687885
I
Y
0
0
0.3178
0.2413
L
U
0
0
0.4568
0.4568
Equation 12
Equation 14
Root 5:
Equation
Root 6:
Equation
Equation
Root 7:
Equation
Equation
Root 8:
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Root 9:
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Equation
Equation
INFL
0
RR
0
0.97678244
5
C
0
C
1
0.93004710
3
K
0
K
1
7
X
0
0.81572266
6
IM
0
IM
1
7
X
0
X
1
0.64401733
3
I
1
K
0
K
1
4
I
0
RR
0
6
IM
0
IM
1
Y
1
7
ER
0
X
0
X
1
9
E
1
E
0
R
0
13
E
0
ER
0
14
R
0
RR
0
15
P
1
P
0
0.34533697
1
K
0
L
0
Y
0
3
I
1
K
1
4
I
0
RR
0
8
P
0
R
0
10
INFL
2
P
1
U
0
11
I
0
12
L
0
U
0
14
INFL
0
RR
0
15
INFL
0
P
1
0.3291
0.2951
0.00000000i
1.0993
1.1016
0.00000000i
1.0931
1.1179
0.1016
0.00000000i
0.4547
0.4547
0.5453
0.5453
0.00000000i
0.1301
0.2728
0.4029
0.2190
0.1997
0.2781
0.3522
0.1057
0.1125
0.3064
0.3881
0.2975
0.4669
0.1693
0.1693
0.2089
0.1618
0.1997
0.1291
0.2026
0.45641323i
0.1117
0.2849
0.1732
0.1475
0.1598
0.2882
0.2066
0.1900
0.1036
0.4538
0.1006
0.2849
0.1407
0.2849
0.2849
0.1129
0.2066
0.2590
0.1521
0.1069
With one negative root and two pairs of complex roots, we have no less than three kinds of cycles that this
model can generate. (And that's just the linearized version!)
Where do these cycles come from? If you look at the elasticities, you can see that all of the cyclical roots (2, 4,
and 9) depend on both the money demand equation (equation 8) and the Phillips curve (equation 10), among
other things. Moreover, none of the noncyclical roots depend on the Phillips curve. Notice that the Phillips
curve includes (among other things) an implicit inverse relationship between P(+1) and P(2) (from the
definition of INFL(2)). Without beginning a detailed exploration of the implications of that relationship, we can
surmise that it would be a good place to start looking for endogenous cycles. (If you're interested, you might try
building some simple models with a similar Phillips curve dynamic.)
2000A:
2004A:
2008A:
2012A:
2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:
2096A:
0.099987
0.099919
0.099569
0.097835
0.113305
0.079713
0.102305
0.099895
0.100465
0.105149
0.081116
0.102077
0.099916
0.100474
0.105184
0.082116
0.107849
0.095737
0.100267
0.099995
0.100089
0.09999
0.100002
0.100008
0.100029
0.100033
0.10023
0.101482
0.109173
0.101893
0.090292
0.10048
0.099684
0.098013
0.090334
0.091292
0.100391
0.099684
0.098
0.090218
0.089371
0.11853
0.099618
0.099884
0.099982
0.100027
0.099999
0.099999
0.099988
0.099897
0.099963
0.099815
0.098997
0.096676
0.125635
0.100032
0.099648
0.100238
0.101465
0.117685
0.100207
0.09966
0.100237
0.101484
0.117802
0.100869
0.097164
0.101135
0.099837
0.099964
0.099987
0.100003
0.100004
0.100016
0.100052
2000A:
2004A:
2008A:
2012A:
2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:
2096A:
7.8730808e006
3.2132180e005
0.000215
0.001351
0.002849
0.010181
0.003049
0.000528
0.000797
0.004469
0.010254
0.003
0.00053
0.000774
0.004327
0.008496
0.002839
0.000432
5.52560011e005
9.8282828e006
9.03653893e005
1.9589439e005
1.51310888e006
4.0025019e006
3.7642310e005
6.14197820e006
3.89752558e005
0.000214
0.000961
0.007441
0.018612
0.002044
7.7990101e005
0.000463
0.005149
0.018884
0.002076
8.4028869e005
0.000483
0.005262
0.017764
0.002237
0.000208
1.81689638e005
6.2459550e006
9.24437720e005
1.0171988e005
2.40717682e006
8.62229189e006
3.11513855e005
1.2066885e005
8.3993102e005
0.000541
0.003378
0.010234
0.008296
0.000356
0.00031
0.001987
0.009666
0.008708
0.000392
0.000307
0.001929
0.009336
0.008593
0.000912
3.25737340e006
5.3381795e006
4.2944064e005
3.02326216e005
1.4793386e006
1.4220049e006
1.2311662e005
0.000109
1.72779683e005
9.12693038e005
0.000487
0.000762
0.018702
0.000449
0.000353
0.000233
0.001466
0.017684
0.000207
0.00034
0.000239
0.001514
0.017955
1.90522509e005
0.000216
7.61579870e005
4.4551699e006
5.2981089e005
1.1670389e005
3.05558596e006
3.81217691e006
1.69016135e005
5.55179000e005
0.000683
0.018702
0.005477
0.000149
0.017618
0.003779
4. Permanent Shocks
To simulate permanent shocks, you must change the terminal values to be consistent with the shock. Normally,
you will accomplish this change by running the steadystate simulation again with the new set of parameters.
Someday perhaps this Guide will contain an example.
E. IMPERFECT FORESIGHT
1. OneTime Unanticipated Shock
To model a onetime unanticipated shock (an "unseen oneshot shock"), one approach is as follows:
"expected" counterparts.
For each leaded or lagged endogenous variable, change the superscript by adding the lag
or lead to it. (e.g., Y8(3) becomes Y5(3), and Y8(+3) becomes Y11(+3).)
If any lagged variable ends up with the superscript less than zero, change the
superscript to zero (so that Y2(4) becomes Y0(4)).
If any leaded variable ends up with the superscript greater than N1, change the
superscript to zero (so that, for N=50, Y49(+1) becomes Y0(+1))
Simulate the modified model. Variables with superscript zero represent realized values, and those
with other superscripts represent anticipated values.
Commands
Functions
Programming
User's Guide
3. NONASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS
II. CYCLING
If your simulation continues for many, many iterations without converging, it may be cycling. You could try to fix this problem
by using DAMP. But probably there is something wrong with your model.
III. NONASSIGNABILITY
Just because the number of equations matches the number of variables doesn't mean that there is a valid normalization. If not,
you have to fix the model.
A singular Jacobian usually means that the simulator is searching for a solution in a neighborhood where a unique solution does
not exist. That may be because the model has a continuum of solutions, in which case you need to change the model in such a
way as to give a preferred solution within that continuum. On the other hand, there may be a unique solution somewhere else.
This situation is similar to that of illegal iterations, described below, and the same approaches are appropriate.
In rare cases, a singular Jacobian may merely represent a technical failure of the algorithm due to roundoff error or a similar
cause. In those cases, anything that "tweaks" the solution algorithm to run a little bit differently may well solve the problem. For
example, changing convergence parameters may help, and any of the procedures described below for dealing with illegal
iterations may also help.
C. DAMPING ITERATIONS
The DAMP parameter defaults to 1.0, but it can be changed with "conopt damp". A DAMP value less than 1.0 will cause the
Newton iterations to become less aggressive, so that they are less likely to wander into an illegal region.
F. NEW MODEL
You should always consider the possibility that there is something inherently wrong with your model in the context of
the data to which you are trying to apply it. If so, you have to change it.