You are on page 1of 317

Commands

Functions
Programming

User's Guide

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide: Table of Contents


User's Guide generated 2003-3-27 for TROLL Release 1.2

Chapter One. Introduction And Overview


I. PORTABLE TROLL
A. THE PORTABLE TROLL USER'S GUIDE
B. CONVENTIONS USED IN THIS GUIDE
II. GETTING STARTED
A. STARTING TROLL
B. ENTERING TROLL COMMANDS
C. GETTING SESSION INFORMATION
D. HOW TROLL HANDLES DATABASES
E. SETTING THE DATABASE ENVIRONMENT
F. A QUICK EXAMPLE OF TROLL AT WORK
III. WHIRLWIND TOUR
A. BUILT-IN FUNCTIONS
1. Output
2. Arithmetic
3. Statistics
4. Matrices
5. Calculus
6. Character Strings
7. Time Series
B. DATA CREATION AND MANIPULATION
C. MODEL CREATION
D. SIMULATION
1. Simplest Example: Linear Equations
2. Simple Non-Linear Example
3. Simple Dynamic Example: Fibonacci Sequence
4. Forward-Looking Simulation: Fibonacci Backwards
5. Rudimentary Forward-Looking Keynesian Model
E. ADVANCED ESTIMATION
F. TROLL PROGRAMMING
1. Macros
2. User-Defined Functions
G. CONCLUSION
IV. WHAT

NEXT?

Chapter Two. Understanding TROLL

I. USING THIS CHAPTER


A. PURPOSE
B. STRUCTURE
II. DISTINCTIONS TO KEEP IN MIND
A. DATA vs. MODELS
B. COMMANDS vs. FUNCTIONS
C. COMMANDS vs. MACROS
D. FUNCTIONS vs. SPECIAL OPERATORS
III. THE ELEMENTS OF TROLL
A. SYMBOLS
1. Use of Symbols
2. Symbolnames
3. Symboltypes
B. DATA
1. Data Types
2. Data Shapes and Dimensions
a. scalars
b. dimensions
c. timeseries
d. spatial arrays
i. size
ii. active dimensions
iii. trailing dimensions
iv. leading dimensions
v. special kinds of spatial arrays
e. timeseries of spatial arrays
f. constants
g. literals
i. numbers
ii. strings
iii. dates
iv. booleans
3. Lags, Leads, and Subscripts
a. lags and leads
b. subscripts
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. Built-In
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. User-Defined
F. EXPRESSIONS
G. MODELS
1. Model Files
2. Symbol Table
3. Equations
a. equation numbers
b. equation labels
c. identities that define DEFINITION-type symbols
H. CALCULATIONS
1. DO Commands
2. Expression Statements
I. TASKS
J. COMMANDS
1. High-Level Commands
2. Low-Level Commands
3. Utility Commands
K. PROGRAMS
1. Macros
a. user-written macros
b. macros included with troll
2. User-Defined 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

TERMS USED IN THIS GUIDE

B. PROGRAMMING LANGUAGE
C. ARCHIVE
D. TPL
E. SIDE EFFECTS

Chapter Three. Using And Managing Information


I. THE

ACCESS

AND SEARCH LISTS

A. ACCESS LIST: THE AVAILABLE SET OF DATABASES


1. Troll's Default ACCESS List
2. Changing the ACCESS List
a. the ACCESS command: adding to the ACCESS list
b. host files as DATA databases
c. writable access modes
d. database names: IDs and aliases
e. the DELACCESS command: letting go of databases and changing 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 multi-level 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. Big-Endian Hardware vs. Little-Endian 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 line-by-line and letter-by-letter
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

Chapter Four. Automating TROLL Tasks


I. USING INPUT FILES
A. INPUT FILES
B. PROFILE FILES
C. LOG FILES
II. A

QUICK INTRODUCTION TO MACRO PROGRAMMING

Chapter Five. Manipulating Data in Portable TROLL


I. DATA TYPES AND SHAPES
A. MIXING DATA TYPES
B. MIXING DATA SHAPES
II. DO

COMMANDS
III. THE TROLL MODELLING LANGUAGE

IV. BUILT-IN

FUNCTIONS

Chapter Six. Creating And Working With Models


I. MODEL SPECIFICATION
A. THE RAW MATERIAL: SYMBOLS AND SYMBOLTYPES
B. USING THE BASIC SYMBOLTYPES
1. EXOGENOUS, ENDOGENOUS, and COEFFICIENT Symbols
2. Declaring Symbols
3. Specifying Equations
4. Estimating and Simulating the Model
C. OTHER SYMBOLTYPES AND SPECIFICATION TECHNIQUES
1. Discretionary Input: PARAMETER Symbols
2. Changing Equations
3. Using a PARAMETER Symbol
4. Fancier Specifications: FUNCTION Symbols
5. Shock Variables: POLICY Symbols
6. Identity Equations and DEFINITION Symbols
D. SYMBOLTYPE SHORTCUTS: DEFAULTS AND SUFFIXES
II. MODEL FILES
A. THE "CURRENT" MODEL FILE AND THE MODEDIT BUFFER
B. MODEL FILE STRUCTURE
1. The Rudimentary Model File
2. Adding Useful Information
a. equation labels
i. creating labels
ii. changing symbols
iii. adding labels and changing equations
b. comments
i. model comments
ii. symbol comments
iii. equation comments
3. TROLL's Model Analysis Information
a. incidence matrix
b. block ordering
c. simulation code
4. The Complete Model File
III. USING MODELS
A. WHAT MODELS ARE FOR
B. GETTING INFORMATION
1. Specification Information
a. PRINT
b. PRTMOD
2. Analysis Information

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

Chapter Seven. Estimating Model Coefficients


I. OVERVIEW OF HOW TO USE ESTIMATION TASKS
A. BOUNDS AND MISSING DATA
1. Working With Missing Values
2. Replacing Or Eliminating Missing Values
a. NAFILL: replacing missing values with a single value
b. NAINTERP: linear interpolation
c. NAGROW: growth rate (geometric) interpolation
d. OVERLAY: replacing missing values with other series
e. NASQUEEZE: collapsing away missing values
f. combining multiple data replacement methods
II. ORDINARY

LEAST SQUARES

A. DIRECT-INPUT OPTION
B. MODEL-INPUT OPTION
III. ADVANCED SINGLE-EQUATION
A. DISTRIBUTED LAGS
B. SERIAL CORRELATION
C. TWO-STAGE LEAST SQUARES
D. NON-LINEAR LEAST SQUARES
IV. MULTIPLE

TECHNIQUES

EQUATION TECHNIQUES

Chapter Eight. Simulating A Model


I. BASIC SIMULATION
A. STATIC SIMULATION
B. DYNAMIC SIMULATION
C. MULTIPLE-EQUATION SIMULATION
D. NON-LINEAR SIMULATION
E. USING FUNCTIONS
F. FORWARD-LOOKING SIMULATION
G. CALCULATING ADD FACTORS
H. CHOOSING AN ALGORITHM
1. Newton-Raphson
2. Relaxation (First-Order) Methods
a. gauss-seidel
b. jacobi
c. successive over-relaxation (SOR)
d. fast gauss-seidel (FGS)
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
II. SIMULATION CHOICES IN TROLL
A. DATE RANGE
B. ALGORITHM
C. SYMBOL TYPES
1. Types of Symboltypes
2. Symboltype Details
D. HOW "DYNAMICALLY" TO SIMULATE
1. Dynamic Lags
2. Dynamic Leads
E. WHERE TO GET STARTING GUESSES
F. SIMULATION PARAMETERS
G. WHETHER TO SOLVE SIMULTANEOUSLY

III. SIMULATION
A. MODEL
B. DATA

REQUIREMENTS

IV. THINGS TO KEEP IN MIND


A. ADVANTAGE OF A LOGICAL NAMING STRUCTURE
B. CHECK YOUR MODEL BEFORE SIMULATING
C. DEFINITION SYMBOLS DO NOT USE DATA

Chapter Nine. Advanced Simulation


I. CONVERGENCE ISSUES
A. PRECISION vs. EFFICIENCY
B. THE CONVERGENCE TEST AND ITS PARAMETERS
1. The Convergence Test
2. Choosing Parameters
a. CONCR
b. STOP
c. GAMMA
d. DIVCR and START
e. DAMP
C. DIFFERENCES AMONG ALGORITHMS
D. ALTERING CONVERGENCE PROPERTIES OF RELAXATION METHODS
1. Renormalizing the Equations
2. Reordering the Equations
II. MODEL ANALYSIS
A. SYMBOL TABLE ANALYSIS
B. INCIDENCE MATRIX
C. BLOCK ORDERING
D. NORMALIZATION
E. SIMULATION CODE
F. LIMITS IMPOSED BY DATA
G. EIGENANALYSIS
III. FORWARD-LOOKING SIMULATION
A. THE NATURE OF FORWARD-LOOKING SIMULATION
B. PREPARING FOR FORWARD-LOOKING SIMULATION
1. Establishing Endpoints
C. USING THE STANDARD STACKED TIME METHOD
1. Temporary Shocks
2. How Many Periods to Stack
3. OLDSTACK vs. NEWSTACK
4. Permanent Shocks
D. USING THE FAIR-TAYLOR MACRO
E. IMPERFECT FORESIGHT
1. One-Time Unanticipated Shock

2. Ongoing Shock with Unanticipated Realizations


a. multiple simulations
b. multiple explicit expectations
3. Rational Expectations with Multiple Random Draws

Chapter Ten. Simulation Troubleshooting


I. DIVERGENCE
II. CYCLING
III. NON-ASSIGNABILITY
IV. SINGULAR

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

VI. SPEED vs. STABILITY


A. SPARSE MATRIX TUNING IN NEWTON-RAPHSON
VII. MISCELLANEOUS DEBUGGING TECHNIQUES
A. USING JACOBI TO DEBUG GAUSS-SEIDEL
B. SINGLE-EQUATION MODE (FORECAST)
C. ONE-STEP-AHEAD MODE (SIMPER)

Commands
Functions
Programming

User's Guide

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter One. Introduction And Overview


I. PORTABLE TROLL
A. THE PORTABLE TROLL USER'S GUIDE
B. CONVENTIONS USED IN THIS GUIDE

II. GETTING STARTED


A. STARTING TROLL
B. ENTERING TROLL COMMANDS
C. GETTING SESSION INFORMATION
D. HOW TROLL HANDLES DATABASES
E. SETTING THE DATABASE ENVIRONMENT
F. A QUICK EXAMPLE OF TROLL AT WORK

III. WHIRLWIND TOUR


A. BUILT-IN FUNCTIONS
1. Output
2. Arithmetic
3. Statistics
4. Matrices
5. Calculus
6. Character Strings
7. Time Series
B. DATA CREATION AND MANIPULATION
C. MODEL CREATION
D. SIMULATION
1. Simplest Example: Linear Equations
2. Simple Non-Linear Example
3. Simple Dynamic Example: Fibonacci Sequence
4. Forward-Looking Simulation: Fibonacci Backwards
5. Rudimentary Forward-Looking Keynesian Model
E. ADVANCED ESTIMATION
F. TROLL PROGRAMMING
1. Macros
2. User-Defined Functions
G. CONCLUSION

IV. WHAT NEXT?

Portable TROLL User's Guide

Chapter One. Introduction And Overview

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 well-suited 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 forward-looking
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 ready-to-use commands for statistical data analysis and model simulation. TROLL is designed both to interact easily
with users and to operate on pre-written command files without user attention. Both non-technical users and experienced
programmers have a place in the world of Portable TROLL.
Although TROLL now comes on a compact disc and downloads over high-speed 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 "Time-shared Reactive On-Line 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 large-scale 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
Kuh-Neese-Hollinger 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 ever-improving 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
platform-independent 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.

A. THE PORTABLE TROLL USER'S GUIDE


This Guide is intended as both a learning tool for beginning users and a "functional" reference for more advanced users.
If you are just starting to learn TROLL, you can read the chapters one by one to get a gradual introduction to Portable
TROLL's various capabilities. If you have been working with TROLL for a while but need information about how to
accomplish certain kinds of tasks (or if you are too impatient to read anything cover-to-cover), you can skip around or
go directly to the relevant sections.
Unlike the Portable TROLL Reference Manual and the Portable TROLL Programming Language manual, this volume
is organized in terms of what you want to do rather than how you do it. Thus, for example, if you want to find out how
to import data into Portable TROLL, you can go to the chapter on "Using and Managing Information" in this volume.
On the other hand, if you want more detailed information on how to use a particular command such as "SEARCH," you
can go to the relevant section in the Reference Manual.

B. CONVENTIONS USED IN THIS GUIDE

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).

II. GETTING STARTED


A. STARTING TROLL
The specifics of how you begin a TROLL session will depend on your host environment and, in some cases, on the
details of your TROLL installation. If the procedures described here do not work for you, contact your local TROLL
administrator or systems consultant.
Most likely, you work in either a UNIX environment or a Windows environment. Under most UNIX installations, you
can invoke TROLL by typing "troll" (normally lower case) at a command prompt. In some cases, it will first be
necessary to find the directory in which TROLL is installed and create a link to the TROLL executable.
In a Windows environment, there are several ways to run TROLL. In a command prompt session (or MS-DOS session),
you can type "troll" (upper or lower case) at the command prompt. (This assumes you have the TROLL directory on
your "path" list, which will be the case for a standard installation.) Similarly, you can use the Windows "Run" command
from the Start menu (or the "File" menu in Windows 3.1): choose "Run," type "troll" in the "Open:" box, and choose
"OK". These methods invoke the "console" version of TROLL, which is the same as the UNIX version in most respects.
Alternatively, if you are working in a Windows environment and you have the GUI version of TROLL, you can choose
"TROLL for Windows" from the "Programs" menu or double-click on the Desktop shortcut for TROLL (if one exists).
If you invoke TROLL this way, you will see a Startup dialog box. Unless you want to change the TROLL session
parameters, you can simply choose "OK" (or press "Enter"). This will invoke the GUI (Graphical User Interface)
version of TROLL, which includes a separate "Input" window for entering TROLL commands. Since not all users have
the GUI available, the rest of this User's Guide is written with reference to the console version. For the most part,
everything in here applies to the GUI version as well, except that you type commands into the "Input" window. The
appearance of the "Session" window will be essentially the same as that of the command window in the console version.
When you invoke TROLL, it will begin by prompting you for a TROLL Command. The beginning of the session should
look something like this:
TROLL Release 1.033
Copyright (C) Intex Solutions, Inc. 1993-1997
Copyright (C) Massachusetts Institute of Technology 1978-1987
TROLL Command:

B. ENTERING TROLL COMMANDS

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.

C. GETTING SESSION INFORMATION


If you're just learning to use TROLL, one of the first things you may want to learn is how to get information about your
TROLL session. TROLL gives the user such information in response to "look" commands, which normally begin with
"LK". For example, try typing "lkaccess;" in response to the "TROLL Command:" prompt. The result should look
something like this:
TROLL Command: lkaccess;
Accessed Databases:
Alias
----SAVE
.

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 (computer-readable 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 convergence-related options (see
Reference Manual entry); LKSTATUS, which shows information about the model and time-series 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.

D. HOW TROLL HANDLES DATABASES


TROLL's ability to access multiple databases at once raises some important problems. For example, what happens when
a variable with the same name is in two different databases? When you refer to one of those variables by name, how
does TROLL know which one you are talking about? Also, if TROLL is accessing many large databases at once, how
can it manage the potentially cumbersome computer resources efficiently?
The answer to these questions is in something called a "SEARCH list," an ordered list of databases used in a TROLL

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 read-SEARCHable
but not write-SEARCHable 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 write-SEARCHable.

E. SETTING THE DATABASE ENVIRONMENT


You can control TROLL's database ACCESS and SEARCH lists by using the commands ACCESS, SEARCH, DELACCESS, and
DELSEARCH. The ACCESS command makes a database available to TROLL, so that the database will appear on the "ACCESS
list" reported by LKACCESS. The SEARCH command adds a database to a the SEARCH list and allows the user to specify its
position on the list. ACCESS and SEARCH are perhaps the most important commands for managing data in TROLL.
DELACCESS and DELSEARCH are used to remove databases from the ACCESS and SEARCH lists.
The following is a simple syntax for the ACCESS command:
ACCESS alias TYPE dbtype ID idname [MODE modeval];

(The full syntax is described in the Reference Manual.)


The "alias" is the name to be used for the database within the TROLL session. The "idname" is a name by which
TROLL can identify the database initially in order to gain access. Often a host system filename is used as the "idname."
Suppose you want to use some information in a database that resides in a file called "usanipa.frm". (The ".frm"
extension indicates that this refers to a "FORMDATA" database -- a text file in a format that TROLL recognizes.) If you
only want to use the information, not revise it or supplement it, then the safer option is to access it in read-only mode.
This happens to be the default, so you can omit the "[MODE modeval]". The following example assumes the file is located
in the main directory of a PC host system. (The "idname" would be slightly different on a UNIX system.) This
command gives TROLL access to usanipa.frm, using the alias "nipa":
TROLL Command: access nipa type formdata id c:\usanipa.frm;

LKACCESS can verify that the database is now available to TROLL:


TROLL Command: lkaccess;
Accessed Databases:
Alias
----SAVE
.
TROLLSYS
NIPA

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;

...and verify with LKSEARCH:


TROLL Command: lksearch;
Current SEARCH list:
Name
---SAVE
.
TROLLSYS
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 "non-BASIC" databases from both the SEARCH list and the ACCESS list:

TROLL Command: delaccess all ;


TROLL Command: lkaccess ;
Accessed Databases:
Alias
----SAVE
.
TROLLSYS

DB Type
------MEMDB
DISK
DISK

R/W?
---R/W
R/W
R

Filetype
-------DATA
ALL
ALL

TROLL Command: lksearch ;


Current SEARCH list:
Name
---SAVE

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.

F. A QUICK EXAMPLE OF TROLL AT WORK


Before considering more of the preliminaries, and before examining the special capabilities of TROLL, let's look at a
very simple example of TROLL's basic functionality: good, old-fashioned linear regression. We'll use the
USANIPA.FRM file from the previous section. In this example, we assume again that the file resides in the main
directory of a PC-type host system, and we also assume that its contents include annual data for U.S. gross domestic
product ("GDP") and personal consumption expenditures ("CONS") from 1969 through 1995. First, set up the ACCESS and
SEARCH environment as above. Then type, "ols cons gdp, 1969a to 1995a;" at the command prompt. (The "a" after
1969 and 1995 stands for "annual," which identifies 1969 and 1995 as years rather than ordinary numbers.)
TROLL Command: access nipa type formdata id c:\usanipa.frm;
TROLL Command: search nipa;
TROLL Command: ols cons gdp, 1969a to 1995a;
ORDINARY LEAST SQUARES
LHS VARIABLE:

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 Left-hand-side variable as "CONS." It then presents various regression statistics,
and finally it shows the coefficient estimates, along with their standard errors, T-statistics, 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."

OLS Command: prtdiag rstudent;


RSTUDENT
1969A
1970A
1971A
1972A
1973A
1974A
1975A
1976A
1977A
1978A
1979A
1980A
1981A

-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.

TROLL Command: prtdiag rstudent;


ERROR 101
Not a command:
PRTDIAG
TROLL Command:

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 "high-level"
access methods, not through regression-specific 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

III. WHIRLWIND TOUR


Having examined some of TROLL's basic functionality, let's take a step back and look more broadly at TROLL's capabilities. If
you're a new user, many of the TROLL sessions shown here may appear cryptic. Don't worry about understanding the details of
the syntax and methods. The purpose of this section is just to give you an idea of what is possible, so you can get an idea of
how you might use TROLL and begin to get a feeling for the way TROLL looks and works.

A. BUILT-IN FUNCTIONS
TROLL has approximately 200 built-in 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:

TROLL Command: do prt.(5);


5:
Numeric scalar:

TROLL Command: do prtdata(5*2);


5*2:
Numeric scalar:

10

TROLL Command: do prt.(5*2,2*3);


5*2:
Numeric scalar:

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 1-by-1 matrix:
TROLL Command: do prtmat( 5 ) ;
Row
1

Column 1
5

(Note that the spaces around the 5 above are optional.)

2. Arithmetic
Anything a typical hand-held calculator can do, TROLL can do better (or at least equally well):
TROLL Command: do prt.(sqrt(1000));
SQRT(1000):
Numeric scalar:

31.622777

TROLL Command: do prt.(arcsin(1));


ARCSIN(1):
Numeric scalar:

1.570796

TROLL Command: do prt.(absv(2*(3-5)));


ABSV(2*(3-5)):
Numeric scalar:

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 scale-sensitive, 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

Time dimension -->


:
7.97755
:
8.10655
:
8.18442
:
8.27515
:
8.39556
:
8.52407
:
8.57647

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

TROLL Command: do prt.(range(gdp));


RANGE(GDP):
Numeric array -1 space dimension: 2

[1]:

Space dimension number 1 -->


2914.780935
5601.5644

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]:

Space dimension number 2 -->


27
4135.815598
850.353715

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

TROLL Command: do prt.(statvec);


STATVEC:

STATVEC = TRANSP(STATS(GDP))
Numeric array -1 space dimension: 5

[1]:
[5]:

Space dimension number 1 -->


27
4135.815598
850.353715

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 one-dimensional array. The "two-dimensional" array is now a
"one-dimensional" 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]:

Space dimension number 2 -->


27
4135.815598
850.353715

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:

The first dimension of statvec is size 5: five rows.


TROLL Command: do prt.(dimsize(statvec,2));
DIMSIZE(STATVEC,2):
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:

In fact, it has millions of dimensions:


TROLL Command: do prt.(dimsize(statvec,1000000));
DIMSIZE(STATVEC,1000000):
Numeric scalar:
1

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" (non-trailing) dimensions a matrix has. Use the
NDIMS function:
TROLL Command: do prt.(ndims(statvec));
NDIMS(STATVEC):
Numeric scalar:

Or you may just want to know how many elements it has:


TROLL Command: do prt.(nvals(statvec));
NVALS(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 two-dimensional 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

And if you don't happen to like row 4, get rid of it:


TROLL Command: do prtmat(delrow(sillymat,4));
Row
1
2
3
4

Column 1

Column 2

27
4135.815598
2914.780935
850.353715

850.353715
5601.5644
2914.780935
27

...or replace it:


TROLL Command: do prtmat(setrep(sillymat,0,4,col(sillymat)));
Row
1
2
3
4
5

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 partial derivatives:


TROLL Command: do deriv(cos(y)*log(x*y),y);
DERIV(COS(Y)*LOG(X*Y),Y) = -(SIN(Y))*LOG(X*Y)+COS(Y)*1/Y

...and second derivatives:


TROLL Command: do deriv(log(x+y),x,x);
DERIV(LOG(X+Y),X,X) = -1/(X+Y)/(X+Y)

...and cross-derivatives:
TROLL Command: do deriv(5*x**2*y,x,y);
DERIV(5*X**2*Y,X,Y) = 5*2*X

...and (in case anyone's interested) tenth derivatives:


TROLL Command: do deriv(x**12,x,x,x,x,x,x,x,x,x,x);
DERIV(X**12,X,X,X,X,X,X,X,X,X,X) = 12*11*10*9*8*7*6*5*4*3*X**2

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

Time dimension -->


:
-0.000343
-0.000343
:
-0.000302
-0.000303
:
-0.000279
-0.000266
:
-0.000255
-0.00026
:
-0.000226
-0.000219
:
-0.000199
-0.000196
:
-0.000188
-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

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"

Now, evaluate that derivative:


TROLL Command: do prt.(evalstr(symderiv));
EVALSTR(SYMDERIV):
Numeric scalar timeseries -Time dimension: Periodicity 1,
Time dimension -->
1969A :
-0.000343
1973A :
-0.000302
1977A :
-0.000279
1981A :
-0.000255
1985A :
-0.000226
1989A :
-0.000199
1993A :
-0.000188

-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"

Then, if you want, you can evaluate the string again.


You can form an array of strings using COMBINE (which works for numerical data as well):
TROLL Command: do couple=combine("HUSBAND", "AND", "WIFE");
TROLL Command: do prt.(couple);
COUPLE:
COUPLE = COMBINE("HUSBAND","AND","WIFE")
String array -1 space dimension: 3

[1]:

Space dimension number 1 -->


"HUSBAND" "AND" "WIFE"

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]:

Space dimension number 1 -->


"HUSBAND" "AND" "WIFE"

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! "

Naturally, you can find the length of a string...


TROLL Command: do prt.( length( "My name" ) );
LENGTH("My name"):
Numeric scalar:

...and extract substrings...


TROLL Command: do prt.( substr( "Processing this forward", 17 ) );
SUBSTR("Processing this forward",17):
String scalar: "forward"
TROLL Command: do prt.( substr( "Processing this forward", 12, 4 ) );
SUBSTR("Processing this forward",12,4):
String scalar: "this"

...starting from the end, if you prefer:


TROLL Command: do prt.( substr( "Processing this backward", -8, 4 ) );
SUBSTR("Processing this backward",-8,4):
String scalar: "back"

7. Time Series
Finally, to close the "Built-in 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

If you don't like those dates, you can change them:


TROLL Command: do conpre80=subrange(cons,,1979a);
TROLL Command: do conpos73=subrange(cons,1974a,NA);
TROLL Command: do prt.(startdate(conpos73),enddate(conpre80));
STARTDATE(CONPOS73):
Date scalar: 1974A
ENDDATE(CONPRE80):
Date scalar: 1979A

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:

Time dimension -->


NA
2914.780935
3316.134145
3584.683297
3925.140736
4427.403328

1965A to 1987A (23 observations)

NA
2915.694014
3295.33595
3757.358183
3840.987421
4560.653581

TROLL Command: do prt.(nob(gdp65t87));

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

TROLL Command: do prt.(natest(gdp65t87));


NATEST(GDP65T87):
Boolean scalar:

TRUE

TROLL Command: do gdpshort=natrim(gdp65t87);


TROLL Command: do prt.(nob(gdpshort));
NOB(GDPSHORT):
Numeric scalar:

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

TROLL can also calculate overlapping ranges of non-missing data:


TROLL Command: do bounds(gdp65t87,conpos73);
1974A to 1987A

...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

Time dimension -->


:
414.40095
:
440.77844
:
447.24806
:
467.16778
:
492.32372
:
495.17708
:
505.23031
:
529.21150
:
547.71241
:
567.60691
:
586.30149

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

B. DATA CREATION AND MANIPULATION


Another thing TROLL functions can do is to create and reorganize data. Consider, for example, the SEQ function, which
produces a sequence of numbers:
TROLL Command: do prt.(seq(10));
SEQ(10):
Numeric array -1 space dimension: 10

[1]:

Space dimension number 1 -->


1
2

[5]:
[9]:

5
9

6
10

68
140
212

86
158

TROLL Command: do prt.(seq(32,212,10*9/5));


SEQ(32,212,10*9/5):
Numeric array -1 space dimension: 11

[1]:
[5]:
[9]:

Space dimension number 1 -->


32
50
104
122
176
194

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

TROLL Command: do prt.(reshape(seq(10),1980a));


RESHAPE(SEQ(10),1980A):
Numeric scalar timeseries -Time dimension: Periodicity 1,

1980A
1984A
1988A

:
:
:

Time dimension -->


1
5
9

1980A to 1989A

2
6
10

(10 observations)

3
7

4
8

Or if you prefer a nonlinear pattern...


TROLL Command: do prt.(10*reshape(sqrt(3+log(absv(sin(seq(-9.56,1,.628
Continue eq: ))))),1980a)) ;
10*RESHAPE(SQRT(3+LOG(ABSV(SIN(SEQ(-9.56,1,0.628))))),1980A):
Numeric scalar timeseries -Time dimension: Periodicity 1, 1980A to 1996A (17 observations)

1980A:
1984A:
1988A:
1992A:
1996A:

Time dimension -->


9.980549
16.224714
17.275306
17.010533
14.975145

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]:

Space dimension number 1 -->


1
2
8
13

3
0

5
0

TROLL Command: do whitelie=c.(fibb,0,0,0);


TROLL Command: do prt.(whitelie);
WHITELIE:
WHITELIE = C.(FIBB,0,0,0)
Numeric array -1 space dimension: 9

[1]:
[5]:
[9]:

Space dimension number 1 -->


1
2
8
13
0

It's also easy to create a timeseries using COMBINE with RESHAPE or with CRSERIES:

TROLL Command: do prt.( reshape( c.(1,3,7,22,100), 2000m1 ) );


RESHAPE(C.(1,3,7,22,100),2000M01):
Numeric scalar timeseries -Time dimension: Periodicity 12,

2000M01:
2000M05:

Time dimension -->


1
100

2000M01 to 2000M05 (5 observations)

22

TROLL Command: do prt.( crseries( 2000m1, c.(1,3,7,22,100) ) );


CRSERIES(2000M01,C.(1,3,7,22,100)):
Numeric scalar timeseries -Time dimension: Periodicity 12,

2000M01:
2000M05:

Time dimension -->


1
100

2000M01 to 2000M05 (5 observations)

22

You can generate "random" numbers...


TROLL Command: do prt.(randnorm(,,10)-randunif(,,10));
RANDNORM(NA,NA,10)-RANDUNIF(NA,NA,10):
Numeric array -1 space dimension: 10

[1]:
[5]:
[9]:

Space dimension number 1 -->


0.813793
-1.101452
-1.422684
0.033928
-0.459743
-0.027697

-0.541802
-0.899749

-0.215298
-0.550727

Create a zero matrix...or a non-zero matrix...


TROLL Command: do prtmat(crmat(2,4));
Row
1
2

Column 1

Column 2

Column 3

Column 4

0
0

0
0

0
0

0
0

TROLL Command: do prtmat(crmat(3,3,5));


Row
1
2
3

Column 1

Column 2

Column 3

5
5
5

5
5
5

5
5
5

...and add columns and rows to a matrix:


TROLL Command: do prtmat(addrow(addcol(crmat(3,3,5),2,4.4),3));
Row
1
2
3
4

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 element-by-element 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 model-editing 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;

And some COEFFICIENTs:


MODEDIT Command: addsym coefficient a tradj;

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);

... and now the interest rate ...


MODEDIT Command: addeq bottom IRATE: r=a*capsh*(k**(capsh-1))+prem;

Now we add a few identity equations. (Note that multiple equations can be added in a single ADDEQ statement.)
MODEDIT Command: addeq bottom

(TROLL prompts, rather ambiguously here, for more information.)


'+', '-', ',', ';' or next item: TAXREV: t = trate*y,
[Lbl:] Equation: GDPIDEN:
k-k(-1) + (pi+n)*k(-1) = y-c-g ,
[Lbl:] Equation: BUDGIDEN:
b-b(-1) = (r-(pi+n))*b(-1) +g-t;

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: trate-trate(-1) =
Continue eq: tradj * ( ( (b-bt) - (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 forward-looking expectations:
MODEDIT Command: addeq bottom WHUM: h(+1)-h =
Continue eq: (r+lambda-pi)*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**(CAPSH-1)+PREM
T = TRATE*Y
K-K(-1)+(PI+N)*K(-1) = Y-C-G
B-B(-1) = (R-(PI+N))*B(-1)+G-T
TRATE-TRATE(-1) = TRADJ*(B-BT-(B(-1)-BT(-1)))/Y
C = (THETA+LAMBDA)*(K+B+H)
H(+1)-H = (R+LAMBDA-PI)*H-(Y-R*K-T)

We won't try to solve it now, just save it for later:


MODEDIT Command: filemod;

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 nondata-writable 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, two-equation model.
TROLL Command: usemod ;
New model: (nameless)
TROLL Command: addsym endogenous x y ;

(TROLL automatically enters the model-editing task, since the ADDSYM command unambiguously belongs to
MODEDIT.)
MODEDIT Command: addeq top x+2*y = 10, x-y = 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]

Voil. Y=3 and X=4.

2. Simple Non-Linear Example


Now let's try a nonlinear equation. (The "'N" notation below is a shorthand way to declare an ENDOGENOUS
variable "on the fly". Here we let TROLL process three separate commands from a single input line. The PRINT
command tells TROLL to display the contents of the model.)
SIMULATE Command: usemod ; addeq top sin(x'n) = cos(x) ; print ;
New model: (nameless)
Symbols:
ENDOGENOUS :
X
FUNCTION :
COS SIN
Equations:
1:

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.22308e-001]
[+1.88339e-003]
[-7.05851e-009]

3. Simple Dynamic Example: Fibonacci Sequence


These two examples have shown static simulations, but dynamic simulations are usually more interesting. In the
following example, TROLL generates a Fibonacci sequence:
SIMULATE Command: usemod ; addeq top x'n = x(-1) + x(-2); print ;
New model: (nameless)
Symbols:
ENDOGENOUS :
X

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 ;

4. Forward-Looking Simulation: Fibonacci Backwards


TROLL's specialty is simulation of forward-looking models. In such models, the present state of the universe
depends on the future, so that the usual direction of cause-and-effect is reversed. (Typically, the mechanism for
this reversed causation is foresight by rational agents who act in anticipation of the future.) One simple
illustration of a forward-looking simulation is the Fibonacci sequence in reverse, as in the following model:
TROLL Command: usemod ; addeq top x'n = x(+1) + x(+2); print ;
New model: (nameless)
Symbols:
ENDOGENOUS :
X
Equations:
1:

X = X(+1)+X(+2)

The only difference between this and the previous example is that the minus-signs in the subscripts have become
plus-signs. 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 stacked-time 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 forward-looking 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 stacked-time incidence matrix and code.
Simulations can start from NA to NA.

Now we proceed as before:


SIMULATE Command: list solutions all;
SIMULATE Command: simstart 3a; dotil 10a;

Date:
3A

Solution:

What:
X [3A]
[4A]
[5A]
[6A]
[7A]
[8A]
[9A]
[10A]

Value:
55
34
21
13
8
5
3
2

There it is: the Fibonacci sequence in reverse.

5. Rudimentary Forward-Looking Keynesian Model


For a slightly more practical example of forward-looking simulation, let's look at a variation on the traditional
Keynesian "investment multiplier" model. To keep the model as simple as possible, we will ignore the
government, foreign trade, money, prices, and just about anything else that could complicate the model. The
only complication will be forward-looking behavior by consumers. We start by clearing the model workspace:
TROLL Command: usemod;
New model: (nameless)
TROLL Command: modedit;

To begin with, there is one EXOGENOUS variable, investment:


MODEDIT Command: addsym exogenous i;

...and two ENDOGENOUS variables, income and consumption:


MODEDIT Command: addsym endogenous y c;

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);

That completes the model:


MODEDIT Command: print;
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)

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 pseudo-random data for (exogenous) investment. (The "seed" arguments to
ensure that the data will be replicable.)

RANDNORM

MODEDIT Command: do i=.2*y*(1+randnorm(1,2));


MODEDIT Command: do prt.(i);
I:
I = 0.2*Y*(1+RANDNORM(1,2))
Numeric scalar timeseries -Time dimension: Periodicity 1,

1A
5A
9A
13A
17A
21A

Time dimension -->


:
0.322728
:
0.481454
:
0.718245
:
1.071496
:
1.598484
:
2.384658

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

First we'll simulate by stacking the entire simulation period:


MODEDIT Command: simulate stack 20;
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Constructing stacked-time incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
SIMULATE Command: list solutions y;
SIMULATE Command: simstart 1a; dotil 20a;
Date:
What:
Value:
1A
Solution: Y [1A]
1.761881
[2A]
1.947181
[3A]
2.15197
[4A]
2.378299
[5A]
2.628438
[6A]
2.904898
[7A]
3.210463
[8A]
3.548234
[9A]
3.921682
[10A]
4.334754
[11A]
4.792048
[12A]
5.299193
[13A]
5.863624
[14A]
6.496306
[15A]
7.215526
[16A]
8.055384
[17A]
9.084814
[18A]
10.450307
[19A]
12.471954
[20A]
15.859444

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 multiplier-accelerator 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 two-equation 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=gdp-invest-cons;

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)

Add symbols for the variables:


TROLL Command: addsym endogenous cons invest;
MODEDIT Command: addsym exogenous exdemand;

We also need symbols for the coefficients to estimate:


MODEDIT Command: addsym coefficient a0 a1 b0 b1;

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):

MODEDIT Command: bounds 1969a to 1995a;


MODEDIT Command: conopt stop 100;

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

ORDINARY LEAST SQUARES


2 :

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 simultaneous-equation 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 "full-information maximum likelihood":
OLSMOD Command: fiml;
...ANALYSING MODEL
...GENERATING CODE

To save space, we will suppress detailed reporting of the optimization:


FIML Command: outlvl int 1;

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

FIML Command: estimate;


FIML estimation Begins
*** Standard algorithm ***

MODEL: CURRENT NOB: 27


RANGE: 1969A to 1995A

NOVAR: 4

NEQ: 2

Optimization algorithm: Davidon-Fletcher-Powell


RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
Beginning Linear-Jacobian Iterations
Convergence OBTAINED in 35 iterations, 74 FCN evaluations, FCN=
18.684354
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
Total Iters: 35 Fevals: 74 Final FCN:
18.684354 LOG-LIKE:
-328.861465

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

...and some statistics:


Single Equation Statistics
RSQ
Eqn 1
Eqn 2

CRSQ

0.945342
0.656757

SSR

0.943155
0.643027

569604.260898
125154.572678

SER
150.944263
70.754384

Another GREMLIN task is "three-stage 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

Optimization algorithm: Davidon-Fletcher-Powell


RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
Convergence OBTAINED in 6 iterations, 11 FCN evaluations, FCN=-6.5293531e-012
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 6 Fevals: 11 Final FCN: -6.5293531e-012

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

Single Equation Statistics


RSQ
Eqn 1
Eqn 2

0.945342
0.656757

CRSQ
0.943155
0.643027

3 Stage estimation begins...


MODEL: CURRENT NOB: 27 NOVAR: 4
RANGE: 1969A to 1995A
Optimization algorithm:

SSR
569604.260883
125154.572648

NEQ: 2

Davidon-Fletcher-Powell

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.5032956e-016
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 4 Fevals: 8 Final FCN: -3.5032956e-016

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

Single Equation Statistics


RSQ
Eqn 1
Eqn 2

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: Davidon-Fletcher-Powell
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: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 5 Fevals: 10 Final FCN:
671494.936704 LOG-LIKE:
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

Single Equation Statistics


RSQ
Eqn 1
Eqn 2

0.947023
0.672506

CRSQ
0.944904
0.659406

SSR
552082.842861
119412.093844

SER
148.604555
69.11211

3 Stage estimation begins...


Seemingly unrelated equations (ZELLNER) case
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX:1000
Convergence OBTAINED in 7 iterations, 14 FCN evaluations, FCN=
53.103855
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 7 Fevals: 14 Final FCN:
53.103855 LOG-LIKE:

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

Single Equation Statistics


RSQ
Eqn 1
Eqn 2

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 re-use.
TROLL programs come in two varieties, "macros" and "user-defined 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. User-defined 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;

Then you can do the following:


TROLL Command: &prtdata cons;
NIPA_CONS:
CONS = CONS
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

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));".

TROLL Command: &prtdata(*N*);


NIPA_CONS:
CONS = CONS
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

NIPA_INVEST:
INVEST = INVEST
Numeric scalar timeseries -Time dimension: Periodicity 1,

1969A
1973A
1977A
1981A
1985A
1989A
1993A

Time dimension -->


:
509.28453
:
643.19044
:
651.91469
:
627.76277
:
750.27456
:
783.10274
:
774.12084

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:

Macro to list the variables in a "formdata" file

// 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]:

Space dimension number 1 -->


"CONS"
"GDP"
"INVEST"

Let's look now at the statements in the macro file:


get formdb;

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. User-Defined Functions
User-defined functions work exactly like built-in functions, except that a user-defined function needs the suffix
"'F" so that TROLL will recognize it has a function. Consider a user-defined function called "distance" that
calculates the distance from the origin of a point in two-dimensional 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));
}

As with the macro, you can ignore the "addfun

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 5-squared plus 3-squared, 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.

IV. WHAT NEXT?


If you have been reading this Guide from the beginning, you may want to pause here and consider what to read next. For
example, if you feel comfortable with the syntax and conventions of TROLL already, you may prefer to skip or skim the next
chapter and use it only as a backup reference. If there is a particular topic that you want to learn more about, you could go
directly to the appropriate chapter or section.
If you feel quite comfortable with TROLL now and you're the kind of person who likes to just do things instead of reading
about them, you could just start using TROLL. The Reference Manual and the Programming Language manual should contain
most of the specific information you need. If you get stuck on a particular topic, you could come back and read about it in here.
If you have specific questions, you may find them in the FAQ list, or you can ask other TROLL users or your TROLL trainer or
consultant, if you have one. If necessary, you can get the information straight from the source: the same people who develop
and maintain TROLL are available for user support through various channels.
On the other hand, if you feel like you're on shaky ground and would like to develop a firm foundation before using TROLL on
your own, then by all means read on. Although the remaining chapters can be used separately, they are also intended to provide
a logical sequence wherein each chapter builds on the knowledge from the previous chapters.
So much for the preliminaries. Let the games begin!

Commands
Functions
Programming

User's Guide

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter Two. Understanding TROLL


I. USING THIS CHAPTER
A. PURPOSE
B. STRUCTURE

II. DISTINCTIONS TO KEEP IN MIND


A. DATA vs. MODELS
B. COMMANDS vs. FUNCTIONS
C. COMMANDS vs. MACROS
D. FUNCTIONS vs. SPECIAL OPERATORS

III. THE ELEMENTS OF TROLL


A. SYMBOLS
1. Use of Symbols
2. Symbolnames
3. Symboltypes
B. DATA
1. Data Types
2. Data Shapes and Dimensions
a. scalars
b. dimensions
c. timeseries
d. spatial arrays
i. size
ii. active dimensions
iii. trailing dimensions
iv. leading dimensions
v. special kinds of spatial arrays
e. timeseries of spatial arrays
f. constants
g. literals
i. numbers
ii. strings
iii. dates
iv. booleans

3. Lags, Leads, and Subscripts


a. lags and leads
b. subscripts

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. Built-In
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. User-Defined
F. EXPRESSIONS
G. MODELS
1. Model Files
2. Symbol Table
3. Equations
a. equation numbers
b. equation labels
c. identities that define DEFINITION-type symbols

H. CALCULATIONS
1. DO Commands
2. Expression Statements
I. TASKS
J. COMMANDS
1. High-Level Commands
2. Low-Level Commands
3. Utility Commands
K. PROGRAMS
1. Macros
a. user-written macros
b. macros included with troll

2. User-Defined 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 TERMS USED IN THIS GUIDE


A. MODELLING LANGUAGE
B. PROGRAMMING LANGUAGE
C. ARCHIVE
D. TPL
E. SIDE EFFECTS

Portable TROLL User's Guide

Chapter Two. Understanding TROLL


I. USING THIS CHAPTER
A. PURPOSE
This chapter describes the general structure, terminology, and conventions of Portable TROLL. Rather than
concentrating on how to accomplish specific tasks, this chapter tries to provide a foundation for the student of TROLL
by describing the framework in which he or she will be working. If you prefer to launch directly into using TROLL, this
chapter may be useful as a reference while studying the rest of the book. If you prefer to learn TROLL step by step, this
chapter will teach you to "talk the talk," and the rest of the book will show you how to "walk the walk." If you are an

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.

II. DISTINCTIONS TO KEEP IN MIND


A. DATA vs. MODELS
The most fundamental distinction in TROLL (and perhaps the most fundamental distinction in science) is between data
and models. In the abstract, data represent the empirical component of knowledge, the results of direct observation,
whereas models represent the rational component, the attempt to understand observations in a useful way. In TROLL,
the distinction can be made differently: data are values (usually numbers), whereas models are sets of equations.
Granted, that definition is not a complete one. If the complete definition were so simple, then this section might be
unnecessary. Difficulty arises from what TROLL data and TROLL models have in common. In particular, both data and
models contain "variables." Variables provide the critical link between data and models. At any point in an actual
TROLL session, a given variable is normally either a "data variable" (usually representing a number or set of numbers)
or a "model variable" (representing an abstract quantity in an equation or set of equations), not both.
The processes of estimation and simulation use data in connection with models. TROLL finds "data variables" to match
up with the appropriate "model variables." In other words, TROLL uses a matching of variable names to "plug data into
the model" or "plug numbers into the equations." This liaison is temporary. The data variables retain their identities
apart from their use in estimation or simulation, and when the process is finished, the model and the data go their
separate ways.
Estimation and simulation may also produce data, and in some cases the newly produced data variables will replace
existing data variables. Although a model was used in the estimation or simulation process, the newly produced data are
no longer associated with the model. Like the goddess Athena, the new data are born fully armored and have no need of
their parents.
The situation is further complicated when we encounter the concept of an "abstract data object". Despite its title, an
"abstract data object" is not a piece of "data." Rather, the phrase "data object" in this context is much like the term
"variable." The phrase "data object" is used to emphasize the possibility of multidimensionality, since many people
think of "variables" as being inherently scalar. An "abstract data object" is a "model variable," and a "concrete data
object" is a "data variable."

B. COMMANDS vs. FUNCTIONS


There are several ways to tell TROLL what to do. The simplest way is with commands. A command simply says, "Do
this, and then await further instructions." You enter a command directly at a TROLL prompt; for example:
TROLL Command: lkaccess;

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

valid function, the following statement produces an error message:


TROLL Command: sqrt(16);
ERROR 101
Not a command:
SQRT

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.

C. COMMANDS vs. MACROS


A beginning user might do best simply to think of a macro as a command that begins with an ampersand, such as
&PRTDATA, which is used in the following sequence:
TROLL Command: do x=3;
TROLL Command: &prtdata x;
SAVE_X:
Numeric scalar: 3

Except for the ampersand, a macro is used exactly like a command.


The substantive difference is that commands are integral parts of TROLL, whereas macros are extensions of TROLL
that are implemented as TROLL programs. A command is "hard-wired;" it always works according to the same rules,
which cannot be changed by the user. Since macros are TROLL programs, the rules for how a macro works can, in
theory, be changed by the user: the user can change the program code and recompile the macro. It is also relatively easy
for users to write their own macros and use them with TROLL. Writing actual "commands" for TROLL is not possible
for ordinary users.

D. FUNCTIONS vs. SPECIAL OPERATORS


One source of potential confusion among TROLL users is the availability of special operators that look very much like
functions. In particular, you should be aware that DEL, SUM, and PRODUCT are operators and not functions.

III. THE ELEMENTS OF TROLL


A. SYMBOLS
Symbols are the most fundamental element in TROLL. Unfortunately, the use of the term "symbol" can be somewhat
confusing at times. Sometimes TROLL uses the word "symbolname". From your point of view as a user, a
"symbolname" is essentially the same thing as a "symbol". The term "symbolname" is normally used only in contexts
that refer to a TROLL model, whereas the term "symbol" may be more general.
The TROLL Reference Manual defines "symbol" as "a name used in an equation or expression to represent a data object
or function." A symbol normally consists of a sequence of letters, digits, and/or other characters, such as "US_M2".
Broadly, symbols may be divided into "function symbols" and "data symbols", with the latter sometimes merely called
"symbols". A "function symbol" represents a function. A "data symbol" represents a data object, either abstract or
concrete.

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
lower-case and upper-case letters in symbolnames: all are converted to upper-case. 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 built-in TROLL function or a user-written function.
TROLL will automatically recognize the names of built-in 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 "pseudo-type" 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.

2. Data Shapes and Dimensions


"Data shape" refers to the structure (dimensionality) of a composite or simple data object. For example, the two
time series "Annual US GDP from 1950 through 1990" (numbers) and "Names of Nobel prize winners in
Economics from 1950 through 1990" (strings) have the same shape. The time series "Annual US GDP from
1950 through 1989" has a different shape, as does the number 5. Data shapes are described in terms of
"dimensions".
a. scalars
The simplest data shape is called scalar. A scalar consists of a single data element, such as 235 or "John
Maynard Keynes". All scalars have the same "shape."
b. dimensions
TROLL recognizes two fundamentally different kinds of dimensions:
the time dimension
The time dimension of an array is used for timeseries in which observations are recorded at
regular intervals or periods. A time dimension has an associated periodicity that identifies the
intervals at which observations are recorded, a startdate that identifies the date of the first
observation, and a number-of-observations (NOB) that identifies the number of time periods.
Individual observations in a timeseries can be identified by date.
space dimensions
Space dimensions are used for vectors, matrices and higher-dimensional arrays. Each space
dimension has a size, which identifies the number of elements along that dimension. Individual
elements along the dimension are identified by an integer subscript or "index".
c. timeseries
A timeseries is a data object which has a time dimension. In other words, a timeseries is a data object
which includes observations at regular intervals.
d. spatial arrays
Let's define a spatial array as a data object that has space dimensions. (By this definition, it will turn out
that every TROLL data object is a spatial array, as you will see below.) TROLL allows a very rich set of

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 two-dimensional 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 "E-format"
number. An E-format 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 12345d-6 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 double-quotes ("). The string may be empty
("") or may contain any sequence of printable characters other than double-quote, ampersand (&)
or backslash (\); a double-quote 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:
\"

double-quote
\+

ampersand
\\

backslash
\n

newline (line-feed)
\t

horizontal tab
\b

backspace
\f

form-feed
\r

carriage-return
\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 pre-defined periodicities, as well as various types of
user-definable 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.
business-daily
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 user-defined periodicity. The format is ttttT, where tttt is the number of ticks
(or periods).
user-defined by dividing periods
starts with one of the above periodicities and adds PppFff, where pp is the number of
sub-periods per period, and ff is the sequence number of the current subperiod within the
period. For example, 1990M03P02F01 belongs to a user-defined "semi-monthly"
periodicity and refers to the first half of March, 1990
user-defined by multiplying periods
starts with one of the above periodicities (not the last) and adds Xxx, where xx is the
number of periods per super-period. For example 1990W10X02 and 1990W11X02 both
belong to a user-defined "bi-weekly" periodicity, and both refer to the fifth two-week
period in 1990, (since, in integer arithmetic, 10/2 = 11/2 = 5).
iv. booleans
TRUE

means true, and FALSE means false.

3. Lags, Leads, and Subscripts


Lags, leads, and subscripts are expressions used to select data from data objects. (See the discussion of
expressions later in this chapter.) One data object can be a used as a lag, lead, or subscript for another data
object.
a. lags and leads

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 sub-array 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

keywords as names can be confusing.)


It may be useful to think of a keyword as a special kind of sign, like a plus sign (+) or a greater-than sign (>) but
consisting of more than one letter (or sometimes only one letter, such as the "W" in the statement "search nipa w;"). The
next section discusses "operators," which usually take the form of signs (special characters) but can also take the form
of keywords.

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 non-scalar 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 element-by-element, 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 3-element 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 pre-multiplied by a column
vector. In TROLL, the conformation is element-by-element, so "A * B" is perfectly legal, and TROLL multiplies
each element of A by the corresponding element of B. Now consider a 3-element row vector C. In linear
algebra, "C * B" would be a scalar; in TROLL, "C * B" is a 3-by-3 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 3-element row
vector with a 4-element row vector. However, you can add a 3-element row vector with a 4-element
column vector, because each active dimension in one vector corresponds to an inactive dimension in the
other. The result will be a 4-by-3 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 equal-signs 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.

You've probably heard of NOT before.

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 12-period 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
n-period 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(i-1: anndiff/monthly(-i));

For a given value of I, this statement calculates the I-1 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);

The SUM operator can also be nested:


TROLL Command: do y=sum(k=z[3]**2 to sum(i=1 to 5: z[i]): k*x[k*2]**(1/k));

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 "double-colon") 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]:

Space dimension number 1 -->


1
2

TROLL Command: do prt.((1992a::1995a)-1);


1992A::1995A-1:
Date array -1 space dimension: 4

[1]:

Space dimension number 1 -->


1991A
1992A
1993A

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:

TROLL Command: do prtdata(x);


X:
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"

TROLL Command: do prt.(var);


VAR:
Numeric scalar:

TROLL Command: do dfdelete(basename, varname);


TROLL Command: do prt.(varname, basename);
VARNAME:
String scalar:

"VAR"

BASENAME:
String scalar:

"SAVE"

TROLL Command: do prt.(var);


ERROR 2222
Evaluating error.
Variable 'VAR' was not found on the current SEARCH list.

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 user-defined functions is a fairly advanced task, but fortunately for the beginner, there are
plenty of useful functions built in to TROLL.

1. Built-In
Indeed, TROLL has so many built-in functions that even a sophisticated user can feel overwhelmed. It is
convenient to divide TROLL's built-in 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

inverse trigonometric functions:


ARCSIN
ARCCOS
ARCTAN
ARCCOT

rounding functions (which can apply at any digit or decimal place):


ROUND

standard rounding
ROUNDUP

round away from zero


TRUNCATE

round toward zero


CEILING

round in a positive direction


FLOOR

round in a negative direction


other arithmetic components
SIGN
ABSV

absolute value
MODULO

remainder
advanced arithmetic functions
EXP
LOG

(natural)
LOG10
SQRT

accumulators and differentiators


CUMPROD

cumulative product of a vector


CUMSUM

cumulative sum of a vector


ARRDIFF

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

generates an arithmetic sequence of numbers or dates


CRMAT

creates a matrix in which every element equals a given constant

EXPAND

expands a vector or a scalar timeseries by repeating values


ADDCOL

adds a column of values to a matrix


CRDIAG

creates a diagonal matrix from a vector


CRSERIES

constructs a timeseries from pairs of date and value arrays


ADDROW

adds a row of values to a matrix


ARRCOMB

combines arrays
PARTCOMB

combines matrices
TSCOMB

combines timeseries
taking arrays apart
VALUES

extracts selected elements from an array


SUBMAT

extracts an element or submatrix from an array


SUBRANGE

extracts a subrange of dates from a timeseries


DELCOL

deletes columns from a matrix


DELROW

deletes rows from a matrix


SUBDEL

deletes slices from an array


ARRSPLIT

splits an array along selected dimensions


SELECT

selects values from specified arguments


changing array structure
RESHAPE

changes the shape of an array


SORT

sorts vectors
or REV.
reverses the order of values in a vector

REVERSE
TRANSP

transposes a matrix or reorders the space dimensions of an array


changing array data
SETREP

replaces selected elements in an array


CONVERT

converts datatypes, usually between strings and other datatypes


SPLINE

interpolates a cubic spline given X-Y arrays


getting information about array structure
COL

column indices of an array


ROW

row indices of an array


DIMSIZE

sizes of the space dimensions of an array


DIMVALS

indices of the cells of an array along a selected dimension


NDIMS

number of space dimensions in an array


NOC.

number of columns in an array

NOR.

number of rows in an array


NVALS

total number of values in an array


getting information about array content
DATATYPE

returns the datatype of its argument


DATINT

locates values in an array


or ALL.
tells whether all elements in an array are TRUE or equal a particular value

ALLSAME

IDENTICAL

tells whether data objects are identical


c. character string manipulation
There are also a lot of string functions.
putting strings together
JOINSTR

concatenates all the elements in a string array


REPSTR

repeats and concatenates character strings


CODE2STR

converts numeric or keyword codes to characters


taking strings apart
SUBSTR

extracts substrings
SPLITSTR

splits a string into individual characters


STR2CODE

converts the characters in strings to numeric codes


TOKENIZE

separates strings into lexical items


information about strings
LENGTH
INDEX

locates substrings
changing strings
LOWER

converts to lowercase
UPPER

converts to uppercase
CHANGESTR

changes substrings within a character string


TRIMSTR

trims characters from strings


CONVERT

converts datatypes
STR2SRC

converts strings to "source" form by restoring escape sequences


d. matrix algebra
Matrix algebra provides a foundation for the kind of mathematical modelling and statistical analysis for
which TROLL was designed. TROLL's matrix algebra functions allow users to design custom
procedures efficiently and with minimal effort. Although TROLL has only a few particular matrix
algebra functions, those functions are versatile enough to accomplish a wide variety of tasks. TROLL
offers the following functions for matrix manipulation:
basic matrix operations
IDEN

creates an identity matrix

MATMULT

matrix multiplication
DIAGONAL

extracts the diagonal from a matrix


DETERMINANT
LOGDETERMINANT
INVERSE

decompositions
CHOLESKY

Cholesky decomposition
MINFIT

singular value decomposition


LUDECOMP

LU decomposition
SCHUR

Schur decomposition
GENSCHUR

Generalized Schur decomposition


advanced matrix operations
LUSOLVE

solves a matrix equation using an LU decomposition


QUADFORM

quadratic forms and related products


KRONECKER

Kronecker product
EIGEN

eigenvalues and eigenvectors


GENEIGEN

generalized eigenvalues and eigenvectors


data filtering
KALMANF

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 Non-Missing 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

returns TRUE wherever an array has a missing value


NATEST

tells whether data objects contain any missing values


Replacing and Removing Missing Values
NAFILL

replaces each missing value in an array with a specified value


NAGROW

replaces missing values using growth rates to interpolate


NAINTERP

replaces missing values using linear interpolation


NASQUEEZE

removes missing values from an array


NATRIM

trims missing values from each end of a timeseries


f. output
Data don't do you much good until they produce something you can see. TROLL will let you see task

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 "output-like" 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

displays a line of data values with no header or formatting


PRINTNC

("PRINT No Carriage-return") displays a line of data values without a carriage-return at


the end
PRTDATA or PRT.
displays data objects with header information
PRTIME

displays a table with timeseries as columns


PRTMAT

displays a matrix with row and column labels


SPECS

displays data object headers


file output
MAT2WKS

stores a matrix in a spreadsheet file


XPRTIME

writes a table with timeseries as columns to an external text file


XPRTMAT

writes a matrix with row and column labels to an external text file
internal output
SPRINTF

writes formatted numbers into strings


g. random numbers
TROLL provides several functions to generate (pseudo-)random numbers, which are useful for
stochastic simulations.
floating-point numbers
RANDNORM

generates normally distributed pseudorandom numbers


RANDUNIF

generates uniformly distributed pseudorandom numbers


integers
RANDINT

generates uniformly distributed pseudorandom integers


h. probability distributions
You needn't assume that everything in the world is normally distributed: TROLL provides a rich set of

distribution functions.
discrete distributions (cumulative)
PBIN

binomial distribution
PHYPG

hypergeometric distribution
PPOIS

Poisson distribution
continuous distributions
PCHI

chi-square distribution
PFISH

F distribution
PNORM

normal distribution
PSTUD

Student's t-distribution
inverse distribution function
INORM

inverse normal cumulative distribution function


i. summary statistics
TROLL's statistical functions include the usual univariate and multivariate statistics, as well as several
different ways of handling minima and maxima of multiple arrays. (Remember that a scalar is a special
case of an array, so minima and maxima for a set of scalars are straightforward. The MAX and MAXS
functions, for example, will generally produce identical results when applied to a list of scalars.)
TROLL's univariate statistical functions go a step beyond simple calculation by eliminating missing
values.
univariate statistics
MEAN
MEDIAN
TOTAL

(sum)
or VAR.

VARIANCE
SDEV

standard deviation
STATS

multiple, selectable summary statistics


multivariate statistics
CORREL

correlation matrix for a set of vectors or series


COVAR

covariance matrix for a set of vectors or series


COVCOR

generates a matrix containing covariances and correlations for a set of vectors or series
extrema
MAX

maximum for each position across multiple arrays


MAXS

overall maximum across multiple arrays


MAXARG

identifies which arguments contain the maxima


MIN

minimum for each position across multiple arrays


MINS

overall minimum across multiple arrays


MINARG

identifies which arguments contain the minima


RANGE

minimum and maximum

j. programming
The functions listed below are primarily for use in TROLL programs (macros and user-defined
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

returns the number of arguments to a TPL function


GETARG

retrieves arguments to a TPL function by number


CLEAR

clears the current input buffer


GETDATA

retrieves data objects by name


GETCOM

retrieves comments from data objects


output
PUTCOM

adds or deletes data comments


PUTDATA

stores data objects by name


getting context information
GETOPT

retrieves option values


LASTERR

returns the number of the last ERROR or WARNING


LEVEL

returns the depth level of the currently active program


INMACRO

tells whether the context is a macro (as opposed to a function)


controlling the environment
PUTOPT

changes option settings


EXIT

aborts all active programs


k. modelling
Typically, a TROLL analysis or simulation has a model as its foundation. Usually, you work with models
using MODEDIT commands in the Model-Editing Task. Sometimes, particularly in programs or in files
that can be re-run with different data or models, it is useful to access model information with functions.
These functions let users exploit directly the inner apparatus that TROLL uses to deal with models. For
example, TROLL's symbolic differentiation facility is most often used internally by TROLL for
optimization. But if you just want to take a derivative, you can access that facility directly using the
DERIV function.
retrieving symbolic information
EQLABELS

gets equation labels given numbers or equation numbers given labels


EQSYM

gets names of symbols in selected equations


MODSYM

gets names of symbols in the current model


SYMTAB

finds horizons for symbols from the current working model


evaluating symbolic information
EVALSTR

evaluates an expression and returns its value


EVALARR

evaluates an array of expressions and returns the values

EQEVAL

evaluates an equation from a model


MODEVAL

evaluates equations from a model


processing symbolic information
DERIV

takes symbolic derivatives


LKROOTS

Performs eigenanalysis on a Jacobian matrix representing a linearized version of a model.


outputting symbolic information
SOURCEMOD

returns string array containing MODEDIT commands


l. filesystem (troll databases)
The preferred method for accessing and manipulating files in TROLL is to use TROLL's internal file
system, which maximizes portability across platforms. We've already seen many examples of commands
that deal with TROLL databases. Another way to deal with TROLL databases is with the functions listed
below.
A TROLL "file" is usually not the same as a system "file". For example, your system might contain a file
named "uknipa.frm". To TROLL, however, "uknipa.frm" would most likely be a "database" rather than
a file. To TROLL, the individual objects within a database are known as "files". Thus if uknipa.frm
contains a variable called "gdp", the data for that particular variable would be a "file" from TROLL's
point of view. Moreover, TROLL "files" can exist in RAM, not just on disk. The SAVE database, for
example, contains TROLL files that exist entirely apart from system files.
TROLL databases of type DISK, however, usually do contain files that correspond to individual host
system files. A DISK database generally corresponds to a host system "directory" or "folder". The items
within that directory are known to both TROLL and the host system as "files"
TROLL also makes a distinction between data files and nondata files. Most typically, a TROLL "data
file" will represent a single TROLL data object, which could be a scalar constant, a vector, a matrix, a
scalar timeseries, or a vector timeseries. A nondata file might contain a model or a TROLL program.
Some TROLL functions apply only to data files, while others apply to both data and nondata files.
filesystem information
FINDFILE

finds a specified file according to current SEARCH rules


FLIST

lists files of any type in an ACCESSed database


LKACCESS

returns information on currently ACCESSed databases


LKSEARCH

returns information on current SEARCH list


DFLIST

lists data files in an ACCESSed database


data file processing
DFCOPY'F

copies data files from one database to another


DFDELETE

deletes data files from an ACCESSed database


DFRENAME

renames data files in an ACCESSed database


general file processing
FCOPY'F

copies files of any type from one database to another


FDELETE

deletes files of any type from an ACCESSed database


FRENAME

renames files of any type in an ACCESSed database


m. external file input/output

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 human-readable 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

returns the host-system directory-separator character


HFEXIST

tells whether files exist on the host system


HFOLIST

lists the host files that are currently open by HFOPEN


HFTELL

identifies the current position in an open host file


HFOGETFP

gets the fileptr for an open host file


input
HFGETC

reads bytes from an open host file


HFGETS

reads a line from an open host file as a string scalar


WKS2MAT

reads a spreadsheet range as a matrix


XREAD

reads a host-system text file into a string array


output
XAPPEND

appends strings to a host-system text file


HFPRINTF

writes formatted output to a host file or to your terminal


HFPUTC

writes bytes to an open host file


HFPUTS

writes strings to an open host file


MAT2WKS

stores a matrix in a spreadsheet file


XWRITE

writes strings to a host-system text file


host file management
HFOPEN

opens a host file for input/output


HFCLOSE

closes open host files


HFDELETE

deletes host files


HFSEEK

locates a position in an open host file


n. system interface
You can access the host operating system from within TROLL, even from within a TROLL program, by
using the functions below.
getting system information
DATETIME

current date and time or the number of seconds since starting TROLL
GETENV

retrieves environment variables from your host operating system


external commands
HOST

passes commands to your host operating system


o. miscellaneous

A few more functions, apropos of nothing in particular:


data comparison
IDENTICAL

tells whether data objects are identical


function optimization
MINIMIZE

minimizes a function
getting TROLL information
LKSTATUS

returns information from the USEMOD, BOUNDS or DRANGE command


VERSION

returns current TROLL release number or platform version


p. timeseries and dates
On the data side, TROLL is designed primarily to work with time series. Accordingly numerous TROLL
functions relate specifically to time series:
series information
DATES

returns the dates from the time dimension of an array


STARTDATE

returns the startdate of a timeseries


ENDDATE

returns the enddate of a timeseries


NOB

returns the number of observations in a timeseries


BOUNDS

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

computes the compound growth rate per period for a timeseries


date construction
PV2DATE

returns date given periodicity and value (per*year+fraction)


PYF2DATE

returns date given periodicity, year and fraction


CRDATE

constructs dates from their component values


TV2DATE

returns dates with the specified periodicity type and value


TYF2DATE

returns dates with the specified periodicity type, year and fraction
date conversion
DATE2FRAC

extracts fractions from dates


DATE2PER

extracts periodicities from dates


DATE2YEAR

extracts years from dates


DATE2VAL

like DATE2YEAR but returns year*per+frac


DATESPLIT

splits dates into all their component values


DATE2DAY

returns the day-of-the-month for day-based dates


DATE2MONTH

returns the month for monthly or day-based dates


DATE2SUBFRAC

extracts the sub-fraction or offset of a date


DATE2TYPE

returns the periodicity type of a date

DATE2WDAY

returns the day-of-the-week for day-based dates


changing periodicity
COMPACT

reduces the periodicity of a timeseries by one of three methods: summation, averaging, or


selection of a certain value from each group of input values
SPATQ

converts an annual timeseries to quarterly using a cubic spline


SPLINETS

converts a timeseries to a new periodicity using a cubic spline


SPQTM

converts a quarterly timeseries to monthly using a cubic spline


time series processing
MOVAVG

moving average
KALMANF

Kalman filter
KFOPT

estimates Kalman Filter hyperparameters via maximum likelihood


AUTOCUM

accumulates a series based on an autoregressive structure


SUBRANGE

extracts a subrange from a timeseries


OVERLAY

creates a timeseries by overlaying several timeseries

2. User-Defined
TROLL also allows users to define their own functions. Some installations have libraries of user-defined
functions that are available to all local users. User-defined functions are defined in certain TROLL programs,
which are a later topic. The syntax for calling user-defined functions is like the syntax for built-in functions,
except that user-defined functions must be declared as such. The easiest way to declare a user-defined 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 user-defined function can be used anywhere that a built-in 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
GDP-1.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:

TROLL Command: do gdp=reshape((seq(10))**.5,1a);


TROLL Command: do cons=reshape(1+log(seq(10)),1a);
TROLL Command: do prtdata("It is " ||
Continue eq: convert( 100*(del(log(cons))-1.0) > 100*(del(log(gdp))-1.0) )||
Continue eq: " that consumption is growing faster than GDP.") ;
"It is "||CONVERT(100*(DEL(1: LOG(CONS))-1) > 100*(DEL(1: LOG(GDP))-1))||" that
consumption is growing faster than GDP.":
String scalar timeseries -Time dimension: Periodicity 1, 2A to 10A (9 observations)
2A
3A
4A
5A
6A
7A
8A
9A
10A

:
:
:
:
:
:
:
:
:

"It
"It
"It
"It
"It
"It
"It
"It
"It

is
is
is
is
is
is
is
is
is

TRUE that consumption is growing faster than GDP."


TRUE that consumption is growing faster than GDP."
FALSE that consumption is growing faster than GDP."
FALSE that consumption is growing faster than GDP."
FALSE that consumption is growing faster than GDP."
FALSE that consumption is growing faster than GDP."
FALSE that consumption is growing faster than GDP."
FALSE that consumption is growing faster than GDP."
FALSE that consumption is growing faster than GDP."

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*I-1 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*I-1]*GDP(2*I-1). In
the first half of that larger expression, the expression 2*I-1 is used as a subscript to select a particular row or element of
X. In the second half, the expression 2*I-1 is used as a lag or lead (depending on its sign) to offset the elements of GDP
by 2*I-1 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 well-established 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 re-numbered 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;

// display the equations in the current model

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

MODEDIT Command: deleq 1; // delete an equation identified by number


MODEDIT Command: print eq all; // display the remaining equations
Equations:

1:
2: NEWEQ

B2*X
Y = B1*X

MODEDIT Command: deleq neweq; // delete an equation identified by label


MODEDIT Command: print eq all; // display the remaining equation
Equations:
1:

B2*X

c. identities that define DEFINITION-type symbols


Ordinarily TROLL places very few restrictions on the structure and order of model equations. There is
one notable exception that applies to models used for simulation: DEFINITION-type variables must be
defined before they are used. This means that the first place each DEFINITION-type symbol appears in the
equations must be alone on the left-hand-side of its "identity equation", and it may not appear in the
right-hand-side of that equation.

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 data-writable database on the current SEARCH list
DOCORE

store the result in the "CORE" database (sort of a temporary "scratch-pad" 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 data-writable 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 data-writable 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 data-writable 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
non-writable 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 model-editing, 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 model-editing task:
TROLL Command: addeq bottom x=2;
MODEDIT Command:

The major tasks in TROLL are:


Model Editing
MODEDIT

model-editing task
Estimation
Linear Single-Equation Estimation
ordinary least-squares
OLS

ordinary least-squares regression task, direct input option


OLSMOD

ordinary least-squares regression task, model input option


two-stage least-squares
TSLS

two-stage least-squares regression task, direct input option


TSLSMOD

two-stage least-squares regression task, model input option


least squares with serial correlation correction
SCC

serial-correlation-correction regression task, direct input option


SCC

serial-correlation-correction regression task, model input option


Non-Linear Single-Equation Estimation
NLS

non-linear single-equation regression task


Equation-Systems Estimation
3SLS

three-state least-squares estimation task


FIML

full-information maximum-likelihood estimation task


2SLS

two-stage least-squares equations-systems estimation task (similar to TSLS but supports


non-linear equations)
ZELLNER

Zellner "Seemingly Unrelated Regressions" estimation task


Temporary Calculation (seldom used; mostly for backward compatibility)
DOCORE

temporary calculation task


Simulation
SIMULATE

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
full-model simultaneous mode; the FORECAST command starts the simulation task in single-equation 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. High-Level Commands
A high-level command is a command directed at TROLL itself rather than at a particular task. Often, high-level
commands are used to start TROLL tasks. For example, the high-level command OLS starts the OLS task, and
the high-level command MODEDIT starts the MODEDIT task. A high level command can also be used to control the
TROLL session. For example, the high-level command TREXIT ends a TROLL session, and the high-level
command USEMOD sets the working model file for a TROLL session.
Normally, you type a high-level command at the "TROLL Command:" prompt. Often, you can also type a
high-level command at a task prompt such as "MODEDIT Command:". When you do that, TROLL leaves the task in
order to execute the high-level command. What happens next depends on the particular high-level 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

do y=reshape(seq(7),1a); // Generate dummy data


do x=reshape(sin(seq(7)),1a);
regopt final coef; // (Option just to save space)
ols y x, 1a to 7a; // OLS Command invokes OLS task

ESTIMATE

X
CONST

-1.147431
4.090767

OLS Command: prtresult res;

// Print OLS Residuals

RES
1A
2A
3A
4A
5A
6A
7A

-2.125237
-1.047411
-0.928842
-0.959146
-0.191067
1.588623
3.66308

OLS Command: usemod;


New model: (nameless)
TROLL Command: prtresult res;

// USEMOD is a high-level command


// We are no longer in the OLS task

ERROR 101
Not a command:
PRTRESULT
TROLL Command: ols y x, 1a to 7a;
COEF
X
CONST

// Invoke OLS task again

ESTIMATE
-1.147431
4.090767

OLS Command: modedit;


MODEDIT Command:

// MODEDIT is a high level command


//
which invokes a specific task

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. Low-Level Commands
A low-level command is a command directed at a specific TROLL task. Normally, you type a low-level
command at the prompt for the specific task to which it belongs. In the previous example, PRTRESULT is a
low-level command belonging to the OLS task. Outside the OLS task, PRTRESULT is unrecognized and produces an

error.
Sometimes you can type a low-level 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

// Enter OLS task

ESTIMATE
-1.147431
4.090767

OLS Command: addeq top y'n=c'c*x;


MODEDIT Command: print eq all;

// Issue low-level MODEDIT command from OLS

Equations:
1:

Y = C*X

MODEDIT Command:

At the

OLS prompt, we issue a low-level 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

// Enter OLS task

ESTIMATE
-1.147431
4.090767

OLS Command: lksearch;

// Issue utility command from OLS task

Current SEARCH list:


Name
---SAVE
.
TROLLSYS

W?
-W
W

Filetype
-------DATA
NONDATA
NONDATA

Basic?
-----BASIC
BASIC
BASIC

OLS Command: quit;


// Leave OLS task
TROLL Command: lksearch;
// Issue utility command from TROLL prompt
Current SEARCH list:
Name
---SAVE
.
TROLLSYS

W?
-W
W

Filetype
-------DATA
NONDATA
NONDATA

TROLL Command: modedit;


MODEDIT Command: lksearch;

Basic?
-----BASIC
BASIC
BASIC

// Enter MODEDIT task


// Issue utility command from MODEDIT task

Current SEARCH list:


Name
---SAVE
.
TROLLSYS

W?
-W
W

MODEDIT Command: quit;

Filetype
-------DATA
NONDATA
NONDATA

Basic?
-----BASIC
BASIC
BASIC

// Leave MODEDIT task

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 non-linear single-equation 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 IF-THEN-ELSE constructions) and user-input 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 "queue-input" 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 built-in functions, except that a TPL
function ends with an apostrophe-F ('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 "queue-input" 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. user-written macros
In this context, "user-written" means "written by programmers who use TROLL" (not necessarily by
"users" in the sense of "people who use macros"). The ability of "user-programmers" 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. User-Defined Functions
Again, in this context, "user-defined" means "defined by programmers who use TROLL" (not necessarily by
"users" in the sense of "people who use functions"). A user-defined function is a function designed to
supplement the set of functions built in to TROLL. A user-defined function behaves like a built-in function.
Unlike a built-in function, a user-defined function has to be declared explicitly, usually by adding apostrophe-F
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 periods-per-year 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 4-or-12 periods-per-year 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 "queue-input" 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 read-ACCESSed 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

is label width. MAXBLANKS is the maximum number of consecutive blank lines.

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.

b. convergence criterion (CONCR)


The convergence criterion is 0.001 by default. The exact meaning depends on the context. In general, a
larger convergence criterion is more lax, and a smaller one is more precise.
c. other general convergence options
RADIUS, DIVCR, FEVALMAX, STOPCONV,

and START control various aspects of optimization. See the TROLL


Reference Manual CONOPT section for details.

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.

e. other optimization and related options


determines which optimization algorithm to use for unconstrained optimization in estimation
tasks. DFP is the default; BFGS, MINOPT, SUMSOL, SUMSNO, LBFGSB, SOLVOPT, and SOLVNO are available.
COPTALG determines the algorithm for constrained optimization: currently SOLVOPT is the default, and
LBFGSB and SOLVNO are available. CONDWARN (default 100) determines the condition number that triggers a
collinearity warning in regression.
OPTALG

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.

d. nonlinear least squares options (NLSOPT)

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.

1. Command and Program Comments


Command and program comments are either introduced by a double slash (//) or delineated by an opening
slash-asterisk (/*) and a closing asterisk-slash (*/). A double-slash type comment (sometimes called a C++ style
comment since the format comes from the C++ programming language) ends at the end of the line on which the
double-slash occurs. A slash-asterisk type comment (sometimes called a C-style comment since the format
comes from the C programming language) ends whenever the closing asterisk-slash appears. Thus a slashasterisk type comment can be in the middle of a single line, or it can span several lines. A double-slash type
comment begins either at the beginning or in the middle of a line and always ends at the end of a line. A slashasterisk type comment can begin and end anywhere. Here are some examples:
TROLL Command: /* This is a comment */
TROLL Command: // This is also a comment
TROLL Command: do prt.(6); //This text is a comment
6:
Numeric scalar:

TROLL Command: do /* This text is also a comment */ prt.(6);


6:
Numeric scalar:

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.)

IV. USING TROLL


There are several different ways of using TROLL.

A. TROLL LEVEL vs. TASK LEVEL


Some of the things you do with TROLL, you do at the "TROLL level", which is to say, your commands are processed
from the TROLL command prompt. At the TROLL level, you can use high-level commands (commands designed
specifically for the TROLL level) and utility commands (commands that can run from anywhere in TROLL). You can
also type low-level commands to the TROLL command prompt, but in doing so, you leave the TROLL level and enter
the "task level".
Commands at the task level are processed from the specific task's command prompt. The task's command prompt
appears when you enter the task. This usually happens either because you type the name of the task or because you type
a command that TROLL recognizes as belonging to that task. At the task level, you can use low-level commands
(commands designed specifically for the particular task) and utility commands. You can also type high-level commands
to a task command prompt, but in doing so, you leave the task and enter either the TROLL level or another task.

B. CONSOLE vs. GUI (PC ONLY)


If you use TROLL on a PC or other Windows environment, you probably have available the "GUI" or "Graphical User
Interface" version of TROLL. The GUI version of TROLL provides a multi-windowed view of TROLL including an
"Input" window for typing commands and a "Session" window for viewing the results. There is also a button bar to
facilitate quick actions, a menu bar to make some commands available without typing, and a text editor in which you
can view, edit, and run multiple TROLL files of various types.
Examples in this Guide thus far have used the "console" version of TROLL, which is available on all platforms. In the
console version, a TROLL session is a sequence of "typed" commands and responses on a single screen or window. The
console version uses exactly the same set of commands as the GUI version, but all commands must be typed. In the GUI
version, you can type any TROLL command just as you would in the console version, but you also have the choice of
executing some commands using buttons or menus.
The text that appears in the "Session" window in the GUI version is the same as what appears on the screen in the
console version. However, in the GUI version, you must type commands in the "Input" window (or in the editor).
The GUI and console versions have various relative advantages. The console version is more stable, runs faster, uses
fewer system resources, looks the same on a UNIX system as it does on Windows, can run multiple instances on
multitasking systems, and involves less clutter. The GUI version is easier to learn with, presents a more user-friendly
image, enables the production of charts and graphs, taxes the user's memory less, has the same features on different
Windows platforms, provides more flexibility within a TROLL session, and obviates the need for an external text editor
to use for typing TROLL program and data files.
For those who have both versions available, the choice between GUI and console is largely a matter of personal
preference. New users tend to prefer the GUI, whereas many experienced users prefer the console, but these are only
tendencies. The features provided by the GUI may be more valuable in some environments than in others. For example,
the GUI provides the ability to re-issue earlier commands by scrolling up the Input window, positioning the cursor, and
pressing "Enter." This GUI feature can be quite valuable for Windows 95 users, who may have no other way of
retrieving old commands. But under Windows NT, the operating system provides a similar feature even to console users.
Because the Session window provides a console-like view to the GUI user, whereas the console user has no
corresponding GUI-like view available, this Guide will continue to use examples primarily from the console version. If
you use the GUI, you can implement the examples by typing the bolded text into the Input window and watching the
Session window for the results. But feel free to experiment with the GUI-only features, such as buttons, menus, and the
editor. If you understand the TROLL commands and have experience with Windows, the GUI's features are largely
self-explanatory.

C. INTERACTIVE vs. BATCH


There are two ways to run a TROLL session. One is just to type in commands and watch TROLL's responses. That's
called "interactive mode". The other way is to use TROLL input files to run a pre-written set of commands. That's called
"batch mode."
All the examples in this Guide so far have used interactive mode. Interactive mode is usually better for learning: typing
commands and then seeing the results immediately gives you a better sense of what the commands do. Interactive mode
can also be useful when you want to explore some data or model without really knowing exactly how beforehand. By
using interactive mode, you can change your course of action depending on the results of your previous action. For
example, you might use summary statistics as an indication of what kind of regression to run, or you might use
steady-state results as an indication of what kind of dynamic simulation to run.
Batch mode has different advantages. If you have a set of commands that you want to re-run several times with only
minor changes, batch mode enables you to avoid retyping the commands or scrolling up to find the old commands. If
you want to be able to repeat an analysis exactly at a later time, you can make it easy by using batch mode. If you have
an analysis that you want to share with others, you can use batch mode to specify the steps necessary to perform the
analysis, without requiring others to perform each step individually. If you know what you want to do but aren't sure
how, you can use batch mode to try out different sequences of commands without having to retype the parts they have in
common. If you want to run the same analysis on multiple datasets or using multiple alternative models, you can use
batch mode to specify the analysis and run it in different contexts.
To use TROLL's batch mode, you create a TROLL input file, normally with a file name ending in ".INP". In some
environments, INP is called the "filetype" or "file extension". In some Windows configurations, you may not see the
.INP in the file name, but .INP will determine the "Type" of the file. Windows may refer to such a file an "INP file". If a
file type has been registered with the INP extension, then TROLL input files will be of that file type.

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;

Current SEARCH list:


Name
---SAVE
.
TROLLSYS

W?
-W
W

Filetype
-------DATA
NONDATA
NONDATA

Basic?
-----BASIC
BASIC
BASIC

TROLL Command: do prt.(5*2);


5*2:
Numeric scalar:

10

TROLL Command: // This is the end of the input file.


TROLL Command:

The second way to run a TROLL input file is to use its name (without the ".INP") as a command-line 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. 1993-1997
Copyright (C) Massachusetts Institute of Technology 1978-1987
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

TROLL Command: do prt.(5*2);


5*2:
Numeric scalar:

10

TROLL Command: // This is the end of the input file.


TROLL Command:

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 double-clicking 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 number-of-periods and added to date; return value is a date.
date - number

Same as above, except the number-of-periods is subtracted.


date - date

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 not-available or not-computable 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
NA-type 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 non-NA 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

TRUE where x is NA, FALSE elsewhere

x == NA

TRUE where x is NA, FALSE elsewhere

NA <> x

FALSE where x is NA, TRUE elsewhere

x <> NA

FALSE where x is NA, TRUE elsewhere

IF bool THEN x ELSE NA

x where bool is TRUE and NA elsewhere

IF bool THEN NA ELSE x

x where bool is FALSE and NA elsewhere

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 queue-input statement consists of two
greater-than signs (>>) followed by a TROLL command. When the queue-input statement is executed, it causes TROLL
to execute that command.

B. THE SEQUENCE OF TROLL STATEMENTS


TROLL statements proceed in a certain order. In an interactive session or an input file, the order is simply "linear" -one statement after another. The only concern is whether TROLL is ready for the next statement you want to issue. In
TROLL macros and user-written functions, the order is controlled by the logic of the program, and the order my contain
loops and branches.

C. PECULIARITIES OF TROLL SYNTAX


Some things about TROLL syntax are peculiar. For example,

1. Abbreviated Function Names


Sometimes a function name can be abbreviated by a shorter name followed by a period. For example PRTDATA is
abbreviated as PRT. This probably wouldn't seem peculiar to an English teacher, but it might seem peculiar to a
programmer or an Internaut. An expression like PRT.(X) might seem exotic, but it's really just an application of
the quite mundane function PRTDATA.

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 high-tech 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."

VI. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE


A. MODELLING LANGUAGE
The Portable TROLL Modelling Language lets you express algebraic relationships. It is used for:
Calculations
Interactive "DO" commands
Models
Sets of equations used for estimation or simulation
Programs
Series of statements stored for future computation
Algebraic expressions consist of
Literals
Literal values such as numbers or character strings
Symbols
Names of data objects or functions
Operators
Special characters and keywords representing mathematical operations
Punctuation
Parentheses and commas, used to group operations and to specify subscripts and function argument lists
Although calculations, models and programs share a common modelling language, there are restrictions that apply in
each case. For example, a model cannot contain programming statements, only mathematical equations, but it can
include equations with complicated expressions on the left-hand-side.

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 (IF-THEN-ELSE),
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

Command: // By defining a multi-level variable, we create archives.


Command:
Command: do body_face_nose_color="Pink";
Command:
Command:
// The SAVE database now contains an archive called BODY,
Command:
//
which contains an archive called FACE,
Command:
//
which contains an archive called NOSE,
Command:
//
which contains a variable called COLOR.
Command:
Command: lksearch; // None of these archives are on the search list

Current SEARCH list:


Name
---SAVE
.
TROLLSYS

W?
-W
W

Filetype
-------DATA
NONDATA
NONDATA

TROLL Command: search save_body;


TROLL Command: lksearch;

Basic?
-----BASIC
BASIC
BASIC
// Put the BODY archive on the search list

Current SEARCH list:


Name
---SAVE
.
TROLLSYS
SAVE_BODY

W?
-W
W

Filetype
-------DATA
NONDATA
NONDATA
DATA

Basic?
-----BASIC
BASIC
BASIC

TROLL Command: do prt.(face_nose_color);


FACE_NOSE_COLOR:
String scalar:

// TROLL will now find FACE_NOSE_COLOR

"Pink"

TROLL Command: // The NOSE archive is not on the search list


TROLL Command:
TROLL Command: do prt.(color); // So TROLL will not know where to find COLOR
ERROR 2222
Evaluating error.
Variable 'COLOR' was not found on the current SEARCH list.
TROLL Command: search save_body_face_nose;
// Put NOSE on the search list
TROLL Command:
TROLL Command: do prt.(color); // Now TROLL can find COLOR
COLOR:
String scalar:

"Pink"

TROLL Command: lksearch;

// Also the BODY archive is still on the search list

Current SEARCH list:


Name
W?
----SAVE
W
.
W
TROLLSYS
SAVE_BODY
SAVE_BODY_FACE_NOSE

Filetype
-------DATA
NONDATA
NONDATA
DATA
DATA

Basic?
-----BASIC
BASIC
BASIC

TROLL Command: do prt.(face_nose_color);


FACE_NOSE_COLOR:
String scalar:

"Pink"

// So TROLL can still find FACE_NOSE_COLOR

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 3381-C10D
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 3381-C10D
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

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter Three. Using And Managing Information


I. THE ACCESS AND SEARCH LISTS
A. ACCESS LIST: THE AVAILABLE SET OF DATABASES
1. Troll's Default ACCESS List
2. Changing the ACCESS List
a. the ACCESS command: adding to the ACCESS list
b. host files as DATA databases
c. writable access modes
d. database names: IDs and aliases
e. the DELACCESS command: letting go of databases and changing 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 multi-level 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. Big-Endian Hardware vs. Little-Endian 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 line-by-line and letter-by-letter

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

Portable TROLL User's Guide

Chapter Three. Using And Managing Information


Just about everything you can do in TROLL involves using and managing information, in the broad sense of the term. There are several
kinds of information that TROLL uses. "Data" are the most obvious kind of information. Since TROLL is much more than a data
analysis tool, it also uses other kinds of information: in particular, models, programs, and command input files. TROLL also
distinguishes between program "source code" and compiled, "ready-to-run" programs as different types of information.
TROLL uses "databases" to store and retrieve information. Contrary to what you might think, "databases" can contain things other than
"data". A "database" is really an "information base", which could be a "model base", a "program base", a "source code base", an "input
file base", or a "data base" in the strict sense, depending on what type of information it stores. Also, some databases can store several
kinds of information.
This chapter covers both general aspects of information management in TROLL and specifics of how to use data. Storage and retrieval
methods for models, programs, and other non-data information are covered here, but not the specifics of how to create models,
programs, and input files. In TROLL, the storage and retrieval methods for non-data information are analogous to those for data, but
the processes of modelling and programming are very different from those involved in managing data.

I. THE ACCESS AND SEARCH LISTS


Information management in TROLL depends critically on two lists kept during a TROLL session -- the ACCESS list and the
list. These lists determine the locations where TROLL will store and retrieve data, as well as where TROLL will store
and retrieve programs, models, and any other information that it needs.
SEARCH

A. ACCESS LIST: THE AVAILABLE SET OF DATABASES


Before TROLL can use any data, the "database" containing that data must be on the ACCESS list. A database is a
"top-level" entry in TROLL's internal file system, where TROLL keeps track of available data. Such a database may
correspond to a "file" on the host operating system. Alternatively, a TROLL database may correspond to a "directory"
(or "folder") on the host system. Or a TROLL database may be a entity unknown to the host system.

1. Troll's Default ACCESS List

You can look at TROLL's ACCESS list by typing " lkaccess:"


TROLL Command: lkaccess;
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

(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.

2. Changing the ACCESS List


You can control the contents of the ACCESS list using the ACCESS and DELACCESS commands. (You cannot
eliminate FIXED databases from the ACCESS list.) The ACCESS command means, "Put this database (or these
databases) on the ACCESS list." The DELACCESS command means, "Take this database (or these databases) off the
ACCESS list." If you have some data (or a model or a program), and you want to use that data in a TROLL
session, then you have to do one of two things: either use the ACCESS command to make the data available to
TROLL, or place the data in a database (such as TROLLSYS) which automatically appears on the ACCESS list.
a. the ACCESS command: adding to the ACCESS list
ACCESS lets you specify several characteristics of an ACCESSed database. The only characteristic that you
must specify is the alias, without which TROLL would not have any way to refer to the database. The
rest TROLL will decide for you, if it can. For example,
TROLL Command: access tempdir;
TROLL Command: lkaccess;
Accessed Databases:
Alias

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 "non-data" 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 non-DISK 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 "host-file" 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 platform-independent, so that PC
and UNIX system users can share data. TROLLDB format is platform-specific.) Two other text formats are
available for sharing with specific other software: TSD for AREMOS, and TSPLOAD for TSP. FAME format,
a non-text 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;

// Access a FORMDATA database


// Access a TROLLDB database

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

TROLL Command: do prt.(base2.trl_c1);


BASE2.TRL_C1:
Numeric scalar:

Basic?
-----Fixed
Fixed
Fixed

ID
----(none)
(none)
d:\troll\code
TEMPDIR
BASE1.FRM
BASE2.TRL

// c1 happens to be in base2.trl

-36.541054

c. writable access modes


Suppose you want to use a "writable" database, which will contain new information created in your
TROLL session. You have to specify the "mode" parameter, which controls whether a database is
writable and whether it is to be a newly created database or an existing one. The simplest mode to
specify is MODE W, generic writable mode, as follows:
TROLL Command: access base3.frm type formdata mode w;
TROLL Command: lkaccess;
Accessed Databases:
Alias
----SAVE
.
TROLLSYS
TEMPDIR
BASE1.FRM

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 termination-protected.

There are two possible levels of termination protection. "Fixed" databases such as the SAVE database
have complete termination-protection: they cannot be DELACCESSed. "BASIC" databases -- those created
using the BASIC keyword -- have partial termination-protection. 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

TROLL Command: delaccess all;


TROLL Command: lkaccess;
Accessed Databases:
Alias
----SAVE
.
TROLLSYS
B5

DB Type
------MEMDB
DISK
DISK
TROLLDB

R/W?
---R/W
R/W
R
R/W

TROLL Command: delaccess b5;


TROLL Command: lkaccess;
Accessed Databases:
Alias
----SAVE
.
TROLLSYS

DB Type
------MEMDB
DISK
DISK

R/W?
---R/W
R/W
R

TROLL Command: delaccess trollsys;


WARNING 18159
This alias is flagged as "FIXED" and cannot be DELACCESSed:
TROLLSYS

f. opening multiple databases in one command


A single ACCESS command can specify multiple databases, by listing the databases (with all the requested
options: type, mode, id, etc.) separated by commas. Essentially, if you want to say "access [bunch of
stuff 1];" and "access [bunch of stuff 2];", you can combine them into "access [bunch of stuff 1],
[bunch of stuff 2];". The following passage repeats the earlier examples, but with the alias commands
combined:
TROLL Command: //This also shows how TROLL prompts for input
TROLL Command: // when a command has not been completely entered.
TROLL Command: //The following five input lines are one long command:
TROLL Command: access tempdir, base1.frm type formdata,
Alias name or ';': base2.trl type trolldb, base3.frm type formdata mode w,
Alias name or ';': b4 type trolldb mode w id base4.trl, b5 type trolldb
'TYPE', 'ID', 'MODE', 'SPECS', 'BAsic', 'FIXED', ',' or ';': mode w id
ID name: base5.trl basic; // There, the command is complete.
TROLL Command: lkaccess;
Accessed Databases:
Alias
----SAVE
.
TROLLSYS
TEMPDIR
BASE1.FRM
BASE2.TRL
BASE3.FRM
B4
B5

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

TROLL Command: delaccess tempdir b5 all;


TROLL Command: lkaccess;

ID
----(none)
(none)
d:\troll\code
TEMPDIR
BASE1.FRM
BASE2.TRL
BASE3.FRM
base4.trl
base5.trl

// Note:

"ALL" must come last

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 write-ACCESSes a database, all other TROLL sessions will be denied any
ACCESS.

B. SEARCH LIST: DEFAULT LOCATIONS FOR INFORMATION


1. Working Without a SEARCH List
If you don't mind doing things the hard way, the ACCESS command is all you really need to control TROLL's
database environment. Any database on the ACCESS list is available, and you can go ahead and work with its data
(or its programs or its models). If you do, you will make extensive use of the underscore, in the construction
"[database alias]_[object name]", which means, "The object [object name] from the database [database alias]."
The following passage repeats the OLS example from Chapter 1 using the underscore syntax:
TROLL Command: access nipa type formdata id c:\usanipa.frm;
TROLL Command: ols nipa_cons nipa_gdp, 1969a to 1995a;
ORDINARY LEAST SQUARES
LHS VARIABLE:

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 multi-level archive, and you end up using names like
local_mainbase_econdata_nipa_us_quarterly_nsa_real_base1985_gdp.

2. What the SEARCH List Is


TROLL's SEARCH list is a ordered list of locations where TROLL can find and/or store information. The order of
the SEARCH list specifies the order in which TROLL will search those databases. For example, if you refer to a
data object called CONS in a TROLL command, TROLL will look in each of the databases on the SEARCH list until
it finds an object called CONS. The databases on the SEARCH list can also have particular characteristics
(writability, filetype, etc.) that will affect whether TROLL looks at them when going through the SEARCH list for
a particular purpose.
Each item on the SEARCH list must be a database or archive to which TROLL has access, either directly or
indirectly. TROLL has direct access to those databases that appear on the ACCESS list. Such an ACCESSed database
is known by its alias. TROLL has indirect access to any database or archive that is a component or descendent of
an ACCESSed database. Such a component or descendant is known by a composite name beginning with the alias
of the ACCESSed database, and with the parts of the name separated by underscores. For example, suppose there
is a database called base1 (that is, a database with "base1" as its alias), and suppose base1 includes an archive
called part1, and suppose part1 contains a sub-archive called section1. If base1 appears on the ACCESS list, then
TROLL has direct access to base1 and indirect access to base1_part1 and base1_part1_section1. Any of these
three names could go on the SEARCH list.
You can look at TROLL's SEARCH list by typing "lksearch;"
TROLL Command: lksearch;

Current SEARCH list:


Name
---SAVE
.
TROLLSYS

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.

3. Changing the SEARCH List


You can control the contents and order of the SEARCH list using the SEARCH and DELSEARCH commands. In some
ways the SEARCH list is analogous to the ACCESS list, but unlike the ACCESS list, the SEARCH list is ordered. When
you use the SEARCH list, you have to be aware of not only which databases are on the list, but also where on the
list those databases appear. The SEARCH command means, "Put this database at a particular position on the SEARCH
list." The DELSEARCH command means, "Take (the first instance of) this database off the SEARCH list." To change
the order of the SEARCH list without changing the contents, you have to use both DELSEARCH and SEARCH.
a. the SEARCH command: adding to the SEARCH list
TROLL puts SAVE, [dot], and TROLLSYS (in that order) on the SEARCH list automatically, but the rest is up
to you. (Your site may use profiles that put other things on the SEARCH list automatically.) Before trying
to add something to the SEARCH list, it's useful to take a look at the ACCESS list. To go on the SEARCH list, a
database must either be on the ACCESS list or be a descendant of one that is on the ACCESS list. Because of
the syntax for descendants, this means that any name on the SEARCH list must begin with an alias that is
on the ACCESS list. Let's start with the full ACCESS list from the earlier example:
TROLL
Alias
Alias
TROLL

Command: access tempdir, base1.frm type formdata, base2.trl type trolldb,


name or ';': base3.frm type formdata mode w, b4 type trolldb mode w id base4.trl,
name or ';': b5 type trolldb mode w id base5.trl basic ;
Command: lkaccess ;

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

TROLL Command: search first b4;


TROLL Command: lksearch;
Current SEARCH list:
Name
---B4
SAVE
.
TROLLSYS

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 "non-writable" 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:

search last b5;


search before b5 tempdir;
search after tempdir base1.frm;
lksearch;

Current SEARCH list:


Name
---B4
SAVE
.
TROLLSYS
TEMPDIR
BASE1.FRM
B5

W?
-W
W

Filetype
-------DATA
DATA
NONDATA
NONDATA
ALL
DATA
DATA

Basic?
-----BASIC
BASIC
BASIC

b. to write or not to write


If you want TROLL to store its results in a particular database, you must specify a writable SEARCH rule
for that database, and that database must appear before any other write-SEARCHable database on the
SEARCH list. If you want TROLL to store its results in a particular database, you must specify a writable
SEARCH rule for that database, and that database must appear before any other write-SEARCHable database
on the SEARCH list. If you want TROLL to store its results in a particular database, you must specify a
writable SEARCH rule for that database, and that database must appear before any other write-SEARCHable
database on the SEARCH list. Remember that.
To specify a writable SEARCH rule, you simply put a W after the database alias in the SEARCH command. For
example:
TROLL Command: search first base3.frm w;
TROLL Command: lksearch;
Current SEARCH list:
Name
---BASE3.FRM
B4
SAVE
.
TROLLSYS
TEMPDIR
BASE1.FRM
B5

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 write-SEARCHable database is also read-SEARCHable.
You won't always have the opportunity to make a database write-SEARCHable. If TROLL does not have
write ACCESS to a database, then the database cannot be write-SEARCHable. TROLL will make it
read-SEARCHable instead:
TROLL Command: search first base2.trl w;
WARNING 5010
Search error:
The database 'BASE2.TRL' is accessed Read-Only;

'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 read-SEARCHable, we'll delete it and leave
the SEARCH list as it was reported above.)
TROLL Command: delsearch base2.trl;
TROLL Command:

c. changing the SEARCH order


To change the order of the SEARCH list without changing what is on it, use DELSEARCH followed by SEARCH.
DELSEARCH removes an item from the SEARCH list, and SEARCH puts it back on. For example, suppose you
want to move base3.frm from the top to the bottom of the SEARCH list. Just remove it from the top and
add it to the bottom:
TROLL Command: delsearch base3.frm;
TROLL Command: search last base3.frm w;
TROLL Command: lksearch;
Current SEARCH list:
Name
---B4
SAVE
.
TROLLSYS
TEMPDIR
BASE1.FRM
B5
BASE3.FRM

W?
-W
W

Filetype
-------DATA
DATA
NONDATA
NONDATA
ALL
DATA
DATA
DATA

Basic?
-----BASIC
BASIC
BASIC

d. removing items from the SEARCH list


You can use DELSEARCH just to remove something from the SEARCH list.
TROLL Command: delsearch tempdir;
TROLL Command: lksearch;
Current SEARCH list:
Name
---B4
SAVE
.
TROLLSYS
BASE1.FRM
B5
BASE3.FRM

W?
-W
W

Filetype
-------DATA
DATA
NONDATA
NONDATA
DATA
DATA
DATA

Basic?
-----BASIC
BASIC
BASIC

You can remove all non-BASIC 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 non-BASIC entry must be removed
explicitly.
TROLL
TROLL
TROLL
TROLL

Command:
Command:
Command:
Command:

delsearch save;
delsearch .;
delsearch trollsys;
lksearch;

Current SEARCH list:


Name
----

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

TROLL Command: delsearch all;


TROLL Command: lksearch;
Current SEARCH list:
Name
---B4

W?
--

Filetype
-------DATA

Basic?
-----BASIC

e. permanent ("file") and temporary ("memory") storage


Some TROLL commands make a distinction between permanent ("disk" or "file") and temporary
("memory" or "save") databases when they use the SEARCH list. This feature can be useful when you want
to distinguish between results that are only needed for the current session and results that you wish to
store for use in a later session or by another program.
A typical example is the set of commands DO, DOFILE, and DOSAVE. DO saves its result to the first writeSEARCHable database on the list. DOFILE saves its result to the first write-SEARCHable permanent database
on the list. DOSAVE always saves its result to the SAVE database, a specific temporary database which may
or may not be the first on the list. The following passage shows this behavior:
TROLL Command: search basic first save w;
TROLL Command: search after save b5 w;
TROLL Command: lksearch;
Current SEARCH list:
Name
---SAVE
B5
B4
TROLL
TROLL
TROLL
TROLL

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:

// List variables in "b5" database

"INFILE"

TROLL Command: listsave;


SAVE Database:

Basic?
-----BASIC

// List variables in "save" database

INDO
INSAVE

---

Numeric scalar
Numeric scalar

f. searching multi-level archives


The SEARCH list provides a convenient way of handling multi-level archives. Multi-level archives are a
hierarchical structure implicit in the way TROLL handles databases. An archive is a "location" for a set
of variables. An archive can be a database on the ACCESS list, or it can be a child or descendant of such a
database. You can specify an archive as the location of a particular data object by prefixing the archive
name, followed by an underscore, to the name of the data object.
Consider a data series named B5_US_SA_REAL_GDP. You may (correctly) think of that series as the series
US_SA_REAL_GDP from the archive called B5. Alternatively, you may (equally correctly) think of that
series as the series GDP from the archive B5_US_SA_REAL. Or you may (again correctly) think of it as the
series REAL_GDP from the archive B5_US_SA, or the series SA_REAL_GDP from the archive B5_US. TROLL's
SEARCH list can handle any of these possibilities, as the following passage demonstrates.
TROLL
TROLL
TROLL
TROLL
TROLL

Command:
Command:
Command:
Command:
Command:

access usanipa type formdata id c:\usanipa.frm;


search first usanipa; // "usanipa" contains "gdp"
do b5_us_sa_real_gdp = gdp;
// Put "gdp" in "b5_us_sa_real"
delsearch usanipa; // Forget about "usanipa"
lksearch; // Now none of these is a direct parent of "gdp"

Current SEARCH list:


Name
---SAVE
B5
B4

W?
-W
W

Filetype
-------DATA
DATA
DATA

Basic?
-----BASIC
BASIC

TROLL Command: do prt.(gdp);


ERROR 2222
Evaluating error.
Variable 'GDP' was not found on the current SEARCH list.
TROLL Command: search after b5 b5_us_sa_real;
TROLL Command: do prt.(gdp);

// "b5_us_sa_real" contains "gdp"

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

TROLL Command: // ...but no SEARCHed archive contains "sa_real_gdp" directly


TROLL Command: do prt.(sa_real_gdp);
ERROR 2222
Evaluating error.
Variable 'SA_REAL_GDP' was not found on the current SEARCH list.
TROLL Command: search after b5_us_sa_real b5_us;
TROLL Command: lksearch;
Current SEARCH list:
Name
---SAVE
B5
B5_US_SA_REAL
B5_US
B4

W?
-W
W

Filetype
-------DATA
DATA
DATA
DATA
DATA

Basic?
-----BASIC

BASIC

TROLL Command: do prt.(sa_real_gdp);


SA_REAL_GDP:

// "b5_us" contains "sa_real_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

g. specifying multiple SEARCH rules at once


As with ACCESS, SEARCH can take multiple arguments. However, SEARCH will not allow you to
apply different position specifiers or different "basic" status to the different arguments. You can apply
different "W?" status to the various arguments, and the arguments need not be separated by commas. The
following command adds b5_us_sa, save_newbase, and TROLLSYS (in that order) to the top of the SEARCH
list, with only save_newbase as a write-SEARCHable archive:
TROLL Command: search first b5_us_sa save_newbase w trollsys;
TROLL Command: lksearch;
Current SEARCH list:
Name
---B5_US_SA
SAVE_NEWBASE
TROLLSYS
SAVE
B5
B5_US_SA_REAL
B5_US
B4

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 billy-goats who tried to use the SEARCH list without paying close attention.

II. HOST CONSIDERATIONS


A. UNIX SYSTEMS vs. PCs
UNIX systems and PCs are different. For example, UNIX systems use forward slashes to specify file locations (e.g.
"/usr/data/trolldat"), whereas Windows PCs use backward slashes (e.g. "\usr\data\trolldat"). TROLL is designed
to be portable across platforms: properly written programs for TROLL developed on one platform should work on any
other platform. As a TROLL user, however, you will need to deal with your particular host system and its particular
idiosyncrasies. You may also find that your platform offers useful features that are not present on other platforms.

1. UNIX Operating Software vs. Windows Operating Software


The "slashes vs. backslashes" example in the above paragraph refers to a difference in the operating software. A
PC running the Linux operating system (for which TROLL is also available) would behave like a UNIX system
with respect to most such operating system issues. In particular, Linux does use forward slashes.

2. Big-Endian Hardware vs. Little-Endian Hardware


Another way in which PCs differ from most UNIX systems is in the way that numbers are represented internally.
PCs use the so-called "little-endian" representation, wherein the low-order byte comes first; most other
computers use the "big-endian" representation, wherein the high-order byte comes first. With respect to this and
other hardware differences, a Linux PC is very much a PC and does not behave like most commercial UNIX
systems. Thus, for example, a TROLLDB database that can be shared among various commercial UNIX systems
cannot generally be shared with a Linux PC.

B. UNIX SYSTEMS vs. UNIX SYSTEMS, PCs vs. PCs

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 up-arrow 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.

C. LOCAL vs. NETWORK


Another difference among different TROLL installations is the difference between a local installation (on the computer
you use directly) and a network installation (on some other computer that is connected to yours). This may affect how
you use TROLL.
Furthermore, whether TROLL is installed on your local computer or somewhere else on the network, some of your
TROLL files may be local and others may be elsewhere on the network. This may affect how you access those files.
The simplest case is a local TROLL installation using local files. If your computer is not connected to a network, then
this is the only possibility.
Most of the examples in this Guide use local files with a local TROLL installation. Moreover, most of the examples
come from a PC environment (Windows NT 4). Bear in mind that not everything in the examples will apply in all
environments. Especially if you work in a UNIX environment or if you use TROLL over a network (either installed on
the network or using network data), you should talk to your local TROLL consultants about the particulars of data
access.

III. ENTERING DATA


There are several ways to enter data in TROLL. The most common are the &DEDIT macro and the COMBINE function.

A. THE &DEDIT MACRO


is a "sample" macro included with TROLL. &DEDIT simplifies the task of entering or modifying a time series. If
you're not yet comfortable with macros, just think of &DEDIT as a command that begins with an ampersand (&). You can
start a &DEDIT session for a new time series by typing "&DEDIT" followed by the series name and the first date in the time
series:
&DEDIT

TROLL Command: &dedit aseries 1960a;


New series ASERIES
DEDIT Command:

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

Terminate the data entry process with a semicolon:


Value for 1964A or ';': ;
DEDIT Command:

To add more data to an existing series, use the ADD command:


DEDIT Command: add 1963a
Value for 1964A or ';': 5
Value for 1965A or ';': 6

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
*

Similarly, the DELETE command causes future data to shift backward:


DEDIT Command: delete 1960a to 1962a;
DEDIT Command: print data;
1960A:
1964A:
1968A:

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
*

B. THE COMBINE FUNCTION


Another way to enter data is by "brute force", using the COMBINE function. COMBINE puts together a series of numbers into
an array (without a time dimension). If you want a time series, you can use the RESHAPE command to convert the array
into a time series. More generally, you could reshape the array into a matrix, a multidimensional array, a timeseries of
arrays, or a timeseries of matrices or multidimensional arrays.
Let's start with a simple array. The following statement creates an array of numbers by combining the data which the
user provides:
TROLL Command: do unemp=combine(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 prt.(unemp);
UNEMP:
UNEMP = COMBINE(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)
Numeric array -1 space dimension: 16

[1]:
[5]:
[9]:
[13]:

Space dimension number 1 -->


7.1
7.6
7.5
7.2
5.5
5.3
7.4
6.8

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)

Numeric scalar timeseries -Time dimension: Periodicity 1,

1980A
1984A
1988A
1992A

:
:
:
:

Time dimension -->


7.1
7.5
5.5
7.4

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 columnby-column convention contrasts with the row-by-row 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]:

Space dimension number 1 -->


1
2
5
6
9

3
7

4
8

TROLL Command: do prt.( reshape( m, 3, 3 ) ) ;


RESHAPE(M,3,3):
Numeric array -2 space dimensions: 3 by 3

[1,1]:
[2,1]:
[3,1]:

Space dimension number 2 -->


1
4
2
5
3
6

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 4-element year-by-year 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.)

TROLL Command: do usanx=reshape(c.(-74.3,-60.3,-78.5,-72,-32.9,-12.3,-22,-14.8,


Continue eq: -8.9,-29.0,-37.6,-42.7,-47.4,-62,-77.1,-73.2,-80.3,-97.4,-108.4,
Continue eq: -99.7,-106.6,-122.4,-100.6),1990a,4);
TROLL Command: do prt.(usanx);
USANX:
USANX = RESHAPE(C.(-74.3,-60.3,-78.5,-72,-32.9,-12.3,-22,-14.8,-8.9,-29,-37.6,-4
2.7,-47.4,-62,-77.1,-73.2,-80.3,-97.4,-108.4,-99.7,-106.6,-122.4,-100.6),1990
A,4)
Numeric array timeseries -Time dimension: Periodicity 1,
1 space dimension: 4

1990A
1994A
1990A
1994A
1990A
1994A
1990A
1994A

[1]:
[1]:
[2]:
[2]:
[3]:
[3]:
[4]:
[4]:

1990A to 1995A

Time dimension -->


-74.3
-32.9
-80.3
-106.6
-60.3
-12.3
-97.4
-122.4
-78.5
-22
-108.4
-100.6
-72
-14.8
-99.7
NA

(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

:
:
:
:
:
:

Time dimension -->


-74.3
-32.9
-8.9
-47.4
-80.3
-106.6

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

Just to clean up for the next examples:


TROLL Command: delaccess all; delsave all;

IV. IMPORTING DATA


For some strange reason, the world still produces a lot of data in formats that are not native to TROLL. It may therefore be
necessary for you to import data into TROLL. There are several ways to do this. If you need to import data from a program that
does not use one of TROLL's database formats, it is usually best to export the data in either a text format or a spreadsheet
format. The specifics will be discussed later in this section. First, however, note that some popular formats can be used directly
by TROLL. (The LKDBTYPE command will list the database formats available directly to TROLL.)

A. DATA FORMATS THAT TROLL USES DIRECTLY


1. FAME
You need a special version of TROLL to use FAME data. If your installation has that version, you can access
FAME data by using the ACCESS statement with "type fame". LKDBTYPE will list the available database types, so
you can check whether "FAME" is one of them.

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.

1. Using Troll's FORMDATA Text Format


TROLL's native FORMDATA format is a text format. Sometimes you can take external text data and format it as a
FORMDATA database, so that TROLL can access the data using its standard database access methods.
A FORMDATA database consists of a series of one or more FORMDATA objects. Each object begins on a new line and
occupies two or more lines. (There are no blank lines between objects.)
FORMDATA objects can have either one of two different formats, OLDFORMAT and NEWFORMAT. OLDFORMAT is the
default when TROLL writes FORMDATA files, but it is used primarily for backward-compatibility. NEWFORMAT
(available starting with Portable TROLL 1.2) is more versatile and convenient for data import.

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:

datatype startdate ndims nvals nobs clines

(This is NOT a valid header line, just a syntax description.) For the most part, the field names should be
self-explanatory: 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 3-by-2 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
line-breaks among the data, are arbitrary: TROLL will read the data in order, going through each
observation column-by-column 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"

TROLL Command: search matts ;


TROLL Command: do prt.( object_name ) ;
OBJECT_NAME:
Numeric array timeseries -Time dimension: Periodicity 1,
2 space dimensions: 3 by 2

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]:

1960A to 1963A (4 observations)

Space dimension number 2 -->


1
4
2
5
3
6
7
10
8
11
9
12
13
16
14
17
15
18
19
22
20
23
21
24

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"

TROLL Command: search that;


TROLL Command: do prt.(object_name);
OBJECT_NAME:
Numeric scalar timeseries -Time dimension: Periodicity 4,

1990Q2 to 1993Q1

Time dimension -->


1990Q2 :
1.2
2.33476
1991Q2 :
9
9
1992Q2 :
1
1.00000000e-005

(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

And here's how TROLL interprets it:


TROLL Command: access this type formdata id example.frm;
TROLL Command: do prt.(dflist("this"));
DFLIST("this"):
String array -1 space dimension: 2

[1]:

Space dimension number 1 -->


"UNEMP" "USANX"

TROLL Command: search this;


TROLL Command: do prt.(usanx,unemp);
USANX:
Except for this comment, this series is the same USANX
that we entered earlier using COMBINE and RESHAPE

Numeric scalar timeseries -Time dimension: Periodicity 4,

1990Q1
1991Q1
1992Q1
1993Q1
1994Q1
1995Q1

Time dimension -->


:
-74.3
:
-32.9
:
-8.9
:
-47.4
:
-80.3
:
-106.6

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

Time dimension -->


:
7.1
:
7.5
:
5.5
:
7.4

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

2. Reading Columns of Data


TROLL includes a "sample" macro called &READXMAT (i.e., "READ eXternal MATrix") designed to read data in
regular columns within a host system text file.
reads an external file containing a matrix consisting of columns of numbers headed by a row of
variable names; if the first column is labeled "YEAR", then the second element in the first column (which must
be an integer, not a date) will provide the startdate. No empty lines are allowed., and &READXMAT cannot read
numbers containing commas. Here is an example of a file ("govspend.asc") that &READXMAT can read very easily:
&READXMAT

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

To read these data into TROLL:


TROLL Command: &readxmat govspend.asc;
TROLL Command: listsave;
SAVE Database:
DEFENSE
OTHRFED
STATLOC

----

Numeric scalar timeseries


Numeric scalar timeseries
Numeric scalar timeseries

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

TROLL Command: search save_qnip;


TROLL Command: do prt.(rfi);
RFI:
Numeric scalar timeseries -Time dimension: Periodicity 4,

1993Q1
1994Q1
1995Q1
1996Q1

Time dimension -->


:
237.9
:
263.6
:
265.9
:
271.1

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]:

Space dimension number 1 -->


237.9
234.8
263.6
271.6
265.9
256.5
271.1
281.5

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]:

Space dimension number 1 -->


405.5
401.6
375.8
355.4

401.5
337

397.5
319.6

TROLL Command: do prt.(year);


YEAR:
Numeric array -1 space dimension: 8

[1]:
[5]:

Space dimension number 1 -->


1988
1989
1992
1993

1990
1994

1991
1995

3. Reading Arbitrary Data Formats


Usually if you want to import data into TROLL, it is best to reformat the data into a format that TROLL

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 end-users.
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 line-by-line and letter-by-letter
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

Open the file and read the first line:


TROLL Command: do debtptr = hfopen("debt.doc","r");
TROLL Command: do line1 = hfgets(debtptr);
TROLL Command: do prt.(line1);
LINE1:
String scalar:

//Open in text read mode

"Net Government Debt\n"

(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]:

Space dimension number 1 -->


85
83

65

Convert them to a character string:


TROLL Command: do prt.(code2str(nextchars));
CODE2STR(NEXTCHARS):
String scalar: "USA"

Read the rest of the line:


TROLL Command: do restofline=hfgets(debtptr);
TROLL Command: do prt.(restofline);
RESTOFLINE:
String scalar:

" 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

TROLL Command: do startqtr = convert(code2str(hfgetc(debtptr,4)));


TROLL Command: do prt.(startqtr);
STARTQTR:
Numeric scalar:

Read the data value and convert it to a number:


TROLL Command: do restofline = hfgets(debtptr);
TROLL Command: do prt.(restofline);
RESTOFLINE:
String scalar:

"

851.1\n"

TROLL Command: do numberpart = substr(restofline,1,length(restofline)-1);


TROLL Command: do prt.(numberpart);
NUMBERPART:
String scalar:

"

851.1"

TROLL Command: do obs1 = convert(numberpart);


TROLL Command: do prt.(obs1);
OBS1:
Numeric scalar:

851.1

Read the second data point from the next line:


TROLL
TROLL
TROLL
TROLL

Command:
Command:
Command:
Command:

do
do
do
do

hfgetc(debtptr,9); // Skip the year and quarter


restofline = hfgets(debtptr);
obs2 = convert(substr(restofline,1,length(restofline)-1));
prt.(obs2);

OBS2:
Numeric scalar:

875.4

Begin putting the data series together:


TROLL Command: do datavals = combine(obs1,obs2);

Read and attach the next data point:


TROLL Command: do hfgetc(debtptr,9); // Skip the year and quarter
TROLL Command: do restofline = hfgets(debtptr);

TROLL Command: do r = restofline;


TROLL Command: do datavals = c.(datavals,convert(substr(r,1,length(r)-1)));
TROLL Command: do prt.(datavals);
DATAVALS:
DATAVALS = C.(DATAVALS,CONVERT(SUBSTR(R,1,LENGTH(R)-1)))
Numeric array -1 space dimension: 3

[1]:

Space dimension number 1 -->


851.1
875.4

929.5

Continue reading data and attaching data points:


TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL

Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:
Command:

do
do
do
do
do
do
do
do
do
do
do
do

hfgetc(debtptr,9); // Skip the year and quarter


r = hfgets(debtptr);
datavals = c.(datavals,convert(substr(r,1,length(r)-1)));
hfgetc(debtptr,9);
r = hfgets(debtptr);
datavals = c.(datavals,convert(substr(r,1,length(r)-1)));
hfgetc(debtptr,9);
r = hfgets(debtptr);
datavals = c.(datavals,convert(substr(r,1,length(r)-1)));
hfgetc(debtptr,9);
r = hfgets(debtptr);
datavals = c.(datavals,convert(substr(r,1,length(r)-1)));

...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);

Convert the data array to a timeseries:


TROLL Command: do debt = reshape(datavals,stdate);
TROLL Command: do prt.(debt);
DEBT:
DEBT = RESHAPE(DATAVALS,STDATE)
Numeric scalar timeseries -Time dimension: Periodicity 4,
Time dimension -->
1982Q1 :
851.1
1983Q1 :
1035.7

1982Q1 to 1983Q3

875.4
1098.4

929.5
1142.8

(7 observations)

983.5

Don't forget to clean up:


TROLL Command: do prt.(hfolist());
HFOLIST():
String array -2 space dimensions: 1 by 3

[1,1]:

Space dimension number 2 -->


"_fp_5278c8" "debt.doc"
"r"

TROLL Command: do hfclose(debtptr);


TROLL Command: do prt.(hfolist());
HFOLIST():
String array -2 space dimensions: 0 by 3
Space dimension number 2 -->

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.

1. Time Series: the &WKS2TS Macro


The "sample" macro &WKS2TS, which ships with TROLL, allows a user to read time series data from a
spreadsheet file. &WKS2TS can serve as a starting point if you want to create a macro for your own spreadsheet
files. To use &WKS2TS without revising it first, you must arrange your spreadsheet data in a table (as described
below) and save the spreadsheet in a standard PC format that uses the ".wk1", ".wks", ".wrk", or ".wr1" file
extension. (These formats are native to early versions of Lotus 1-2-3, but all popular PC spreadsheet programs
offer an option to save in one of these formats.)
A spreadsheet for importation via &WKS2TS should be arranged as follows:
The spreadsheet should consist of a single page containing the data. (Most spreadsheet programs will
allow you to save one page of a multi-page spreadsheet in the required format.)
The upper left corner cell (usually cell "A1") may be empty or may contain irrelevant information.
The rest of the first column should consist of a series of consecutive dates in standard TROLL format
(e.g., "1950Q1" in cell A2, "1950Q2" in cell A3, and so on). In practice, only the first date (in cell A2) is
necessary; the rest will be assumed.
Each subsequent column should contain a data series, with its name in the row 1 cell and the data in the
remaining cells.
Series names should be in capital letters.
Here is an example:

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;

TROLL Command: listsave;


SAVE Database:
CPI
UE

---

Numeric scalar timeseries


Numeric scalar timeseries

TROLL Command: do prt.(ue,cpi);


UE:
Numeric scalar timeseries -Time dimension: Periodicity 12,
Time dimension -->
1992M01:
7.1
1992M05:
7.4
1992M09:
7.5
1993M01:
7.1
1993M05:
6.9

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

1992M01 to 1993M06 (18 observations)

7.3
7.6
7.3
7

7.3
7.6
7.3
7

1992M01 to 1993M06 (18 observations)

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.

2. Generic Matrices: the WKS2MAT Function


&WKS2TS is very useful but also quite limiting: the inputs must be time series, must have the same periodicity,
must cover the same time periods, and must be arranged in the correct format. TROLL has a function called
WKS2MAT which will read an arbitrary matrix from any part of a spreadsheet file (".wk1", ".wks", ".wrk", or
".wr1"). After reading a matrix from a spreadsheet file, you can process the elements of the matrix as you wish.
Alternatively, you can read multiple data series as separate matrices.

Consider the following spreadsheet:

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

104.8 103.5 100.1 107.0 112.0 111.8

95.9

92.4

90.3

95.0

107.3

100.3 100.7 95.7

11

Appraisal of Present Situation: Percent

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

Jobs not so plentiful

52.4

54.8

51.3

55.6

52.4

51.8

51.1

51.1

53.2

52.2

19

Jobs hard to get

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]:

Space dimension number 2 -->


88.405725
98.001819
103.538385
100.067504
111.813456
107.284535
101.093095
110.800497
120.232788
114.713365
128.533105
124.630621
79.947478
89.469367
92.408783
90.303597
100.667023
95.720478

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]:

Space dimension number 2 -->


21
22.3
25.7
23.1
27
27.2
21.9
18.5
17.4
19
16
15.8
57.1
59.2
56.9
57.9
57
57

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]:

Space dimension number 2 -->


21.3
21.8
24.8
24.6
26.4
25.4
52.4
54.8
52.4
51.8

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]:

Time dimension -->


88.405725
103.538385
111.813456
101.093095
120.232788
128.533105
79.947478
92.408783
100.667023

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]:

Time dimension -->


21
25.7
27
21.9
17.4
16
57.1
56.9
57

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]:

Time dimension -->


21.3
24.8
26.4
52.4
52.4
53.2
26.3
22.8
20.4

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,

Time dimension -->


1996M01:
100
1996M05:
100
1996M09:
100

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

TROLL Command: do ccisum = sum(i=1 to 3: ccindex[i]);


TROLL Command: do prt.(ccisum);
CCISUM:
CCISUM = SUM(I = 1 TO 3: CCINDEX[I])
Numeric scalar timeseries -Time dimension: Periodicity 12,
Time dimension -->
1996M01:
269.446297
1996M05:
316.179957
1996M09:
341.013583

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:

TROLL Command: do months=wks2mat("confiden.wks","b3..k3","STR");


TROLL Command: do prt.(months);
MONTHS:
MONTHS = WKS2MAT("confiden.wks","b3..k3","STR")
String array -2 space dimensions: 1 by 10

[1,1]:
[1,8]:

Space dimension number 2 -->


" Jan."
" Feb."
" Mar."
" Apr."
" Aug."
" Sept." " Oct."

" 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.

5. What About UNIX?


TROLL has no native support for any spreadsheet formats designed for use in UNIX environments. The best
solution is probably to save your data in a text format and import them using one of the methods described
earlier. Note also that there are certain difficulties associated with transporting data from UNIX systems to PCs
and vice versa. There problems are discussed later in the section on USING TROLL DATA FILES, under the
subheading MOVING TROLL DATA BETWEEN PLATFORMS

D. ARBITRARY BINARY DATA


Lasciate ogne speranza, voi ch'intrate. TROLL can read binary data, but only advanced users should attempt to use
TROLL in this way. If you want to try, you might start by reading the earlier section on "Reading Arbitrary Data
Formats" under "TEXT DATA". For binary data, you will want to open files with mode "rb" instead of "r", and you will
have to read byte-by-byte. As a very brief example, the following sequence reads from a file containing 4-byte integers
stored using the "little-endian" (least significant byte first) convention. The example reads one integer, skips a second,
and then reads a third:
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL

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:

V. USING TROLL DATA FILES


A. DATA FILE FORMATS
1. FORMDATA
FORMDATA

files are human-readable 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 human-readable. 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 site-specific support for other database types.

B. MOVING TROLL DATA BETWEEN PLATFORMS


Because of differences in the way data are represented in different computer architectures, some databases cannot be
transparently moved from UNIX platforms to PC platforms and vice versa. In particular, TROLLDB data are not portable
between PC platforms and typical UNIX platforms. Both FORMDATA and TESTBIN1 databases are portable. TESTBIN1 is
usually preferable because it is more compact.

VI. EXPORTING DATA


Exporting data from TROLL is very much like importing data, except that the process is reversed. The methods are analogous:
You can write AREMOS, TSP, or FAME data in a format that the receiving program will understand directly, if you
have the appropriate version of TROLL (see "DATA FORMATS THAT TROLL USES DIRECTLY" under
"IMPORTING DATA").
You can write data in TROLL's FORMDATA text format (described under Using TROLL's FORMDATA Text Format in the
section on Importing TEXT DATA) and read it using a program that can read formatted text.
You can write a string array to a host system file using the XWRITE function.
You can use TROLL's formatted text capabilities to write data to host system files in a format that can be read by
another program. The functions HFOPEN, HFCLOSE, HFOGETFP, HFOLIST, HFSEEK, and HFTELL, described earlier, are useful
for this purpose. In addition, you will probably want to use HFPRINTF, HFPUTC, and/or HFPUTS, which, like the other
functions, are described in the Function Reference Manual.
You can write data to spreadsheets directly using the function MAT2WKS and the macro &TS2WKS, which behave
analogously to their counterparts described earlier. The MAT2WKS function is described in the Function Reference Manual,
and the &TS2WKS macro is described in the MACROS.TXT file that ships with TROLL.
The general difference between importing and exporting data is that export databases must be writable. And if you use the
SEARCH list to access those databases, they must be write-SEARCHable.

VII. OTHER DATA ISSUES


A. CAPITALIZATION: WHEN IT MATTERS AND WHEN IT DOESN'T
Sometimes capitalization matters, and sometimes it doesn't. Usually, when you use lower case letters in a command line,
TROLL will convert them to capitals as necessary. GETDATA and PUTDATA are important exceptions. Because GETDATA and
PUTDATA can be used to access external databases that are case-sensitive, these functions must preserve case. If you
create data objects using an ordinary TROLL command (such as a calculation in a DO command) and then attempt to
retrieve them using GETDATA, you must capitalize the argument to GETDATA (even if you created the data objects using
lower case letters). The following example demonstrates:
TROLL Command: do this=1; //TROLL converts "this" to "THIS"
TROLL Command: do thisvalue=getdata("this"); //"this" does not exist
WARNING 2222
Evaluating error.
Data file 'this' not found.

TROLL Command: do thisvalue=getdata("THIS");


TROLL Command: do prt.(thisvalue);
THISVALUE:
Numeric scalar:

TROLL Command: do prt.(this);


THIS:
Numeric scalar:

//but "THIS" exists

//TROLL converts "this" to "THIS"

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:

access temp type trolldb mode w id temp.trl ;


do temp_x = 1 ;
do dflist( "temp", "x" ) ;
do prt.( dflist( "temp", "x" ) ) ;

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

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter Four. Automating TROLL Tasks


I. USING INPUT FILES
A. INPUT FILES
B. PROFILE FILES
C. LOG FILES

II. A QUICK INTRODUCTION TO MACRO PROGRAMMING

Portable TROLL User's Guide

Chapter Four. Automating TROLL Tasks


Thus far, this Guide has discussed interactive TROLL. Although interaction is useful when you need quick feedback, some interactive
tasks can become repetitive. TROLL provides several tools for automating interactive tasks.

I. USING INPUT FILES


A. INPUT FILES
The most basic automation tool is the input file. An input file is simply a file containing a sequence of TROLL
commands, exactly as you would have entered them at the keyboard. Normally TROLL input files are identified by the
extension ".inp".
There are several ways to use input files. First, from within a TROLL session, you can use the troll command INPUT to
execute the contents of an input file. Second, when you invoke TROLL from the host system, you can execute an input
file by supplying the input file name as a command line argument. Finally, you can provide a file named profile.inp,
which will be executed automatically whenever you start a TROLL session. The following paragraphs give examples of
these methods.
Consider the "advanced estimation" example from Chapter One. The commands for that example could be typed into a
file (using any standard text editor, such as Windows "Notepad" or UNIX "ex"). If we give the file a name with the
".inp" extension, it becomes a TROLL input file. The following example begins at a Windows NT command prompt
with a file that was created by Notepad. (In a UNIX environment, you could use "cat" in place of "type" and "mv" in
place of "rename".)
C:\troll>type eg2.txt
access nipa type formdata id c:\usanipa.frm;
search first nipa;
do exdemand=gdp-invest-cons;
usemod;
addsym endogenous cons invest;
addsym exogenous exdemand;
addsym coefficient a0 a1 b0 b1;
addeq bottom cons=a0+a1*(exdemand+invest);
addeq bottom invest=b0+b1*(exdemand+cons);
print;
bounds 1969a to 1995a;
conopt stop 100;
olsmod all;
savecoef;
fiml;
outlvl int 1;

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. 1993-1998
Copyright (C) Massachusetts Institute of Technology 1978-1987

TROLL Command: input eg2;


TROLL Command: access nipa type formdata id c:\usanipa.frm;
TROLL Command: search first nipa;
TROLL Command: do exdemand=gdp-invest-cons;
TROLL Command: usemod;
New model: (nameless)
TROLL Command: addsym endogenous cons invest;
MODEDIT Command: addsym exogenous exdemand;
MODEDIT Command: addsym coefficient a0 a1 b0 b1;
MODEDIT Command: addeq bottom cons=a0+a1*(exdemand+invest);
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)

MODEDIT Command: bounds 1969a to 1995a;


MODEDIT Command: conopt stop 100;
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

ORDINARY LEAST SQUARES


2 :

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

OLSMOD Command: savecoef;


OLSMOD Command: fiml;
...ANALYSING MODEL
...GENERATING CODE
FIML Command: outlvl int 1;
FIML Command: estimate;
FIML estimation Begins
*** Standard algorithm ***
MODEL: CURRENT NOB: 27 NOVAR: 4
RANGE: 1969A to 1995A

PROB>|T|

3.392959
7.165006

0.002307
0

NEQ: 2

Optimization algorithm: Davidon-Fletcher-Powell


RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
Beginning Linear-Jacobian Iterations
Convergence OBTAINED in 35 iterations, 74 FCN evaluations, FCN=
18.684354
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
Total Iters: 35 Fevals: 74 Final FCN:
18.684354 LOG-LIKE:
-328.861465
VALUE
A0
A1
B0
B1

-1658.948879
2.896423
286.031144
0.109593

STD ERR
210.524031
0.140305
66.267126
0.018721

Single Equation Statistics


RSQ
Eqn 1
Eqn 2

CRSQ

0.945342
0.656757

SSR

0.943155
0.643027

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

569604.260897
125154.572678

SER
150.944263
70.754384

NEQ: 2

Optimization algorithm: Davidon-Fletcher-Powell


RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
Convergence OBTAINED in 6 iterations, 11 FCN evaluations, FCN=3.94638259e-013
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 6 Fevals: 11 Final FCN: 3.94638259e-013
VALUE
A0
A1
B0
B1

-1658.948879
2.896423
286.031144
0.109593

FEVALMAX: 500

STD ERR
1.449408
0.000966
0.973607
0.000275

Single Equation Statistics


RSQ
Eqn 1
Eqn 2

0.945342
0.656757

CRSQ

SSR

0.943155
0.643027

3 Stage estimation begins...


MODEL: CURRENT NOB: 27 NOVAR: 4
RANGE: 1969A to 1995A

569604.260883
125154.572648

NEQ: 2

SER
150.944263
70.754384

Optimization algorithm: Davidon-Fletcher-Powell


RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
Convergence OBTAINED in 4 iterations, 8 FCN evaluations, FCN=-1.4027637e-016
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 4 Fevals: 8 Final FCN: -1.4027637e-016
VALUE
A0
A1
B0
B1

-1658.948879
2.896423
286.031144
0.109593

FEVALMAX: 500

STD ERR
210.520997
0.140302
66.286481
0.018728

Single Equation Statistics


RSQ
Eqn 1
Eqn 2

CRSQ

0.945342
0.656757

0.943155
0.643027

SSR
569604.260883
125154.572648

SER
150.944263
70.754384

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: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
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: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 5 Fevals: 10 Final FCN:
671494.936704 LOG-LIKE:
VALUE
A0
A1
B0
B1

-1484.786935
2.779316
217.329789
0.129394

FEVALMAX: 500
-317.453518

STD ERR
1.329736
0.000885
0.926801
0.000261

Single Equation Statistics


RSQ
Eqn 1
Eqn 2

0.947023
0.672506

CRSQ
0.944904
0.659406

SSR
552082.842861
119412.093844

SER
148.604555
69.11211

3 Stage estimation begins...


Seemingly unrelated equations (ZELLNER) case
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100 FEVALMAX: 500
Convergence OBTAINED in 7 iterations, 14 FCN evaluations, FCN=
53.103855
MODEL: CURRENT NOB: 27 NOVAR: 4 NEQ: 2
RANGE: 1969A to 1995A
Optimization algorithm: Davidon-Fletcher-Powell
RADIUS:
1
CONCR:
0.001
Iter limit: 100
Total Iters: 7 Fevals: 14 Final FCN:
53.103855 LOG-LIKE:
VALUE
A0
A1
B0
B1

-1537.085898
2.814482
184.572979
0.138835

STD ERR
187.189308
0.124499
60.698883
0.017101

FEVALMAX: 500
-316.981119

Single Equation Statistics


RSQ
Eqn 1
Eqn 2

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 forward-looking 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. 1993-1998
Copyright (C) Massachusetts Institute of Technology 1978-1987
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

:
:
:
:
:
:

Time dimension -->


0.322728
0.481454
0.718245
1.071496
1.598484
2.384658

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

MODEDIT Command: simulate stack 20;


Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Constructing stacked-time incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
SIMULATE Command: list solutions y;
SIMULATE Command: simstart 1a; dotil 20a;
Date:
What:
Value:
1A
Solution: Y [1A]
1.761881
[2A]
1.947181
[3A]
2.15197
[4A]
2.378299
[5A]
2.628438
[6A]
2.904898
[7A]
3.210463
[8A]
3.548234
[9A]
3.921682
[10A]
4.334754
[11A]
4.792048
[12A]
5.299193
[13A]
5.863624
[14A]
6.496306
[15A]
7.215526
[16A]
8.055384
[17A]
9.084814
[18A]
10.450307
[19A]
12.471954
[20A]
15.859444
SIMULATE Command:

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:

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;
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

TROLL Command: lksearch;


Current SEARCH list:
Name
---SAVE
MYDATA
.
MYDIR
TROLLSYS

W?
-W
W
W

TROLL Command: trexit ;

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. 1993-1998
Copyright (C) Massachusetts Institute of Technology 1978-1987
TROLL
TROLL
TROLL
TROLL
TROLL
TROLL

Command:
Command:
Command:
Command:
Command:
Command:

access
search
access
search

mydata type formdata mode w id c:\troll\mydir\mydata.frm;


after save mydata w;
mydir type disk mode w id c:\troll\mydir;
before trollsys mydir;

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

TROLL Command: lksearch;


Current SEARCH list:
Name
---SAVE
MYDATA
.
MYDIR
TROLLSYS

W?
-W
W
W

Filetype
-------DATA
DATA
NONDATA
ALL
NONDATA

Basic?
-----BASIC
BASIC
BASIC

TROLL Command:

There it is, all set up and ready to do your bidding.

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. 1993-1998
Copyright (C) Massachusetts Institute of Technology 1978-1987
TROLL
TROLL
TROLL
TROLL
TROLL

Command:
Command:
Command:
Command:
Command:

access
search
access
search
trexit

mydata type formdata mode w id c:\troll\mydir\mydata.frm;


after save mydata w;
mydir type disk mode w id c:\troll\mydir;
before trollsys mydir;
;

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"

option, invoked with the "SYSOPT"

search after save mydata w;


access mydir type disk mode w id c:\troll\mydir;
search before trollsys mydir;
C:\troll>troll
TROLL Release 1.042
Copyright (C) Intex Solutions, Inc. 1993-1998
Copyright (C) Massachusetts Institute of Technology 1978-1987
TROLL Command: sysopt screen off;
TROLL Command:

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

TROLL Command: lksearch;


Current SEARCH list:
Name
---SAVE
MYDATA
.
MYDIR
TROLLSYS

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 over-writes 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 over-write the old log file. Instead, it will append the new log to the end of the old
one.
TROLL Command: trexit ;

II. A QUICK INTRODUCTION TO MACRO PROGRAMMING


Input files are useful, but they have obvious limitations. For example, what if you have a sequence of TROLL commands that
you want to run several times using different data files? To do that using input files alone, you would have to edit the input file
after each run and change the name of the data file. Or what if you wanted to repeat the same sequence of commands several
times with different parameter values? Again, you could do it with input files, but not conveniently. And here's an even bigger
problem: what if you needed the result of the first run to determine the parameter values for the second run? You could look at

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 human-readable,
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
greater-than 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 greater-than signs on each
line. The spaces will not affect TROLL's interpretation.) In TROLL macro terminology, a line beginning with two greater-than
signs is called a "queue-input 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 queue-input 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 open-curly-brace ("{") 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 close-curly-brace ("}"). 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. 1993-1998
Copyright (C) Massachusetts Institute of Technology 1978-1987
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 ready-to-run 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

Time dimension -->


:
0.322728
:
0.481454
:
0.718245
:
1.071496
:
1.598484
:
2.384658

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

Analyzing Model's Incidence Matrix


Analyzing Model's Block Structure
Constructing stacked-time incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
Date:
What:
Value:
1A
Solution: Y [1A]
1.761881
[2A]
1.947181
[3A]
2.15197
[4A]
2.378299
[5A]
2.628438
[6A]
2.904898
[7A]
3.210463
[8A]
3.548234
[9A]
3.921682
[10A]
4.334754
[11A]
4.792048

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:

Voil. So much for the basic syntax differences.


There would not be much point in writing macros if they were simply input files with different syntax. (There might be some
point -- for example, if you want to share an input file without making the contents visible, you could convert it to a macro and
share only the .prg object file.) To realize the power of macros, you must learn how to exploit the other differences. The most
important is the ability to take arguments.
When you write a macro, you need to specify how it will obtain argument values from the user. The simplest way to do this is
with the GET statement, which consists of "get" followed by the name of the argument, for example:
get mpc;

// Get "marginal propensity to consume" from user

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;

// Simple consumption function

This statement corresponds to the following statement from flkeynes.src:


>>addeq bottom c=.8*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

Time dimension -->


:
0.322728
:
0.481454
:
0.718245
:
1.071496
:
1.598484
:
2.384658

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

Analyzing Model's Incidence Matrix


Analyzing Model's Block Structure
Constructing stacked-time incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
Date:
What:
Value:
1A
Solution: Y [1A]
1.761881
[2A]
1.947181
[3A]
2.15197
[4A]
2.378299
[5A]
2.628438
[6A]
2.904898
[7A]
3.210463
[8A]
3.548234
[9A]
3.921682
[10A]
4.334754
[11A]
4.792048
[12A]
5.299193
[13A]
5.863624
[14A]
6.496306
[15A]
7.215526
[16A]
8.055384
[17A]
9.084814
[18A]
10.450307
[19A]
12.471954
[20A]
15.859444
SIMULATE Command: &flusempc .99;
New model: (nameless)
Symbols:
ENDOGENOUS :
C Y YPERM
EXOGENOUS :
I
Equations:
1:
2:
3:

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

Time dimension -->


:
0.322728
:
0.481454
:
0.718245
:
1.071496
:
1.598484
:
2.384658

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

Analyzing Model's Incidence Matrix


Analyzing Model's Block Structure
Constructing stacked-time incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
Date:
What:
Value:
1A
Solution: Y [1A]
60.709405
[2A]
62.145595
[3A]
63.482898
[4A]
64.698291
[5A]
65.765691
[6A]
66.655604
[7A]
67.33473
[8A]
67.765528
[9A]
67.905731
[10A]
67.707813
[11A]
67.118392
[12A]
66.07757
[13A]
64.518208
[14A]
62.365108
[15A]
59.534124
[16A]
55.931161
[17A]
51.451078
[18A]
45.976467
[19A]
39.376299
[20A]
31.504432
SIMULATE Command: &flusempc .5;
New model: (nameless)
Symbols:
ENDOGENOUS :
C Y YPERM
EXOGENOUS :
I
Equations:
1:
2:
3:

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

Time dimension -->


:
0.322728
:
0.481454
:
0.718245
:
1.071496
:
1.598484
:
2.384658

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

Analyzing Model's Incidence Matrix


Analyzing Model's Block Structure
Constructing stacked-time incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
Date:
What:
Value:
1A
Solution: Y [1A]
0.659325
[2A]
0.728667
[3A]
0.805301
[4A]
0.889996
[5A]
0.983597
[6A]
1.087043
[7A]
1.201369
[8A]
1.327718
[9A]
1.467355
[10A]
1.621678
[11A]
1.792231
[12A]
1.980724
[13A]
2.189046
[14A]
2.419321
[15A]
2.674066
[16A]
2.957118
[17A]
3.279027
[18A]
3.689324
[19A]
4.469966
[20A]
7.295871

0.435638
0.649895
0.969529
1.446368
2.157728

I never said the model was realistic...


Finally, let's add some logic. The details of macro logic are covered in the Portable TROLL Programming Language manual.
Here we'll just look at an example of the two most fundamental logical structures -- loops and conditionals.
Suppose you wanted to investigate the effect of different stack parameters on the simulation algorithm. The following macro,
"FLSTACKS", repeats the simulation in FLUSEMPC for all possible stack parameters and reports the results:
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);
// Loop through stack sizes
for (nstack=2; nstack<21; nstack=nstack+1)
begin; // start loop block
// Number of periods must be a multiple of stack size
modv = modulo (20, nstack) ;
if ( modv == 0 ) then
begin; // begin "if" block
>>simulate stack &nstack;
>>list solutions y;
>>simstart 1a; dotil 20a;
end;
// end "if" block
else
begin; // begin "else" block
print(" Ignoring nstack = ", nstack, ": modulus is ", modv);
end;
// end "else" block
end;
// end loop block
end;

This macro follows FLUSEMPC word-for-word 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 "if-then-else" 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 queue-input 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 queue-input 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 queue-input
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;

TROLL Compiler: Rel. 1.0


END OF COMPILATION
ERRORS:
0
WARNINGS: 0
TROLL Command: &flstacks .7;
New model: (nameless)
Symbols:
ENDOGENOUS :
C Y YPERM
EXOGENOUS :
I
Equations:
1:
2:
3:

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

Time dimension -->


:
0.322728
:
0.481454
:
0.718245
:
1.071496
:
1.598484
:
2.384658

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

Analyzing Model's Incidence Matrix


Analyzing Model's Block Structure
Constructing stacked-time incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
Date:
What:
Value:
1A
Solution: Y [1A]
1.362874
[2A]
1.978117
3A
Solution: Y [3A]
1.664618
[4A]
2.416078
5A
Solution: Y [5A]
2.03317
[6A]
2.951004
7A
Solution: Y [7A]
2.483319
[8A]
3.604364
9A
Solution: Y [9A]
3.033133
[10A]
4.40238
11A
Solution: Y [11A]
3.704677
[12A]
5.37708
13A
Solution: Y [13A]
4.524902
[14A]
6.56758
15A
Solution: Y [15A]
5.526728
[16A]
8.02166
17A
Solution: Y [17A]
6.750361
[18A]
9.797678
19A
Solution: Y [19A]
8.244909
[20A]
11.966911
Ignoring nstack = 3: modulus is 2
Constructing stacked-time incidence matrix and code.
Simulations can start from 1A to 20A and must end by 20A.
Date:
What:
Value:
1A
Solution: Y [1A]
1.159921
[2A]
1.340265
[3A]
1.664618
[4A]
2.416078
5A
Solution: Y [5A]
1.730399
[6A]
1.99944
[7A]
2.483319
[8A]
3.604364
9A
Solution: Y [9A]
2.581453
[10A]
2.982814
[11A]
3.704677
[12A]
5.37708
13A
Solution: Y [13A]
3.851075
[14A]
4.449836
[15A]
5.526728
[16A]
8.02166

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 stacked-time 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 stacked-time 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 stacked-time 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

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter Five. Manipulating Data in Portable


TROLL
I. DATA TYPES AND SHAPES
A. MIXING DATA TYPES
B. MIXING DATA SHAPES

II. DO COMMANDS
III. THE TROLL MODELLING LANGUAGE
IV. BUILT-IN FUNCTIONS

Portable TROLL User's Guide

Chapter Five. Manipulating Data in Portable


TROLL
I. DATA TYPES AND SHAPES
Data objects in Portable TROLL are characterized by "type" and "shape". "Type" (or "datatype") refers to the kind of data that
an object contains -- numeric, date, string (character), boolean (true/false), or NA (unknown type). (Note that objects not of the
NA type can still have the value NA -- meaning that the type is known but the value is unknown.) "Shape" (or "data shape")
refers to the dimensionality of the data object -- whether it is a scalar, a matrix, a time series, or some combination, and how big
it is. Data shapes (and data types) are covered in some detail in Chapter Two.

A. MIXING DATA TYPES


TROLL generally discourages (and usually prohibits) mixing of data types in expressions, because of the potential for
confusion. Thus the following attempt to mix data types results in an error:
TROLL Command: do x = "1", y = 2, prt.( x || y ) ;
ERROR 2222
Evaluating error.
Incompatible datatypes for binary operator: (String) || (Numeric).

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 ) ) ;
X||CONVERT(Y):
String scalar:

"12"

TROLL Command: do prt.( convert( x ) + y ) ;


CONVERT(X)+Y:
Numeric scalar:

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+7-3:
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

B. MIXING DATA SHAPES


You can mix data shapes in an expression, provided that the shapes are "conformable". There are two requirements for
data objects to be conformable:
Any time dimensions that exist must have the same periodicity.
All active space dimensions (those with size > 1) must be the same size on one object as on another.
TROLL applies the following rules to conform the objects:
The date range of the result is the intersection of the date ranges (of any objects that have time dimensions).
If a time dimension is lacking or a space dimension has size 1, then the values are replicated along that
dimension (if necessary) to match the other objects.
The simplest case of "conforming arrays" is combining a scalar and a vector. In this case, the scalar is replicated along
the dimension of the vector:
TROLL Command: do scalar = 10, colvec = seq( 3 ) ;
TROLL Command: do prt.( scalar, colvec, scalar + colvec ) ;
SCALAR:
Numeric scalar:

10

COLVEC:
COLVEC = SEQ(3)
Numeric array -1 space dimension: 3

[1]:

Space dimension number 1 -->


1
2

SCALAR+COLVEC:
Numeric array -1 space dimension: 3

[1]:

Space dimension number 1 -->


11
12

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]:

Space dimension number 2 -->


1
2

TROLL Command: do prt.( 10 * rowvec + colvec ) ;


10*ROWVEC+COLVEC:
Numeric array -2 space dimensions: 3 by 4

[1,1]:
[2,1]:
[3,1]:

Space dimension number 2 -->


11
21
12
22
13
23

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]:

Space dimension number 2 -->


111
112
211
212
311
312

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:

Time dimension -->


1
5

CONSTANT+SERIES:
Numeric scalar timeseries -Time dimension: Periodicity 12,

2000M01:
2000M05:

Time dimension -->


11
15

2000M01 to 2000M05 (5 observations)

2000M01 to 2000M05 (5 observations)

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]:

2000M01 to 2000M05 (5 observations)

Space dimension number 2 -->


111
121
211
221
311
321
112
122

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:

Time dimension -->


1

2000M08 to 2000M10 (3 observations)

SERIES+SERIES2:
Numeric scalar timeseries -Time dimension: Periodicity 12,

2000M08 to 2000M07 (0 observations)

Time dimension -->

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:

Time dimension -->


1

1999A to 2002A (4 observations)

TROLL Command: do prt.( series + annual ) ;


ERROR 6000
Invalid argument(s) to a function.
Arguments to binary operator do not conform: periodicities do not match.

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 data-writable 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 multi-level 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 data-writable
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
data-writable 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 over-writing 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.

III. THE TROLL MODELLING LANGUAGE


The TROLL Modelling Language consists of the linguistic elements among those constructs described as the "elements of
TROLL" in Chapter Two. The "Modelling Language" is also a "calculation language": you can use TROLL Modelling
Language expressions in DO statements to manipulate data. The TROLL Modelling Language is described in the TROLL
Reference Manual.

IV. BUILT-IN FUNCTIONS


See the section on "Functions" in Chapter Two, and the TROLL Functions manual.

Commands
Functions
Programming

User's Guide

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter Six. Creating And Working With Models


I. MODEL SPECIFICATION
A. THE RAW MATERIAL: SYMBOLS AND SYMBOLTYPES
B. USING THE BASIC SYMBOLTYPES
1. EXOGENOUS, ENDOGENOUS, and COEFFICIENT Symbols
2. Declaring Symbols
3. Specifying Equations
4. Estimating and Simulating the Model
C. OTHER SYMBOLTYPES AND SPECIFICATION TECHNIQUES
1. Discretionary Input: PARAMETER Symbols
2. Changing Equations
3. Using a PARAMETER Symbol
4. Fancier Specifications: FUNCTION Symbols
5. Shock Variables: POLICY Symbols
6. Identity Equations and DEFINITION Symbols
D. SYMBOLTYPE SHORTCUTS: DEFAULTS AND SUFFIXES

II. MODEL FILES


A. THE "CURRENT" MODEL FILE AND THE MODEDIT BUFFER
B. MODEL FILE STRUCTURE
1. The Rudimentary Model File
2. Adding Useful Information
a. equation labels
i. creating labels
ii. changing symbols
iii. adding labels and changing equations
b. comments
i. model comments
ii. symbol comments
iii. equation comments

3. TROLL's Model Analysis Information


a. incidence matrix
b. block ordering
c. simulation code

4. The Complete Model File

III. USING MODELS


A. WHAT MODELS ARE FOR
B. GETTING INFORMATION
1. Specification Information
a. PRINT
b. PRTMOD

2. Analysis Information
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

Portable TROLL User's Guide

Chapter Six. Creating And Working With Models


I. MODEL SPECIFICATION
A. THE RAW MATERIAL: SYMBOLS AND SYMBOLTYPES
A model is a set of equations. Each equation represents a relationship among entities. Within an equation, each entity is
represented by a symbol.
In TROLL, the model specification process begins with symbols. Before a symbol can be used in an equation, it must
have a symboltype. Although you need not always declare symbols and their symboltypes explicitly, you can avoid
many problems by knowing the symboltypes of your symbols before using them.

B. USING THE BASIC SYMBOLTYPES


1. EXOGENOUS, ENDOGENOUS, and COEFFICIENT Symbols
The most important symboltypes in TROLL are EXOGENOUS (the default), ENDOGENOUS, and COEFFICIENT.
EXOGENOUS symbols represent values determined outside the model: TROLL does not alter those values when it
estimates or simulates the model. ENDOGENOUS symbols represent values determined "within the model", -- in
other words, determined by the process which the model represents. COEFFICIENT symbols represent fixed but
unknown values that determine the behavior of the model. When it estimates a model, TROLL generates values
("estimates") for the COEFFICIENT symbols; when it simulates a model, TROLL generates new values ("results")
for the ENDOGENOUS symbols. (The results of estimation and simulation aren't necessarily saved, so the data
objects represented by the symbols may retain their old values.)

2. Declaring Symbols
Before discussing other symboltypes, let us look at the mechanics of model specification. To start specifying a
model, invoke the model-editing 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
backward-looking real sector:
Real Sector:
Financial Sector:
Phillips Curve:
where

Y
r
G
p

=
=
=
=

Y = a0 - a1r-1 + a2r-2 + a3G


r = b0 + b1r-1 + b2p+1
p = c0 + c1p-1 + c2Y-1 + c3Y-2

change in per-capita real GDP


short-term nominal interest rate
change in real government purchases
inflation rate

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
position-specifier 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) ;

Here's what the model looks like to TROLL:


MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
P R Y
EXOGENOUS :
G
COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

C0

C1

C2

C3

Equations:
1:
2:
3:

Y = A0-A1*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)

4. Estimating and Simulating the Model


The following passage crudely estimates and simulates the model using US data.
MODEDIT Command: access us type trolldb id d:\troll\samples\work\usm6.trl ;
MODEDIT Command: search after save us ; // Point to the data
MODEDIT Command: olsmod all, 1973a to 1996a ; // Estimate

ORDINARY LEAST SQUARES


1 :

Y = A0-A1*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

ORDINARY LEAST SQUARES


2 :

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.55796154e-006
3.247981
0.003849

ORDINARY LEAST SQUARES


3 :

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

OLSMOD Command: savecoef ; // Store estimated coefficients for use in sim


OLSMOD Command: do g = setrep( g, 2, 1997a::2015a ) ; // dummy data for exog var
OLSMOD Command: simulate stack 20 ; // Start simulator for forward-looking
Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
Constructing stacked-time incidence matrix and code.
Simulations can start from 1972A to 2099A and must end by 2099A.
SIMULATE Command: list solutions all ; // to display results
SIMULATE Command: simstart 1996a ; // start date for simulation
SIMULATE Command: dotil 2015a ; // Run the simulation.
Date:
What:
Value:
1996A
Solution: G [1996A]
1.107259
[1997A]
2
[1998A]
2
[1999A]
2
[2000A]
2
[2001A]
2
[2002A]
2
[2003A]
2
[2004A]
2
[2005A]
2
[2006A]
2

[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

C. OTHER SYMBOLTYPES AND SPECIFICATION TECHNIQUES


1. Discretionary Input: PARAMETER Symbols
The example thus far has used ENDOGENOUS, EXOGENOUS, and COEFFICIENT symbols. These are the staples of the
standard estimate-and-simulate paradigm, which works fine as long as all the unknown constants are to be filled
in by empirical estimation. For situations where you want to fill in the unknown constants by other means -perhaps doing multiple trials with different ad hoc parameter values -- TROLL provides the symboltype
PARAMETER. Like a COEFFICIENT, a PARAMETER is "constant" (in the sense that it does not vary over time) but not

"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 forward-looking behavior in
the financial sector in the model presented above. As heretofore described, the model makes the specific
assumption that any inflation-sensitivity in the financial sector will be forward-looking. To vary that assumption,
you could use a PARAMETER ("k") in the second equation:
Financial Sector:

r = b0 + b1r-1 + b2[kp-1 + (1-k)p+1]

(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) + (1-k)*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 = A0-A1*R(-1)+A2*R(-2)+A3*G
R = B0+B1*R(-1)+B2*(K*P(-1)+(1-K)*P(+1))
P = C0+C1*P(-1)+C2*Y(-1)+C3*Y(-2)

3. Using a PARAMETER Symbol


now exists as a symbol within an equation in the model. Since k is a parameter, you must supply it before you
can use the model. You must create a concrete data object corresponding to the symbol k. Usually, the easiest
way to create a data object is with the DO command:
k

MODEDIT Command: do k=.5;

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 read-SEARCHable database before the first write-SEARCHable one. The DO statement writes to the first
write-SEARCHable database on the SEARCH list, but the model will use the first k that it finds, which might be in a
non-write-SEARCHable database.)

Since equations 1 and 3 are unchanged, there is no need to re-estimate them. Thus,
MODEDIT Command: olsmod 2 ;
ORDINARY LEAST SQUARES
2 :

R = B0+B1*R(-1)+B2*(K*P(-1)+(1-K)*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.77353786e-005
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!)

4. Fancier Specifications: FUNCTION Symbols


Suppose you want to change the specification of the real sector equation (equation 1) to make it logarithmic in
R. That's easy to do:
OLSMOD Command: changeq /R(-1)/LOG(R(-1))/ 1 ;
MODEDIT Command: changeq /R(-2)/LOG(R(-2))/ 1 ;

But look at this:


MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
P R Y
EXOGENOUS :
G
COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

C0

C1

C2

C3

PARAMETER :
K
FUNCTION :
LOG
Equations:
1:
2:
3:

Y = A0-A1*LOG(R(-1))+A2*LOG(R(-2))+A3*G
R = B0+B1*R(-1)+B2*(K*P(-1)+(1-K)*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 built-in 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 = A0-A1*LOG(R(-1))+A2*LOG(R(-2))+A3*G

NOB = 24

NOVAR = 4

NCOEF = 4

RANGE: 1973A to 1996A


RSQ =
0.546944
F(3/20) =
8.048217
SER =
1.550095
DW(0) =
1.786429
MAX:HAT =
0.340201
DFFITS =
-0.992997
COEF

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 user-defined 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.

5. Shock Variables: POLICY Symbols


Two symboltypes have not yet appeared in this chapter: DEFINITION and POLICY. Anything you can do with
TROLL, you can do without using DEFINITION or POLICY symbols, but they can sometimes be convenient.
Technically, POLICY symbols are just like EXOGENOUS symbols, but they are often used differently. EXOGENOUS
symbols typically represent "unchangeable" external variables -- variables that do not depend on the model and
also do not depend on what the model is trying to evaluate. POLICY symbols typically represent what the model
is trying to evaluate. A user will typically look at results from various alternative values of the POLICY variables.
These are the "shock" variables. The advantage of using the POLICY symboltype for some variables is that it
makes the model self-documenting. Anyone who uses the model can tell which variables are to be "taken as
given" (EXOGENOUS) and which are to be "shocked and studied" (POLICY).
In the model described earlier in this chapter, we might want to think of G as a "policy" variable. In particular, if
we wanted to study the effect of fiscal policy, we would want to shock G rather than taking it as given.
Accordingly, we could change the symboltype of G as follows:

OLSMOD Command: changesym policy g ;


MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
P R Y
POLICY :
G
COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

C0

C1

C2

C3

PARAMETER :
K
FUNCTION :
LOG
Equations:
1:
2:
3:

Y = A0-A1*LOG(R(-1))+A2*LOG(R(-2))+A3*G
R = B0+B1*R(-1)+B2*(K*P(-1)+(1-K)*P(+1))
P = C0+C1*P(-1)+C2*Y(-1)+C3*Y(-2)

The change is superficial and will not affect any results.

6. Identity Equations and DEFINITION Symbols


Last but not least (certainly not least confusing), there is the DEFINITION symboltype. DEFINITION symbols
represent variables defined by identity equations. That seems like a simple idea, but don't be deceived: these
symbols cause a lot of trouble and should be used with caution.
TROLL places certain restrictions on the use of DEFINITION symbols in estimation and simulation. Most
important, DEFINITION symbols must be defined before they are used -- in other words, they must not appear on
the right-hand side of an equation until they have first appeared on the left-hand side of another equation. When
you add an identity equation (an equation with a DEFINITION symbol on the left-hand side) to a model, you may
often want to use the TOP keyword to specify position. (However, if one identity equation uses a symbol defined
by another identity equation, then the one that defines the symbol must be closer to the top.)
Another requirement is that the DEFINITION symbol must be alone on the left-hand side of its identity equation.
If the equation does not come to you in this form, you will have to solve algebraically for the DEFINITION
symbol before using the identity equation.
Finally, the identity that defines a DEFINITION symbol should not contain ENDOGENOUS variables with leads. In
other words, you can't have a forward-looking identity equation.
Aside from the above restrictions, DEFINITION symbols are very much like ENDOGENOUS symbols. The advantage
of using DEFINITION symbols is that you need not provide data, since TROLL will calculate the values
(assuming the symbol is properly used). When you use an ENDOGENOUS symbol, you must provide data, even if
those data are to be overwritten by a simulation task.
If you want to be safe, you can avoid DEFINITION symbols altogether. You always have the option of declaring a
symbol ENDOGENOUS and calculating it from its identity (using a DO statement, for example). The end result will
be the same as if you had used a DEFINITION symbol. When you do a simulation, you need only supply dummy
values for the endogenous variables (except for initial or terminal values, when required). In some cases,
therefore, you can even avoid the algebra of solving an identity equation: just include the equation in the model,
declare the relevant symbol as ENDOGENOUS, and initialize it to an arbitrary value.

D. SYMBOLTYPE SHORTCUTS: DEFAULTS AND SUFFIXES


One final word about symboltypes: you don't need to use the ADDSYM statement to declare them. As shown in the LOG
example above, built-in TROLL functions are automatically declared with symboltype FUNCTION. Other symbols default
to EXOGENOUS if they are not declared explicitly. The rest can be declared "on the fly" by appending a type abbreviation
to the symbol name the first time the symbol is used. Each type abbreviation is introduced by an apostrophe. These are
the abbreviations:
'C

COEFFICIENT
'D
DEFINITION
'N
ENDOGENOUS
'X
EXOGENOUS
'F
FUNCTION
'P
PARAMETER
'POL
POLICY

The model above could thus be specified as follows:


MODEDIT Command: usemod ;
New model: (nameless)
TROLL Command: addeq bottom y'n = a0'c - a1'c*log(r'n(-1)) + a2'c*log(r(-2))
Continue eq: + a3'c*g'pol ;
MODEDIT Command: addeq bottom r = b0'c + b1'c*r(-1)
Continue eq: + b2'c * (k'p*p'n(-1) + (1-k)*p(+1)) ;
MODEDIT Command: addeq bottom p = c0'c + c1'c*p(-1) + c2'c*y(-1) + c3'c*y(-2) ;
MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
P R Y
POLICY :
G
COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

C0

C1

C2

C3

PARAMETER :
K
FUNCTION :
LOG
Equations:
1:
2:
3:

Y = A0-A1*LOG(R(-1))+A2*LOG(R(-2))+A3*G
R = B0+B1*R(-1)+B2*(K*P(-1)+(1-K)*P(+1))
P = C0+C1*P(-1)+C2*Y(-1)+C3*Y(-2)

...or the original version of the model:


MODEDIT Command: usemod ;
New model: (nameless)
TROLL Command: addeq bottom y'n = a0'c - a1'c*r'n(-1) + a2'c*r(-2) + a3'c*g ;
MODEDIT Command: addeq bottom r = b0'c + b1'c*r(-1) + b2'c*p'n(+1) ;
MODEDIT Command: addeq bottom p = c0'c + c1'c*p(-1) + c2'c*y(-1) + c3'c*y(-2) ;
MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
P R Y
EXOGENOUS :
G
COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

C0

C1

C2

C3

Equations:
1:
2:
3:

Y = A0-A1*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.

II. MODEL FILES


From TROLL's point of view, an existing model is represented by a "model file". A model file is a store of information about a
model. That would include all the information created in the previous section. Normally, a model file resides on a computer's
hard disk with the suffix ".mod".

A. THE "CURRENT" MODEL FILE AND THE MODEDIT BUFFER


The most important model file is the file called "CURRENT", which contains the working model during a TROLL
session. Estimation and simulation tasks in TROLL can only use the "CURRENT" model. The MODEDIT command edits
the "CURRENT" model by default, but it can also edit other model files stored on disk. The USEMOD command sets the
identity of the "CURRENT" model, either by resetting "CURRENT" to an empty model file, or by copying the contents
of a permanent model file into "CURRENT".
Because estimation and simulation tasks use the "CURRENT" model file (and also because it is the default for
MODEDIT), you should remain aware of the identity of the "CURRENT" model during a TROLL session. That identity is
not always obvious.
In particular, the "CURRENT" model file is not the same as the MODEDIT buffer. When you edit a model, MODEDIT keeps
its own temporary copy of the model. (Most commonly, you will be editing the "CURRENT" model, and MODEDIT will
have a temporary copy of it.) This copy is invisible outside MODEDIT, and it is discarded if you leave MODEDIT with the
QUIT command. If you leave MODEDIT by entering another task directly (for example, by typing "simulate;" at the
MODEDIT prompt), then the temporary copy becomes "permanent" and replaces the copy that existed when you began
editing.
Because MODEDIT's buffer is invisible outside MODEDIT, any non-MODEDIT commands you type during the MODEDIT task
will refer to the unedited copy of "CURRENT". For example, suppose you are using MODEDIT to edit the "CURRENT"
model. If you type "prtmod;" (a TROLL utility command) at the MODEDIT prompt, you will see the "CURRENT" model
as it was before you entered MODEDIT, but if you type "print;" (a low-level MODEDIT command), you will see the
temporary, edited copy.

B. MODEL FILE STRUCTURE


1. The Rudimentary Model File
A model file has two essential parts:
a symbol table, and
an equation list.
The symbol table contains an entry for each symbol in the model. A symbol table entry has two essential parts:
a symbolname, and
a symboltype.
The equation list contains an entry for each equation in the model. An equation list entry has two essential parts:
an equation number, and
an equation specification.
The PRINT command in the previous section prints out such a rudimentary model file. Schematically, one could
represent the model like this:

Model File: CURRENT


Symbols
symbolname

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 = A0-A1*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.

2. Adding Useful Information


A human user might want more information about a model than named symbols, numbered equations, and a file
name. Moreover, equation numbers can be hard to remember. Happily, TROLL model files can contain optional
information to help human beings. (Also, TROLL can add its own kind of information to a model when it
analyzes the model for simulation.) Specifically, the following types of information can appear in a model file:
Optional Model Elements
Comment
Simulation Code
Optional Symbol Element
Comment
Optional Equation Elements
Comment
Label
a. equation labels
The last of these optional elements -- the equation label -- is particularly useful, because it is meaningful
both to TROLL and to the user. You might not remember the order in which you entered your model
equations, but if you give them labels, you probably will remember the labels.
i. creating labels
There are several ways to create equation labels. The easiest way is to include the label when you
first specify the equation. The label goes at the beginning of the equation. After the label comes a
colon, and then the equation specification. To show this syntax, we'll re-specify the Phillips curve
equation (equation 3) in the example model with the label "PC".
MODEDIT
MODEDIT
MODEDIT
MODEDIT

Command:
Command:
Command:
Command:

Equations:

deleq 3 ; // Delete the old equation


// Add the "new" equation
addeq bottom pc: p = c0+c1*p(-1)+c2*y(-1)+c3*y(-2) ;
print equations all ;

1:
2:
3: PC

Y = A0-A1*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)

There's the label.


But there is a problem now, and unfortunately you cannot see the problem in the equations.
Observe the following:
MODEDIT Command: print symbols all ;
Symbols:
ENDOGENOUS :
P R Y
EXOGENOUS :
C0 C1 C2

C3

COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

ii. changing symbols


If you try to estimate the PC equation now, you will get an error, because all its coefficients have
become EXOGENOUS. When we deleted the equation, all its symbols (except those appearing in
other equations) were deleted too! When we entered the "new" equation, the "new" symbols were
assigned the default symboltype EXOGENOUS. You can quickly fix that problem with the CHANGESYM
command:
MODEDIT Command: changesym coefficient c0 c1 c2 c3 ;
MODEDIT Command: print symbols c* ;
Symbols:
COEFFICIENT :
C0 C1 C2 C3

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 = A0-A1*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 label-inclusion 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 = A0-A1*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 = A0-A1*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)

You can eliminate the comment by replacing it with nothing:


MODEDIT Command: modcom ;
MODEDIT Command: print ;
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 = A0-A1*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)

Multi-line 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 Forward-Looking Financial Sector
or ';': Used to Demonstrate Model Creation in TROLL
or ';': ;
Command: print ;

Simple Keynesian Model with Forward-Looking Financial Sector


Used 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 = A0-A1*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)

ii. symbol comments


Symbol comments are extremely useful in documenting a model. Symbolnames like Y, R, and P
are not very descriptive. Symbolnames like REAL.PER.CAPITA.OUTPUT.GROWTH.RATE are feasible
but inconvenient. The solution is to use short names and longer comments. Use SYMCOM to add a
comment to a particular symbol:
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT

Command:
Command:
Command:
Command:
Command:

symcom y Real Per Capita Output Growth Rate ;


symcom g Real Government Purchases Growth Rate ;
symcom r Short-term Nominal Interest Rate ;
symcom p Inflation Rate ;
print com ;

Simple Keynesian Model with Forward-Looking Financial Sector


Used to Demonstrate Model Creation in TROLL
Symbols:
ENDOGENOUS :
P
- Inflation Rate
R
- Short-term Nominal Interest Rate
Y
- Real Per Capita Output Growth Rate
EXOGENOUS :
G
- Real Government Purchases Growth Rate
COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

C0

C1

C2

C3

Equations:
1: IS
2: FINANCE
3: PC

Y = A0-A1*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)

iii. equation comments


Equations can also have comments. Use EQCOM to add them:
MODEDIT
MODEDIT
MODEDIT
MODEDIT

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 = A0-A1*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.

3. TROLL's Model Analysis Information


When TROLL analyzes a model (either in preparation for a simulation or in response to certain commands
requesting information about the model), it adds information about the analysis to the model file. Thus it avoids
the need to repeat the analysis for any later simulation or information request. (When you edit the model again,
TROLL will drop the old analysis information from the model file, since the old analysis will not apply to the
revised model.)
Specifically, there are three things that TROLL adds to model:
an "incidence matrix",
a "block ordering", and
"simulation code".
These rather opaque terms are explained briefly below. The Simulation chapter will go into more detail.
a. incidence matrix
The incidence matrix tells which symbols appear in which equations and with what lags and/or leads.
Creating an incidence matrix is the first step in preparing an analysis for simulation.
Information about a model's incidence matrix can be retrieved (and in some cases, created) with the
commands SYMTAB, LKSYM, and LKXREF. SYMTAB displays an augmented symbol table. For each symbol, the
table tells the minimum and maximum lead/lag with which that symbol appears in the model:
MODEDIT Command: symtab all ;
Horizon:
Min
Max
Symboltype
Symbolname
0
0
COEFFICIENT
A0
0
0
COEFFICIENT
A1
0
0
COEFFICIENT
A2
0
0
COEFFICIENT
A3
0
0
COEFFICIENT
B0
0
0
COEFFICIENT
B1
0
0
COEFFICIENT
B2
0
0
COEFFICIENT
C0
0
0
COEFFICIENT
C1
0
0
COEFFICIENT
C2
0
0
COEFFICIENT
C3
0
0
EXOGENOUS
G
-1
0
ENDOGENOUS
P
-2
0
ENDOGENOUS
R
-2
0
ENDOGENOUS
Y

LKSYM

tells which symbols appear in which equations, but it does not give lag/lead information:

TROLL Command: lksym all ;


Variable
A0
A1
A2
A3
B0
B1
B2
C0
C1
C2
C3
G
P
R
Y

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

TROLL Command: lkxref all ;


Analyzing Model's Incidence Matrix
Variable

Used Unlagged in Equations

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.

4. The Complete Model File


Here's the whole model:
TROLL Command: prtmod all com ;
Simple Keynesian Model with Forward-Looking Financial Sector
Used to Demonstrate Model Creation in TROLL
Symbols:
ENDOGENOUS :
P
- Inflation Rate
R
- Short-term Nominal Interest Rate
Y
- Real Per Capita Output Growth Rate
EXOGENOUS :
G
- Real Government Purchases Growth Rate
COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

C0

C1

C2

C3

Equations:
Real Sector
1: IS
Y = A0-A1*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:

Model File: CURRENT


Model Comment
Simple Keynesian Model with Forward-Looking Financial Sector

Used to Demonstrate Model Creation in TROLL


Symbols
symbolname

symboltype

comment

ENDOGENOUS

Inflation Rate

ENDOGENOUS

Short-term Nominal Interest Rate

ENDOGENOUS

Real Per Capita Output Growth Rate

EXOGENOUS

Real Government Purchases Growth Rate

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=
A0-A1*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

(invisible; may be examined with SYMTAB, LKSYM, and LKXREF)


Block Ordering
(invisible; may be examined with LKORD)
Simulation Code
(invisible)

III. USING MODELS


A. WHAT MODELS ARE FOR
In principle, there are two things you can do with a model:
estimate, and
simulate
Accordingly, these two activities are the topics for the next two chapters.
In practice, life is more complicated. You might not want to estimate a whole model at once. If you did intend to

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 low-level 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

TROLL Command: modedit ;


MODEDIT Command: print comment symbols endogenous ;
Symbols:
ENDOGENOUS :
P
- Inflation Rate
R
- Short-term Nominal Interest Rate
Y
- Real Per Capita Output Growth Rate

...or, similarly, the EXOGENOUS variables without comments:


MODEDIT Command: print symbols exogenous ;
Symbols:
EXOGENOUS :
G

(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 = A0-A1*R(-1)+A2*R(-2)+A3*G
P = C0+C1*P(-1)+C2*Y(-1)+C3*Y(-2)

To look at explicit or implicit symbol declarations:


MODEDIT Command: print declarations ;
Symbols (explicitly declared):
MODEDIT Command: print suffixes equations all ;
Equations:
1: IS
2: FINANCE
3: PC

Y'N = A0'C-A1'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

Simple Keynesian Model with Forward-Looking Financial Sector


Used to Demonstrate Model Creation in TROLL
Symbols:
ENDOGENOUS :
P R Y
EXOGENOUS :
G X
COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

C0

C1

C2

C3

Equations:
1:
2:
3:
4:
5:

IS
FINANCE
PC
NEW
NEWER

Y
R
P
X
Y

=
=
=
=
=

A0-A1*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

MODEDIT Command: prtmod ; // Prints "CURRENT" model


Simple Keynesian Model with Forward-Looking Financial Sector
Used to Demonstrate Model Creation in TROLL
Symbols:
ENDOGENOUS :
P R Y
EXOGENOUS :
G X
COEFFICIENT :
A0 A1 A2 A3

B0

B1

B2

C0

C1

C2

C3

Equations:
1:
2:
3:
4:

IS
FINANCE
PC
NEW

Y
R
P
X

=
=
=
=

A0-A1*R(-1)+A2*R(-2)+A3*G
B0+B1*R(-1)+B2*(+1)
C0+C1*P(-1)+C2*Y(-1)+C3*Y(-2)
1

MODEDIT Command: prtmod model previous ; // Prints model named "PREVIOUS"


Simple Keynesian Model with Forward-Looking Financial Sector
Used 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 = A0-A1*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 real-world
modelling: the Japanese submodel from the IMF's Mark II Multimod model. Here it is:
TROLL Command: usemod models_multj ;

TROLL Command: prtmod ;


'Japan' sub-model from Multimod.
Symbols:
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 RES_JA_INVEST RES_JA_IOIL RES_JA_K RES_JA_M
RES_JA_NFA RES_JA_P RES_JA_PGNP RES_JA_PIM RES_JA_PXM RES_JA_RL
RES_JA_RS RES_JA_TAX RES_JA_TRATE RES_JA_XM RES_JA_YCAP RW_ER RW_PXM
SI_A SI_ER SI_PGNPNO SI_PXM T UK_A UK_ER UK_PGNPNO UK_PXM US_A US_ER
US_PGNPNO US_PXM US_R US_RS WTRADE WTRADER
COEFFICIENT :
JC0 JC1 JC2 JC3 JC4 JC5
JIC1 JIC2 JIC3 JIC4 JIC5
JK0 JK1 JK2 JM0 JM1 JM2
JXM1 JXM2 JXM3 JXM4 JXM5
L29 S12 S22 S32 S42 S52
V27 V28 W21 W22 W23 W24

JCOIL0 JCOIL1 JCOIL2 JCOIL3 JCOIL4 JIC0


JIM0 JIM1 JIM2 JIM3 JIM4 JIM5 JIM6 JIM7
JM4 JP1 JP2 JP3 JPXM0 JPXM1 JPXM2 JXM0
JXM6 L21 L22 L23 L24 L25 L26 L27 L28
S62 S72 S82 S92 TAU3 V23 V24 V25 V26
W25 W26 W27 W28 W29

PARAMETER :
CE87 EE87 FE87 GE87 IE87 JBETA JDUMCT JE87 JK87 JL87
JRHO JRPREM JY87 RE87 SE87 T2 TAU1 TAU2 TRDE TRDER

JPROD JR1 JR3


UE87 URBAR

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

DEL(1: LOG(JA_C)) = JC0+JC1*LOG(JA_W(-1)/JA_C(-1))+JC2*JA_RLR+JC3


*DEL(1: LOG(JA_YD))+JC4*JA_DEM3+JC5*DUM80+RES_JA_C
DEL(1: LOG(JA_COIL)) = JCOIL0+JCOIL1*DEL(1: LOG(JA_GDP))+JCOIL2*
DEL(1: LOG(POIL/JA_ER/JA_PGNP))+JCOIL3*LOG(POIL(-1)/JA_ER(-1)/
JA_PGNP(-1))+JCOIL4*LOG(JA_GDP(-1)/JA_COIL(-1))+RES_JA_COIL
DEL(1: LOG(JA_K)) = JK0+JK1*LOG(JA_WK/JA_K(-1))+JK2*LOG(JA_WK(-1)
/JA_K(-2))+RES_JA_K
JA_INVEST = DEL(1: JA_K)+JA_DELTA*JA_K(-1)+RES_JA_INVEST
DEL(1: LOG(JA_XM)) = JXM0+JXM1*DEL(1: JA_REER)+JXM2*DEL(1: LOG(
JA_FA))+JXM3*LOG(JA_XM(-1)/JA_FA(-1))+JXM4*JA_REER(-1)+JXM5*T+
JXM6*T**2+RES_JA_XM
JA_XMA = JA_XM+T2*(WTRADER-TRDER)/JE87
JA_XT = JA_XMA+JA_XOIL
DEL(1: LOG(JA_IM)) = JIM0+JIM1*DEL(1: JIM7*LOG(JA_A)+(1-JIM7)*LOG
(JA_XMA))+JIM2*DEL(1: LOG(JA_PIMA/JA_PGNPNO))+JIM3*LOG(JA_PIMA(1)/JA_PGNPNO(-1))+JIM4*(JIM7*LOG(JA_A(-1))+(1-JIM7)*LOG(JA_XMA(1))-LOG(JA_IM(-1)))+JIM5*T+JIM6*T**2+RES_JA_IM
JA_IOIL = JA_COIL+JA_XOIL-JA_PRODOIL+RES_JA_IOIL
DEL(1: LOG(JA_ICOM)) = JIC0+JIC2*DEL(1: LOG(PCOM/JA_ER/JA_PGNP))+
JIC1*DEL(1: LOG(JA_GDP))+JIC3*LOG(PCOM(-1)/JA_ER(-1)/JA_PGNP(-1)
)+JIC4*LOG(JA_GDP(-1))+JIC5*LOG(JA_ICOM(-1))+RES_JA_ICOM
JA_IT = JA_IM+JA_IOIL+JA_ICOM
JA_A = JA_C+JA_INVEST+JA_G+RES_JA_A
JA_GDP = JA_A+JA_XT-JA_IT+RES_JA_GDP
JA_GNP = JA_GDP+US_R*(JA_NFA(-1)+JA_NFAADJ(-1))/JA_ER/JA_PGNP+
RES_JA_GNP
JA_W = JA_WH+JA_WK+(JA_M+JA_B+JA_NFA/JA_ER)/JA_P
JA_WH = JA_WH(1)/(1+URBAR+0.035)+((1-JA_BETA)*JA_GDP*JA_PGNPJA_TAXH)/JA_P+JRPREM*JA_WK
JA_WK = JA_WK(1)/(1+JA_RSR+JA_K/JA_K(-1)-1)+(JA_BETA*JA_GDP*
JA_PGNP-JA_TAXK)/JA_P-(JA_DELTA+JRPREM)*JA_WK
JA_YD = (JA_GDP*JA_PGNP-JA_TAX)/JA_P-JA_DELTA*JA_K(-1)
JA_GE = JA_P*JA_G+JA_R*JA_B(-1)+JA_GEXOG
JA_TAX = JA_TRATE*(JA_PGNP*JA_GNP-JA_DELTA*JA_K(-1)*JA_P+JA_R*
JA_B(-1)+RES_JA_TAX*JA_PGNP)
JA_TAXK = JDUMCT*JA_BETA*JA_TAX+(1-JDUMCT)*JA_CTREFF*JA_BETA*
JA_GDP*JA_PGNP
JA_TAXH = JA_TAX-JA_TAXK
DEL(1: JA_TRATE) = JA_DUM*(TAU1*(JA_B-JA_BT)/(JA_GNP*JA_PGNP)+
TAU2*DEL(1: JA_B-JA_BT)/(JA_GNP*JA_PGNP))+TAU3*(JA_TRATEBAR(-1)-

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_G-JA_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.2-1+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.2-1
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/100-1)+JP2*DEL(1:
LOG(JA_P/JA_PGNPNO))+RES_JA_PGNP
JA_PGNPNO = (JA_GDP*JA_PGNP-JA_PRODOIL*POIL/JA_ER*JE87)/(JA_GDPJA_PRODOIL)
JA_PGNP = (JA_P*JA_A+JA_XT*JA_PXT-JA_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))+(1-JPXM1
)*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*(WTRADE-TRDE)/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)+(1-JBETA)*((1+JPROD)**
(T-21)*(1+RES_JA_YCAP/(1-JBETA))*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_PXT-JA_IT*JA_PIT)*JA_ER+US_R*(JA_NFA(1)+JA_NFAADJ(-1))+RES_JA_NFA
JA_TB = JA_XT*JA_PXT-JA_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 one-by-one 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 forward-looking behavior enters into the model. Rather than look
through all the equations and pick out those that seem to model forward-looking 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 short-term interest rate; JA_WH,
human wealth; and JA_WK, capital wealth: any forward-looking 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

Take a look, for example, at the equations that contain JA_RS:


TROLL Command: prtmod equations 26 27 28 29 31 48 ;
Equations:
26: JM
27: JRS
28: JRL
29: JR
31: JRSR
48: JER

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.2-1+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 forward-looking 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

Used Unlagged in Equations


8
15
16
1
2
32
47
2
5
25
2
19
14
10
8
4
9
11
3
41
15
50
15
15
35
2
8
38
8
34
36
34
19
5
28
1
26
17
18
16
17
46
20
15

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 one-to-one 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 ultra-simple 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
1-W

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 ;

TROLL Command: usemod models_multj ;


TROLL Command: lkord all ;
The model has 12 blocks, including 1 simultaneous block.
The largest block has 40 equations and the next largest has 1.
Block

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

C. USING AND REUSING MODELS


There are two ways to store a model for later re-use or re-editing. First, you can store the model itself as a TROLL
model file. Second, you can store the TROLL commands used to generate the model. The former method is more
efficient from a computational point of view, but the latter method may be easier to use, since it allows you to alter a
model without learning the details of TROLL's model-editing commands.

1. Storing Models As Models

a. storing with FILEMOD


The FILEMOD command stores the "CURRENT" model in a permanent model file, which you normally
specify by name. If you don't specify a file name, TROLL uses the file name from the last FILEMOD or
USEMOD command. (Note: SAVEMOD is a synonym for FILEMOD.)
TROLL Command: prtmod model waysimpl ;
Symbols:
ENDOGENOUS :
W X Y Z
Equations:
1:
2:
3:
4:

X
X
Z
W

=
=
=
=

2*Y
Y+1
X
1-W

TROLL Command: usemod waysimpl ;


TROLL Command: deleq 4 ;
MODEDIT Command: filemod ;
TROLL Command: prtmod model waysimpl ;
Symbols:
ENDOGENOUS :
W X Y Z
Equations:
1:
2:
3:

X = 2*Y
X = Y+1
Z = X

TROLL Command: addeq bottom w = 1-w ;


MODEDIT Command: filemod ;

// put it back to use later

b. retrieving with USEMOD


As in the example above, USEMOD copies a named model into the "CURRENT" model.
c. editing with MODEDIT
See below, under "CHANGING MODELS".

2. Storing Models As Source Code


a. converting with SOURCEMOD
allows you to take an existing model and generate the TROLL commands necessary to
produce that model. For example,
SOURCEMOD

TROLL Command: usemod models_multj ;


TROLL Command: sourcemod to input makemulj ;
MODEDIT Command:

This SOURCEMOD command produced a file called "makemulj.inp" with the following content:
MODCOM
'Japan' sub-model 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

RES_JA_INVEST RES_JA_IOIL RES_JA_K RES_JA_M RES_JA_NFA RES_JA_P RES_JA_PGNP


RES_JA_PIM RES_JA_PXM RES_JA_RL RES_JA_RS RES_JA_TAX RES_JA_TRATE RES_JA_XM
RES_JA_YCAP RW_ER RW_PXM SI_A SI_ER SI_PGNPNO SI_PXM T UK_A UK_ER UK_PGNPNO
UK_PXM US_A US_ER US_PGNPNO US_PXM US_R US_RS WTRADE WTRADER,
COEFFICIENT
JC0 JC1 JC2 JC3 JC4 JC5 JCOIL0 JCOIL1 JCOIL2 JCOIL3 JCOIL4 JIC0 JIC1 JIC2 JIC3
JIC4 JIC5 JIM0 JIM1 JIM2 JIM3 JIM4 JIM5 JIM6 JIM7 JK0 JK1 JK2 JM0 JM1 JM2 JM4
JP1 JP2 JP3 JPXM0 JPXM1 JPXM2 JXM0 JXM1 JXM2 JXM3 JXM4 JXM5 JXM6 L21 L22 L23
L24 L25 L26 L27 L28 L29 S12 S22 S32 S42 S52 S62 S72 S82 S92 TAU3 V23 V24 V25
V26 V27 V28 W21 W22 W23 W24 W25 W26 W27 W28 W29,
PARAMETER
CE87 EE87 FE87 GE87 IE87 JBETA JDUMCT JE87 JK87 JL87 JPROD JR1 JR3 JRHO JRPREM
JY87 RE87 SE87 T2 TAU1 TAU2 TRDE TRDER UE87 URBAR,
FUNCTION
EXP LOG,
;
ADDEQ BOTTOM
JC
: DEL(1: LOG(JA_C)) = JC0+JC1*LOG(JA_W(-1)/JA_C(-1))+JC2*JA_RLR+JC3*DEL(
1: LOG(JA_YD))+JC4*JA_DEM3+JC5*DUM80+RES_JA_C ,
JCOIL : DEL(1: LOG(JA_COIL)) = JCOIL0+JCOIL1*DEL(1: LOG(JA_GDP))+JCOIL2*DEL(1
: LOG(POIL/JA_ER/JA_PGNP))+JCOIL3*LOG(POIL(-1)/JA_ER(-1)/JA_PGNP
(-1))+JCOIL4*LOG(JA_GDP(-1)/JA_COIL(-1))+RES_JA_COIL ,
JK
: DEL(1: LOG(JA_K)) = JK0+JK1*LOG(JA_WK/JA_K(-1))+JK2*LOG(JA_WK(-1)/JA_K
(-2))+RES_JA_K ,
JINV
: JA_INVEST = DEL(1: JA_K)+JA_DELTA*JA_K(-1)+RES_JA_INVEST ,
JXM
: DEL(1: LOG(JA_XM)) = JXM0+JXM1*DEL(1: JA_REER)+JXM2*DEL(1: LOG(JA_FA))
+JXM3*LOG(JA_XM(-1)/JA_FA(-1))+JXM4*JA_REER(-1)+JXM5*T+JXM6*T**2
+RES_JA_XM ,
JXA
: JA_XMA = JA_XM+T2*(WTRADER-TRDER)/JE87 ,
JXT
: JA_XT = JA_XMA+JA_XOIL ,
JIM
: DEL(1: LOG(JA_IM)) = JIM0+JIM1*DEL(1: JIM7*LOG(JA_A)+(1-JIM7)*LOG(
JA_XMA))+JIM2*DEL(1: LOG(JA_PIMA/JA_PGNPNO))+JIM3*LOG(JA_PIMA(-1
)/JA_PGNPNO(-1))+JIM4*(JIM7*LOG(JA_A(-1))+(1-JIM7)*LOG(JA_XMA(-1
))-LOG(JA_IM(-1)))+JIM5*T+JIM6*T**2+RES_JA_IM ,
JIOIL : JA_IOIL = JA_COIL+JA_XOIL-JA_PRODOIL+RES_JA_IOIL ,
JIC
: DEL(1: LOG(JA_ICOM)) = JIC0+JIC2*DEL(1: LOG(PCOM/JA_ER/JA_PGNP))+JIC1*
DEL(1: LOG(JA_GDP))+JIC3*LOG(PCOM(-1)/JA_ER(-1)/JA_PGNP(-1))+
JIC4*LOG(JA_GDP(-1))+JIC5*LOG(JA_ICOM(-1))+RES_JA_ICOM ,
JIT
: JA_IT = JA_IM+JA_IOIL+JA_ICOM ,
JA
: JA_A = JA_C+JA_INVEST+JA_G+RES_JA_A ,
JGDP
: JA_GDP = JA_A+JA_XT-JA_IT+RES_JA_GDP ,
JGNP
: JA_GNP = JA_GDP+US_R*(JA_NFA(-1)+JA_NFAADJ(-1))/JA_ER/JA_PGNP+
RES_JA_GNP ,
JW
: JA_W = JA_WH+JA_WK+(JA_M+JA_B+JA_NFA/JA_ER)/JA_P ,
JWH
: JA_WH = JA_WH(1)/(1+URBAR+0.035)+((1-JA_BETA)*JA_GDP*JA_PGNP-JA_TAXH)/
JA_P+JRPREM*JA_WK ,
JWK
: JA_WK = JA_WK(1)/(1+JA_RSR+JA_K/JA_K(-1)-1)+(JA_BETA*JA_GDP*JA_PGNPJA_TAXK)/JA_P-(JA_DELTA+JRPREM)*JA_WK ,
JYD
: JA_YD = (JA_GDP*JA_PGNP-JA_TAX)/JA_P-JA_DELTA*JA_K(-1) ,
JGE
: JA_GE = JA_P*JA_G+JA_R*JA_B(-1)+JA_GEXOG ,
JTAX
: JA_TAX = JA_TRATE*(JA_PGNP*JA_GNP-JA_DELTA*JA_K(-1)*JA_P+JA_R*JA_B(-1)
+RES_JA_TAX*JA_PGNP) ,
JTAXK : JA_TAXK = JDUMCT*JA_BETA*JA_TAX+(1-JDUMCT)*JA_CTREFF*JA_BETA*JA_GDP*
JA_PGNP ,
JTAXH : JA_TAXH = JA_TAX-JA_TAXK ,
JTRATE : DEL(1: JA_TRATE) = JA_DUM*(TAU1*(JA_B-JA_BT)/(JA_GNP*JA_PGNP)+TAU2*DEL
(1: JA_B-JA_BT)/(JA_GNP*JA_PGNP))+TAU3*(JA_TRATEBAR(-1)-JA_TRATE
(-1))+RES_JA_TRATE ,
JB
: DEL(1: JA_B)+DEL(1: JA_M) = JA_R*JA_B(-1)+JA_P*JA_G-JA_TAX+JA_GEXOG+
RES_JA_B*JA_P ,
JGDEF : JA_GDEF = DEL(1: JA_B+JA_M) ,
JM
: LOG(JA_M/JA_P) = JM0+JM1*LOG(JA_A)+JM2*JA_RS+JM4*LOG(JA_M(-1)/JA_P(-1)
)+RES_JA_M ,
JRS
: DEL(1: JA_RS)-JR3*(JA_RS(1)-JA_RS(-1)) = JR1*LOG(JA_MT/JA_M)/JM2+
RES_JA_RS ,
JRL
: 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.2-1+RES_JA_RL ,
JR
: JA_R = 0.5*JA_RS(-1)/100+0.5*SUM(I = -3 TO -1: JA_RL(I)/100)/3 ,
JRLR
: JA_RLR = (1+JA_RL/100)/(JA_P(5)/JA_P)**0.2-1 ,
JRSR
: JA_RSR = (1+JA_RS/100)/(JA_P(1)/JA_P)-1 ,
JPGNP : DEL(1: LOG(JA_PGNPNO)) = DEL(1: LOG(JA_PGNPNO(-1)))-JP3*DEL(1: LOG(
JA_PGNPNO(-1)/JA_PGNPNO(1)))+JP1*(JA_CU/100-1)+JP2*DEL(1: LOG(
JA_P/JA_PGNPNO))+RES_JA_PGNP ,
JPNO
: JA_PGNPNO = (JA_GDP*JA_PGNP-JA_PRODOIL*POIL/JA_ER*JE87)/(JA_GDPJA_PRODOIL) ,
JP
: JA_PGNP = (JA_P*JA_A+JA_XT*JA_PXT-JA_IT*JA_PIT)/JA_GDP+RES_JA_P*
JA_PGNP ,
JPFM
: 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(

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))+(1-JPXM1)*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*(WTRADE-TRDE)/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)+(1-JBETA)*((1+JPROD)**(T-21
)*(1+RES_JA_YCAP/(1-JBETA))*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_PXT-JA_IT*JA_PIT)*JA_ER+US_R*(JA_NFA(-1)+
JA_NFAADJ(-1))+RES_JA_NFA ,
JA_TB = JA_XT*JA_PXT-JA_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 model-editing 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:

MODEDIT Command: print symbols ja_i* ;

Symbols:
ENDOGENOUS :
JA_ICOM JA_IM

JA_INVEST

JA_IOIL

JA_IT

MODEDIT Command: renamesym ja_icom ja_impcom


MODEDIT Command: print symbols ja_i* ;

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
re-estimate or re-simulate 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 re-estimate, 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

c. DELEQ: removing equations


eliminates an equation (or set of equations) from the model, along with any associated comment or
label and any implicit symbol declarations that are not applied elsewhere in the model. If necessary,
DELEQ will renumber the remaining equations to form a sequence. See the earlier examples (under
"Changing Equations", "creating labels", and "storing with FILEMOD") and the Reference Manual topic
DELEQ

(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 ultra-simple 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
1-W

TROLL normalized it as follows:


TROLL Command: usemod waysimpl ;
TROLL 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

1
2

Y
X

Var

is associated with Equation 1, and X is associated with equation 2. We can change that as follows:

TROLL Command: renorm 2 y ;


TROLL Command: lkord all ;
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

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 ;

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_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

TROLL Command: renorm 1 ja_rlr 2 ja_gdp 3 ja_wk ;


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

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

E. USING DATA WITH MODELS

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

1. Data that TROLL Uses


Before you can do anything substantive with a TROLL model, you must have some data to use with it. When
TROLL goes to estimate or simulate a model, it tries to use whatever data are available. That is, TROLL goes
down the SEARCH list until it finds a data object with the same name as the model variable for which it needs
data. If you're not sure what is on the SEARCH list, or if you're not sure about the order of the SEARCH list, the
results may not be what you expect. There is nothing to prevent two data objects with the same name from
appearing in SEARCHed databases, but, barring alternative instructions, TROLL will only use the first one.
Consider the following:
TROLL Command: delsearch all ;
TROLL Command: search first us ;
TROLL Command: usemod ;
New model: (nameless)
TROLL Command: addeq top x'n = g ;
MODEDIT Command: do g = 2 ;
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 1970A to 1996A and must end by 1996A.
SIMULATE Command: list solutions all ;
SIMULATE Command: simstart 1970a ;
SIMULATE Command: dotil 1980a ;
Date:
What:
Value:
1970A
Solution: X
-3.136803
G
-3.136803
1971A
Solution: X
-0.15908
G
-0.15908
1972A
Solution: X
1.979313
G
1.979313
1973A
Solution: X
-0.01859
G
-0.01859
1974A
Solution: X
0.408366
G
0.408366
1975A
Solution: X
-0.491335
G
-0.491335
1976A
Solution: X
0.563261
G
0.563261
1977A
Solution: X
2.460729
G
2.460729
1978A
Solution: X
3.201268
G
3.201268
1979A
Solution: X
2.238387
G
2.238387
1980A
Solution: X
0.557095
G
0.557095

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

Time dimension -->


:
-3.136803
:
0.408366
:
3.201268
:
1.358334
:
5.025664
:
2.970237
:
-0.07731

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

In fact, SAVE_G is 2, as it should be:


SIMULATE Command: do prt.(save_g) ;
SAVE_G:
Numeric scalar:

Okay, let's try that simulation again:


SIMULATE Command: search first save ;
SIMULATE Command: simulate ;
Simulations can start from NA to NA.
SIMULATE Command: list solutions all ;
SIMULATE Command: simstart 1970a ;
SIMULATE Command: dotil 1980a ;
Date:
What:
1970A
Solution: X
G
1971A
Solution: X
G
1972A
Solution: X
G
1973A
Solution: X
G
1974A
Solution: X
G
1975A
Solution: X
G
1976A
Solution: X
G
1977A
Solution: X
G
1978A
Solution: X
G
1979A
Solution: X
G
1980A
Solution: X
G

Value:
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

2. Data that TROLL Ignores


You should also be aware of when TROLL needs data and when it doesn't. If TROLL doesn't need data, then it
won't use data, even if the data exist and are on the SEARCH list. In particular, if you have a data object
corresponding (in name) to a DEFINITION symbol, a TROLL simulation will ignore the data object. During
simulation, TROLL will compute the symbol's values according to its identity equation, and if it can't do that, it
will give an error message. If you subsequently re-declare the DEFINITION symbol as ENDOGENOUS, TROLL will
suddenly become interested in the corresponding data object. The former identity equation will no longer be
treated as such. This effect is apparent in the following example:
TROLL Command: usemod ;
New model: (nameless)
TROLL Command: delsearch all ;
TROLL Command: do x = reshape( seq(7), 1a ) ;
TROLL Command: do z = reshape( seq(7), 1a ) ;
TROLL Command: do prt.( x, z ) ;
X:
X = RESHAPE(SEQ(7),1A)
Numeric scalar timeseries -Time dimension: Periodicity 1,

1A
5A

Time dimension -->


:
1
:
5

Z:
Z = RESHAPE(SEQ(7),1A)

2
6

1A to 7A

(7 observations)

3
7

Numeric scalar timeseries -Time dimension: Periodicity 1,

1A
5A

Time dimension -->


:
1
:
5

1A to 7A

2
6

(7 observations)

3
7

TROLL Command: addsym definition z, endogenous x


MODEDIT Command: addeq bottom z = x(-1) ;
MODEDIT Command: addeq bottom x = z(-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 3A to 8A.
SIMULATE Command: list solutions all ;
SIMULATE Command: simstart 3a ;
SIMULATE Command: dotil 8a ;
Date:
What:
Value:
3A
Solution: Z
2
X
1
4A
Solution: Z
1
X
2
5A
Solution: Z
2
X
1
6A
Solution: Z
1
X
2
7A
Solution: Z
2
X
1
8A
Solution: Z
1
X
2
SIMULATE Command: changesym endogenous z ;
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 2A to 8A.
SIMULATE Command: list solutions all ;
SIMULATE Command: simstart 3a ;
SIMULATE Command: dotil 8a ;
Date:
What:
Value:
3A
Solution: Z
2
X
2
4A
Solution: Z
2
X
2
5A
Solution: Z
2
X
2
6A
Solution: Z
2
X
2
7A
Solution: Z
2
X
2
8A
Solution: Z
2
X
2

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.

F. WORKING WITH MULTIPLE MODELS


To work with more than one model in TROLL, you must give names to the models, store them in separate files, and
access them alternately with the USEMOD command (or by re-making them from input files). Only one model can be
"CURRENT" at any time.
With some versions of TROLL, you can operate multiple TROLL sessions at once. It may be convenient to run separate
sessions and work with a separate model in each session. But be careful: TROLL sessions started on the same local
machine normally share the same working directory; and if two TROLL sessions share a working directory, then they
will also share the disk version of the "CURRENT" model. If one session writes its "CURRENT" model to disk, the
other session may read that model as "CURRENT" and produce unexpected results. To get around this problem, you can

deliberately run separate TROLL sessions from separate working directories.


Another trick for working with multiple models is to change the SEARCH list. This won't affect TROLL's working
directory where it stores the "CURRENT" model, but it will change the locations where TROLL searches for named
models. So, for example, if you have an input file that expects to use a model name "MOD1", and you want to use it
with a different model (say "MOD2"), you can put a different model directory on top of the SEARCH list and copy
"MOD2" into that new directory as "MOD1". The following is a trivial example:
SIMULATE Command: host "mkdir dir1" ;
SIMULATE Command: host "mkdir dir2" ;
SIMULATE Command: access dir1 type disk mode w ;
SIMULATE Command: access dir2 type disk mode w ;
SIMULATE Command: search dir1 w ;
SIMULATE Command: usemod ;
New model: (nameless)
TROLL Command: addeq top x'n = 1 ;
MODEDIT Command: filemod mod1 ;
TROLL Command: usemod ;
New model: (nameless)
TROLL Command: addeq top x'n = 2 ;
MODEDIT Command: filemod mod2 ;
TROLL Command: host "copy dir1\\mod2.mod dir2\\mod1.mod"
1 file(s) copied.
TROLL Command: usemod mod1 ;
TROLL Command: prtmod ;
Symbols:
ENDOGENOUS :
X
Equations:
1:

X = 1

TROLL Command: search before dir1 dir2 ;


TROLL Command: usemod mod1 ;
TROLL Command: prtmod ;
Symbols:
ENDOGENOUS :
X
Equations:
1:

X = 2

(The above example uses Windows file path syntax. On a UNIX system, you would replace the double-backslashes with
single forward-slashes.)
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

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter Seven. Estimating Model Coefficients


I. OVERVIEW OF HOW TO USE ESTIMATION TASKS
A. BOUNDS AND MISSING DATA
1. Working With Missing Values
2. Replacing Or Eliminating Missing Values
a. NAFILL: replacing missing values with a single value
b. NAINTERP: linear interpolation
c. NAGROW: growth rate (geometric) interpolation
d. OVERLAY: replacing missing values with other series
e. NASQUEEZE: collapsing away missing values
f. combining multiple data replacement methods

II. ORDINARY LEAST SQUARES


A. DIRECT-INPUT OPTION
B. MODEL-INPUT OPTION

III. ADVANCED SINGLE-EQUATION TECHNIQUES


A. DISTRIBUTED LAGS
B. SERIAL CORRELATION
C. TWO-STAGE LEAST SQUARES
D. NON-LINEAR LEAST SQUARES

IV. MULTIPLE EQUATION TECHNIQUES

Portable TROLL User's Guide

Chapter Seven. Estimating Model Coefficients


I. OVERVIEW OF HOW TO USE ESTIMATION TASKS
TROLL performs estimation tasks on time series data. It finds the appropriate data according to the usual ACCESS and SEARCH
rules. Before estimation begins, TROLL must have a set of dates ("BOUNDS") over which to estimate. All the time series involved
in the estimation must have data available (i.e., not NA) for all of those dates.
The user begins the estimation process by finding such a set of dates. If you know what time periods you want to estimate, and
you have complete data (appropriately ACCESSed and SEARCHed) for all those time periods, you can specify this information via
the BOUNDS command:
TROLL Command: bounds 1970a to 1990a ;

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 ;

***** Regression Bounds *****


Time bounds with 21 observations in 1 range:
1: 1970A to 1990A

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.)

A. BOUNDS AND MISSING DATA


1. Working With Missing Values
As noted above, estimation in TROLL begins with choosing BOUNDS. The easiest way to choose bounds is to let
TROLL choose them for you. The BOUNDS function computes the widest feasible BOUNDS for a set of time series.
In most cases you can cut and paste those bounds directly into a BOUNDS statement. For example:
TROLL
TROLL
TROLL
1970A
TROLL

Command:
Command:
Command:
to 2100A
Command:

access us type trolldb id d:\troll\samples\work\usmac.trl ;


search us ;
do bounds (g, p, r, y) ;
bounds 1970A to 2100A ;

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

Command: do var = reshape ( seq(20) - 10 , 1a ) ;


Command: do bounds ( var ) ;
20A
Command: do bounds ( 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 non-positive 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 NA-free 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 non-positive 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 ;

***** Regression Bounds *****


Time bounds with 20 observations in 2 ranges:
1: 1A to 10A
2: 21A to 30A

2. Replacing Or Eliminating Missing Values


If you need a continuous data set, TROLL offers several options for filling in the blanks:
You can use the average value of a series to fill in its missing values.
You can choose your own default value to fill in the missing values.
TROLL can interpolate linearly between the values surrounding missing values.
TROLL can fill in the missing values based on compound growth rates (geometric interpolation)
You can supply another data series from which to take the missing values.
To avoid filing in missing values with missing values, you can supply several alternate data series.
If you're willing to alter the timing of your data, you can simply squeeze out the missing values and use a
shorter series.
With a little light programming, you can combine these methods in various ways.
a. NAFILL: replacing missing values with a single value
is a function that takes an array (usually a time series) as input and returns a completed version of
the same array. In its simplest form, NAFILL takes one argument and uses the average of the series as its
NAFILL

fill-in 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

Time dimension -->


:
-1.174359
:
0
:
-1.174359
:
-2.651995
:
-2.651995
:
-1.174359
:
0
:
-1.174359
:
-2.651995
:
-2.651995

NAFILL

also has a two-argument 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

TROLL Command: do prt.( nafill (doughnut, 0) ) ;


NAFILL(DOUGHNUT,0):
Numeric scalar timeseries -Time dimension: Periodicity 1,

1A
5A
9A
13A
17A
21A
25A
29A
33A
37A

Time dimension -->


:
-1.174359
:
0
:
-1.174359
:
0
:
0
:
-1.174359
:
0
:
-1.174359
:
0
:
0

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

b. NAINTERP: linear interpolation


For series that have trends, replacing all missing values with a single value may be inappropriate. One
alternative is linear interpolation, which is accomplished via the NAINTERP function. (For points at the
ends of the data series, NAINTERP uses linear extrapolation.) The syntax of NAINTERP is the same as the
one-argument form of NAFILL:
TROLL Command: do prt.( nainterp (doughnut) ) ;
NAINTERP(DOUGHNUT):
DOUGHNUT = LOG(VAR)
Numeric scalar timeseries -Time dimension: Periodicity 1,

1A
5A
9A
13A
17A
21A
25A
29A
33A
37A

Time dimension -->


:
-1.174359
:
0
:
-1.174359
:
-17.144652
:
-9.159506
:
-1.174359
:
0
:
-1.174359
:
-84.616522
:
-168.058685

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

c. NAGROW: growth rate (geometric) interpolation


For series that tend to grow geometrically, linear interpolation may also be inappropriate. NAGROW is the
geometric counterpart of NAINTERP. NAGROW fills in values based on the growth rate between the two
adjacent data points. (NAINTERP also extrapolates when necessary. You are no doubt aware that the results
of geometric extrapolation at long horizons can be very sensitive.)
TROLL Command: do prt.( nagrow (doughnut) ) ;

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)

Time dimension -->


:
-1.174359
-0.531394
-0.211935
-0.050182
:
0
-0.050182
-0.211935
-0.531394
:
-1.174359
-23.133512
-17.642704
-13.455155
:
-10.261534
-7.825928
-5.968421
-4.551798
:
-3.471415
-2.647465
-2.019081
-1.539846
:
-1.174359
-0.531394
-0.211935
-0.050182
:
0
-0.050182
-0.211935
-0.531394
:
-1.174359
-22.0349
-413.448362
-7757.673059
: -145559.873489 -2731189.702
-5.1246247e+007 -9.6155086e+008
: -1.8041908e+010 -3.3852649e+011 -6.3518883e+012 -1.1918265e+014

d. OVERLAY: replacing missing values with other series


Perhaps none of the canned data replacement methods meets your needs. Of course you always have the
option of replacing missing data points one at a time, but usually there is an easier way. The OVERLAY
function allows you to replace missing data by supplying your own replacement series. In the following
example, we use a 10-year centered moving average of "doughnut" as the replacement series.
TROLL Command: do hole = movavg ( doughnut, 5, 5, , true ) ;
TROLL Command: do prt.(hole) ;
HOLE:
HOLE = MOVAVG(DOUGHNUT,5,5,NA,TRUE)
Numeric scalar timeseries -Time dimension: Periodicity 1,

-4A
0A
4A
8A
12A
16A
20A
24A
28A
32A
36A
40A
44A

Time dimension -->


:
-1.174359
:
-0.393574
:
-0.437304
:
-3.170437
:
-6.2628
:
-1.174359
:
-0.393574
:
-0.437304
:
-3.033111
:
-5.988147
:
NA
:
NA
:
NA

-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

TROLL Command: do prt. ( overlay ( doughnut, hole ) ) ;


OVERLAY(DOUGHNUT,HOLE):
Numeric scalar timeseries -Time dimension: Periodicity 1,

-4A
0A
4A
8A
12A
16A
20A
24A
28A
32A
36A
40A
44A

Time dimension -->


:
-1.174359
:
-0.393574
:
-0.050182
:
-0.531394
:
-6.2628
:
-1.174359
:
-0.393574
:
-0.050182
:
-0.531394
:
-5.988147
:
NA
:
NA
:
NA

-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

Time dimension -->


:
-1.174359
:
-0.393574
:
-0.050182
:
-0.531394
:
-6.2628
:
-1.174359
:
-0.393574
:
-0.050182
:
-0.531394
:
-5.988147
:
-99
:
-99
:
-99

-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 5-year average. If that's not available, it uses a 7-year, then a 9-year, 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

TROLL Command: do h2 = movavg ( doughnut, 2, 2, , TRUE


TROLL Command: do h3 = movavg ( doughnut, 3, 3, , TRUE
TROLL Command: do h4 = movavg ( doughnut, 4, 4, , TRUE
TROLL Command: do h5 = movavg ( doughnut, 5, 5, , TRUE
TROLL Command: do h6 = movavg ( doughnut, 6, 6, , TRUE
TROLL Command: do h7 = movavg ( doughnut, 7, 7, , TRUE
TROLL Command: do h8 = movavg ( doughnut, 8, 8, , TRUE
TROLL Command: do h9 = movavg ( doughnut, 9, 9, , TRUE
TROLL Command: do prt. ( natrim ( overlay( doughnut,
Continue eq: h2, h3, h4, h5, h6, h7, h8, h9 ) ) ) ;

)
)
)
)
)
)
)
)

;
;
;
;
;
;
;
;

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

Time dimension -->


:
-1.174359
:
-1.174359
:
-0.852876
:
-0.050182
:
-0.531394
:
-23.133512
:
-1.174359
:
-0.852876
:
-0.050182
:
-0.531394
:
-22.0349
:
-22.0349

-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

e. NASQUEEZE: collapsing away missing values


If you'd rather not replace missing values, you can just get rid of them. This procedure will change the
dates of the remaining observations, so be careful with the results. They may allow you to estimate
reasonable coefficients, but the individual data points will have the wrong dates, and so, of course, will
the residuals, predicted values, and any other time series derived from the estimation process. Okay,
TROLL Command: do prt.( nasqueeze ( doughnut ) ) ;
NASQUEEZE(DOUGHNUT):
Numeric array -1 space dimension: 20

[1]:
[5]:
[9]:
[13]:

Space dimension number 1 -->


-1.174359
-0.531394
0
-0.050182
-1.174359
-23.133512
-0.211935
-0.050182

-0.211935
-0.211935
-1.174359
0

-0.050182
-0.531394
-0.531394
-0.050182

[17]:

-0.211935

-0.531394

-1.174359

-22.0349

f. combining multiple data replacement methods


Maybe one replacement method isn't enough for you. For example, compound growth rates tend to give
reasonable values for interpolation, but the extrapolated values beyond the end of the series can look
ridiculous. To be conservative, you could use geometric interpolation and linear extrapolation, as
follows:
TROLL Command: do prt.( overlay( nagrow(natrim(doughnut)),
Continue eq: nainterp(doughnut) ) );
OVERLAY(NAGROW(NATRIM(DOUGHNUT)),NAINTERP(DOUGHNUT)):
Numeric scalar timeseries -Time dimension: Periodicity 1, 1A to 40A (40 observations)
Time dimension -->
:
-1.174359
:
0
:
-1.174359
:
-10.261534
:
-3.471415
:
-1.174359
:
0
:
-1.174359
:
-84.616522
:
-168.058685

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:

// we won't do extrapolation this time


do rawdata = natrim ( doughnut ) ;
// flag observations with missing values
do nayesno = namask ( rawdata ) ;
// dates with missing values
do nadates = submat ( dates(rawdata), nayesno ) ;
// time coordinates of missing values
do badnums = date2val ( nadates ) ;
// time coordinates of non-missing values
do oknums = date2val ( subdel( dates(rawdata), nayesno ) ) ;
// values to substitute for the missing values
do substitutes = spline(oknums, nasqueeze(rawdata), badnums) ;
// replace the missing values
do cooked = setrep ( rawdata, substitutes, nadates ) ;
do prt. ( cooked ) ;

COOKED:
COOKED = SETREP(RAWDATA,SUBSTITUTES,NADATES)
Numeric scalar timeseries -Time dimension: Periodicity 1,

1A
5A
9A
13A
17A
21A
25A
29A

Time dimension -->


:
-1.174359
:
0
:
-1.174359
:
-59.797862
:
-34.192361
:
-1.174359
:
0
:
-1.174359

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

II. ORDINARY LEAST SQUARES


A. DIRECT-INPUT OPTION
Easy, if your environment (BOUNDS, SEARCH list, etc.) is already set up. Just type "ols" and then the names of the

variables (dependent variable first).


As usual TROLL will go down the SEARCH list looking for each of the variable names, and in each case it will use the
first variable it finds. TROLL automatically includes a constant term in the regression, unless you specify NOCON (or
NOCONSTANT). If necessary (if you haven't set BOUNDS yet, or if you want to change them), you can specify a string of
dates (preceded by a comma) at the end of the command. Those dates (one or more ranges) will become the new BOUNDS
and will remain in effect until you change them explicitly.
With the REGOPT command, you can specify what information you want to appear in the output. For OLS, you type
"regopt final" followed by a list of information that you want to appear in the output. The default is "regopt final
2", where "2" means "level 2 output". If you want a specific statistic in addition to the default, specify "regopt final 2
[other thing you want]". If you want as much information as you can get, specify "regopt final 4"; alternatively, for
minimal output, "regopt final 1". In addition to the default "level 2" output (described in the Reference Manual), you
can request the following:
(dependent variable mean)
(sum of residuals; normally zero)
RSQU (uncentered R-squared)
MEAN (regressor summary statistics)
PARTIAL (partial correlation coefficients)
BETA (beta-weights)
COVAR (coefficient covariances and correlations)
CORR (regressor covariances and correlations)

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:

access us type trolldb id d:\troll\samples\work\usmac.trl ;


search after save us ;
dlag dl p 4 ; /* 4-year unconstrained distributed lag on P */
ols y r p, 1975a to 1996a ;

ORDINARY LEAST SQUARES


LHS VARIABLE:

Current DL/PDL settings:


DL P
4
NOB = 22
NOVAR = 6 NCOEF = 6
RANGE: 1975A to 1996A
RSQ =
0.486788
F(5/16) =
3.035236
SER =
1.651874
DW(0) =
2.574826
MAX:HAT =
0.728524
DFFITS =
3.902183
COEF
R
P
P(-1)
P(-2)
P(-3)
CONST

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 end-constraint, 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:

Current DL/PDL settings:


PDL P
8
2
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

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 non-linear functional forms with OLS, provided they are linear in the coefficients. For the direct-input
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:

(write coefficients to a file)


(write regression diagnostics to a file)
FILERESULT (write specified results to a file)
FILESTAT (write regression statistics to a file)
FILERECALL (write "RECALLable" results [see below] to a file)
SAVECOEF (store coefficients)
SAVEDIAG (store regression diagnostics)
SAVERESULT (store specified results)
SAVERECALL (store "RECALLable" results)
SAVESTAT (store regression statistics)
FILECOEF
FILEDIAG

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. MODEL-INPUT OPTION
The model-input option is similar in many respects to the direct-input 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 model-input 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 model-input 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 model-input
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

Current DL/PDL settings:


DL A2
4

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

ORDINARY LEAST SQUARES


2 :

Y = B0+B1*R+B2*P

Current DL/PDL settings:


PDL B2
8
2

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

ORDINARY LEAST SQUARES


3 :

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

Current DL/PDL settings:


PDL B2
8
2

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

ORDINARY LEAST SQUARES


3 :

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

III. ADVANCED SINGLE-EQUATION TECHNIQUES


A. DISTRIBUTED LAGS
See the discussion above.

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 second-order autocorrelation. As with OLS, both the direct-input option and the model-input option are
available. The commands are SCC ("serial correlation correction") and SCCMOD (the model-input option).
To use SCC or SCCMOD, you have to choose a correction procedure, either the Cochrane-Orcutt procedure or the
Hildreth-Lu procedure. In conjunction with this, you choose either first- or second-order AR correction. The options are
CORC, CORC2, HILU, and HILU2. The next example does a Cochrane-Orcutt AR(2) correction -- and demonstrates how
important the serial correlation correction can be for single-equation 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 24-month 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 one-year treasury bills ("r"). The unemployment rate ("u") appears

contemporaneously on the right-hand 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 user-set CONOPT CONDWARN.
LHS VARIABLE:

Current DL/PDL settings:


PDL I
24
2
NOB = 168
NOVAR = 26 NCOEF = 5
RANGE: 1983M01 to 1996M12
RSQ =
0.329469
CRSQ =
F(4/163) =
20.022757
PROB>F =
SER =
1.761244
SSR =
DW(0) =
0.092025
COND =
MAX:HAT =
0.121795
RSTUDENT =
DFFITS =
0.527993
COEF

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.14105108e-005
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.89936035e-006
4.135303 5.66077332e-005
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 ;
CORCHANE-ORCUTT 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

Current DL/PDL settings:


PDL I
24
2
NOB = 166
NOVAR = 28 NCOEF = 7
RANGE: 1983M01 to 1996M12
RSQ =
0.974261
CRSQ =
F(4/0) =
1003.074979
PROB>F =

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:

C. TWO-STAGE LEAST SQUARES


Another OLS assumption which is often impractical when dealing with timeseries is the assumption that the model's
error term is uncorrelated with the independent variables. This type of violation becomes particularly virulent when
forward-looking behavior is involved. In principle, an equation describing forward-looking behavior specifies that an
agent's behavior depends on some as-yet-unrealized, but still anticipated, outcome. The problem, of course, is that any
surprise element of that outcome will surprise both the agent (whose response is reflected in the error term) and the
econometrician (who measures the independent variables) [1].
The first line of defense against such violations is two-stage least squares, an instrumental variables technique in which
the independent variables are projected on a set of instruments, and resulting projections are used as regressors in an
OLS estimation. TROLL implements two-stage least squares in the tasks TSLS and TSLSMOD (the direct-input and
model-input options). The usage is very much like that of the corresponding OLS tasks, except that one must first create
a list of preliminary regressors (instruments), which, to give the proper results, should include all the predetermined
independent variables (those which do not require instrumentation).
The command CRPREG creates a list of preliminary regressors. Note that one must specify a constant term explicitly.
The following (admittedly contrived) example estimates the (U.S. 1-year treasury bill) interest rate as a function of the
(corresponding) prospective inflation rate, first by OLS and then by TSLS. The following variables are used as
preliminary regressors: the unemployment rate, the normalized help wanted index, a quadratic distributed lag the
inflation rate, and a quadratic distributed lag of the rate of M-2 growth. Lagged interest rates are also included in both
preliminary and final regressions, to deal with the problem of serial correlation. Finally, the preliminary regressor list
includes a constant term, which, as noted above, must be explicitly specified. Since the constant term is predetermined
(could not possibly be correlated with the error term), it should normally be included in the preliminary regressor list if
it exists in the second-stage regression (as it does by default).
There is one more wrinkle here. TROLL does not contain direct support for polynomial distributed lags as preliminary
regressors. It is therefore necessary to calculate explicitly the "scrambled" variables that serve as regressors to represent

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 two-stage 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:

do i.poly = scramble'f (i, 24, 2, "none");


do ip1 = i.poly [1];
do ip2 = i.poly [2];
do ip3 = i.poly [3];
access m2 type formdata id m2.frm ;
search m2 ;
do m2.poly = scramble'f (del(m2), 12, 2, "none");
do mp1 = m2.poly [1];
do mp2 = m2.poly [2];
do mp3 = m2.poly [3];
access nhwi type formdata id nhwi.frm ;
search nhwi ;
crpreg u r(-1) r(-2) ip1 ip2 ip3 mp1 mp2 mp3 nhwi const;

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);

The OLS regression produces the following result:


TROLL Command: bounds 1985m1 to 1996m12 ;
TROLL Command: ols r i.future r(-1) r(-2);
ORDINARY LEAST SQUARES
LHS VARIABLE:

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. Two-stage least squares rides in on a white horse and saves
the day:
OLS Command: tsls r i.future r(-1) r(-2);
TWO-STAGE 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.16764608e-005

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:

D. NON-LINEAR LEAST SQUARES


Such variations on OLS often suffice for the treatment of recalcitrant data. An altogether different problem appears
when the underlying model is not amenable to a linear specification. Whenever possible, it is desirable to transform a
non-linear model into linear form, so as to take advantage of the analytic solution to the linear least-squares problem. In
many cases, however, no such transformation exists.
Fortunately, TROLL has the ability to perform efficient non-linear minimization using the NL2SOL minimization
algorithm. NL2SOL is designed to minimize an arbitrary sum of squares. Accordingly, any single-equation specification
that can be cast as a least-squares problem is a candidate for estimation by TROLL's non-linear least squares task, NLS.
requires some preparation. Although the task will attempt to run using default starting values (0.5 for all
coefficients), those default values are seldom appropriate for the problem at hand. In all but the most well behaved
problem, the default starting values are likely to produce inappropriate results, such as convergence to a local minimum
far from the true solution.
NLS

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 non-linear models can be approximated first with linear models that can be estimated analytically to
provide starting values. Also, many complicated non-linear models can be approximated first with simpler non-linear
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:

access international type formdata id mark3.frm;


search international_ja ;
drange 1974a to 1997a ;
do capital = k*cu/100 ;

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*(1-unr/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 Cobb-Douglas production function:
TROLL Command: bounds 1974a to 1997a ;
TROLL Command: usemod ;

New model: (nameless)


TROLL Command: addeq bottom, cobbdoug: gdp'n =
Continue eq: cdscale'c * capital**alpha'c * labor**(1-alpha) ;

The second equation represents the simple linear production function:


MODEDIT Command: addeq bottom, linear: gdp = betak'c*capital + betal'c*labor ;

The third equation represents the Leontief input-output production function:


MODEDIT Command: addeq bottom, leontief: gdp = min (ck'c*capital, cl'c*labor) ;

The fourth equation represents a form of the constant-returns-to-scale Constant Elasticity of Substitution production
function:
MODEDIT Command: addeq bottom, ceshom1: gdp = scale'c * (
Arguments or ')': ( (1-alpha)**(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*(1-alpha)**2 . As power approaches
zero, the function approaches to Cobb-Douglas function (equation 1) with cdscale = scale*(1-alpha)**
(1-alpha)*alpha**alpha. Finally, as power approaches negative infinity, the function approaches the Leontief function
(equation 3) with ck = scale*alpha and cl = scale*(1-alpha).
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 ')': ( (1-alpha)**(1+power) ) * labor**power +
Continue eq: ( alpha**(1+power) ) * capital**power ) ** (homogeneity'c/power) ;

Here is the complete "model":


MODEDIT Command: print ;
Symbols:
ENDOGENOUS :
GDP
EXOGENOUS :
CAPITAL LABOR
COEFFICIENT :
ALPHA BETAK

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**(1-ALPHA)
GDP = BETAK*CAPITAL+BETAL*LABOR
GDP = MIN(CK*CAPITAL,CL*LABOR)
GDP = SCALE*((1-ALPHA)**(1+POWER)*LABOR**POWER+ALPHA**(1+POWER)*
CAPITAL**POWER)**(1/POWER)
GDP = SCALE*((1-ALPHA)**(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 Cobb-Douglas 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**(1-ALPHA)
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

NLS Command: do cdscale = exp (-2.793665), alpha = .509261 ;


NLS Command: nls 1 ;
Coefficient convergence
Iterations in current NLS estimation : 3
1 : GDP = CDSCALE*CAPITAL**ALPHA*LABOR**(1-ALPHA)
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.966956
COEF

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
residual-based 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

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
CAPITAL
LABOR

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.90641970e-005

PROB>|T|

124.786341
103.148512

0
0

OLS Command: olsmod 2 ;


ORDINARY LEAST SQUARES
2 :

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.90641970e-005

PROB>|T|

124.786341
103.148512

0
0

OLSMOD Command: nls 2 ;


Relative SSR and coefficient convergence
Iterations in current NLS estimation : 3
2 : 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.791093
COEF
BETAK
BETAL

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.90641970e-005

PROB>|T|

124.786341
103.148512

0
0

Looking at these results, we can say that this model fits better than the Cobb-Douglas model, since the SSR is smaller
(and, equivalently, the R-squared 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

NLS Command: do ck = 0.736798, cl = 0.008053 ;


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.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

should now be ready to estimate.

NLS Command: nls 4 ;


WARNING 6001
NA(s) returned where operand values did not allow an operation.
The following problem(s) occurred during binary operator:
-- division by zero

WARNING 2106
Condition number exceeds the current user-set CONOPT CONDWARN.
Coefficient convergence
Iterations in current NLS estimation : 3
4 : GDP = SCALE*((1-ALPHA)**(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 anti-complementarity 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

addeq bottom, robust: gdp = scale * (


')': if (absv (power) < .0001) then ( // Cobb-Douglas
')':
// trap single-factor cases
')':
if (absv (alpha) < .0001) then (labor) else (
')':
if (absv (1-alpha) < .0001) then (capital) else (
')':
// full Cobb-Douglas
')':
scale * alpha**alpha * (1-alpha)**(1-alpha)
* labor**(1-alpha) * capital**alpha
) ) ) else ( if (power < -30) then ( // Leontief
')':
// trap single-factor cases
')':
if (absv (alpha) < .0001) then (0) else (
')':
if (absv(1-alpha) < .0001) then (0) else (

Arguments or ')':
// full Leontief
Arguments or ')':
min (alpha*capital, (1-alpha)*labor) ) ) ) else (
Arguments or ')':
// general case
Arguments or ')':
((1-alpha)**(1+power)*labor**power
Continue eq:
+alpha**(1+power)*capital**power ) **(1/power)
Continue eq:
) ) ) ;
MODEDIT Command: print equation 6 ;
Equations:
6: ROBUST

GDP = SCALE*(IF (ABSV(POWER) < 0.0001) THEN (IF (ABSV(ALPHA) <


0.0001) THEN LABOR ELSE (IF (ABSV(1-ALPHA) < 0.0001) THEN
CAPITAL ELSE (SCALE*ALPHA**ALPHA*(1-ALPHA)**(1-ALPHA)*LABOR**(1ALPHA)*CAPITAL**ALPHA))) ELSE (IF (POWER < -30) THEN (IF (ABSV(
ALPHA) < 0.0001) THEN 0 ELSE (IF (ABSV(1-ALPHA) < 0.0001) THEN 0
ELSE (MIN(ALPHA*CAPITAL,(1-ALPHA)*LABOR)))) ELSE (((1-ALPHA)**(
1+POWER)*LABOR**POWER+ALPHA**(1+POWER)*CAPITAL**POWER)**(1/POWER
))))

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 user-set 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(1-ALPHA) < 0.0001) THEN CAPITAL ELSE
(SCALE*ALPHA**ALPHA*(1-ALPHA)**(1-ALPHA)*LABOR**(1-ALPHA)*CAPITAL**ALPHA)))
ELSE (IF (POWER < -30) THEN (IF (ABSV(ALPHA) < 0.0001) THEN 0 ELSE (IF
(ABSV(1-ALPHA) < 0.0001) THEN 0 ELSE (MIN(ALPHA*CAPITAL,(1-ALPHA)*LABOR))))
ELSE (((1-ALPHA)**(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 Cobb-Douglas 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 Cobb-Douglas 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 user-set 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(1-ALPHA) < 0.0001) THEN CAPITAL ELSE
(SCALE*ALPHA**ALPHA*(1-ALPHA)**(1-ALPHA)*LABOR**(1-ALPHA)*CAPITAL**ALPHA)))
ELSE (IF (POWER < -30) THEN (IF (ABSV(ALPHA) < 0.0001) THEN 0 ELSE (IF
(ABSV(1-ALPHA) < 0.0001) THEN 0 ELSE (MIN(ALPHA*CAPITAL,(1-ALPHA)*LABOR))))
ELSE (((1-ALPHA)**(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

IV. MULTIPLE EQUATION TECHNIQUES


This section is rather incomplete. Accordingly, you may find it helpful to refer to the GREMLIN section in the TROLL Reference
Manual.
TROLL offers three techniques for simultaneous estimation: THREESLS (three-stage least squares), ZELLNER (Zellner's
"Seemingly Unrelated Regressions"), and FIML (Fixed Information Maximum Likelihood). The three are subsumed under the
name "GREMLIN", but "GREMLIN" is only a name, not a command. Each method is invoked via its own name. The syntax
for the three methods is essentially the same, except for the name of the method.
The ZELLNER technique is designed to deal with the situation where equations in disjoint sets of variables exhibit cross-equation
correlation in the error terms. (The classic example is a set of parallel equations for different countries in the same region.)
THREESLS and FIML are alternative approaches to estimation of equations that have commonality in both the error terms and the
set of regressors.
As with NLS and OLSMOD, GREMLIN operates on a pre-existing TROLL model (the current working model). Unlike those other
tasks, GREMLIN estimates the entire model at once instead of estimating equations one at a time.
Like NLS, GREMLIN does explicit optimization rather than solving analytically, so starting values and optimization parameters
matter, and the algorithm can terminate without a solution even when a solution exists. Set parameters with the CONOPT
command.
You have a choice of algorithms (BFGS, DFP, or MINOPT), and there are certain restrictions on things like the number of variables
and equations and time periods and so on. (You can also do TWOSLS -- two-stage least squares -- for which the syntax and
parameters are similar to THREESLS.) With THREESLS (and TWOSLS), and sometimes with ZELLNER, it is possible to select and
modify preliminary regressors using PREREG and CHPREG. You can save results; you can look at options; you can supply starting
guesses for various things; and the usual considerations about BOUNDS apply. You can get detailed iteration output if you want,
and you can get estimated covariance matrices, and so on. Refer to the manual for details, including examples.
The usage goes something like this. First you type the name of the estimation method (along with bounds, if necessary), say,
"zellner;". If you're lucky, nothing happens -- nothing visible. Behind the scenes, GREMLIN analyzes the model and sets up
the estimation environment.
Now you're inside the GREMLIN task. At this point you can type a bunch of things about how you want it to do the estimation
-- do you want to change the options; do you want to save the results; do you want to use different preliminary regressors; and
so on. Or you can skip all that and accept the defaults. (Be warned that the estimation often won't work quite right until you
start tweaking it. Nonetheless, the defaults may be worth a shot, especially since you won't have much idea how to tweak it
until you figure out why it didn't work the first time.)
OK, so now you're ready to estimate. (Maybe you were ready a long time ago, but now the computer's ready too: Non si costrui
Roma in un giorno, or however it goes.) Then you type "estimate;". If you're lucky, the machine spits out a bunch of
coefficients and standard errors and stuff. And if you're very lucky, they actually make sense.
More likely you get either an error message or garbage results. If you didn't set any options at all, you probably get the "failed
to converge in 10 iterations" message, which usually means you need to set CONOPT STOP to something greater than 10. But if
even those ten iterations took a long time to run, something worse is probably going on.
So perhaps you set "conopt stop 50" and ESTIMATE again. Then you might get a more serious error message, the content of
which should give some clue about what to do next. Or perhaps you see some results full of ones and zeros and NAs and 1e30s
and the like. It's time to start tweaking! (Remember the ESTIMATE command; you'll be using it a lot.) In particular, you may find
it useful to experiment with CONOPT parameters until you find something that works for you.
Footnotes

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

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter Eight. Simulating A Model


I. BASIC SIMULATION
A. STATIC SIMULATION
B. DYNAMIC SIMULATION
C. MULTIPLE-EQUATION SIMULATION
D. NON-LINEAR SIMULATION
E. USING FUNCTIONS
F. FORWARD-LOOKING SIMULATION
G. CALCULATING ADD FACTORS
H. CHOOSING AN ALGORITHM
1. Newton-Raphson
2. Relaxation (First-Order) Methods
a. gauss-seidel
b. jacobi
c. successive over-relaxation (SOR)
d. fast gauss-seidel (FGS)

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

II. SIMULATION CHOICES IN TROLL


A. DATE RANGE
B. ALGORITHM
C. SYMBOL TYPES
1. Types of Symboltypes
2. Symboltype Details
D. HOW "DYNAMICALLY" TO SIMULATE
1. Dynamic Lags
2. Dynamic Leads
E. WHERE TO GET STARTING GUESSES
F. SIMULATION PARAMETERS
G. WHETHER TO SOLVE SIMULTANEOUSLY

III. SIMULATION REQUIREMENTS


A. MODEL
B. DATA

IV. THINGS TO KEEP IN MIND


A. ADVANTAGE OF A LOGICAL NAMING STRUCTURE
B. CHECK YOUR MODEL BEFORE SIMULATING
C. DEFINITION SYMBOLS DO NOT USE DATA

Portable TROLL User's Guide

Chapter Eight. Simulating A Model


I. BASIC SIMULATION
This section takes a simple simulation example through several revisions to show the basic usage of TROLL's simulator with
different model features. In real life, with richer, more complicated models and data that don't always cooperate, the process is
not likely to go quite as smoothly as it does here. Much of the remainder of this and the next two chapters, particularly the
chapter on "simulation troubleshooting" will address the difficulties that may appear. But first things first.

A. STATIC SIMULATION
The "simplest" kind of model to simulate is a static, linear, single-equation 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 left-hand side. Just declare the variable as ENDOGENOUS when you set up the model.
The following "static multiplier-accelerator 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*(y-t*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:

Total investment equals total savings


I*Y+X = Y+M*Y-C*(Y-T*Y)-G

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
semi-permanent 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]:

Space dimension number 1 -->


480.713658
477.250849
519.448436
533.975668
524.60376
543.892823
602.162089
631.143779
679.875902
666.540362

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 ;

Now we can simulate with the new tax rate:


SIMULATE Command: simstart 1974a ;
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:
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 "divider-decelerator" 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 prior-year income ;
MODEDIT Command: changeq /i*y/i*y(-1)/ bottom ;
MODEDIT Command: changeq/(y-t*y)/((1-h)*(y-t*y)+h*(y(-1)-t*y(-1)))/bottom;

MODEDIT Command: filemod dynamic ;


TROLL Command: quit ;
TROLL Command: prtmod comment ;
Symbols:
ENDOGENOUS :
Y
- National income/output
EXOGENOUS :
X
- Export demand
POLICY :
G

- Government purchases

COEFFICIENT
C
H
I
M

:
-

Rate of consumption out of disposable income


Fraction of consumption based on prior-year income
Rate of investment "acceleration" as output increases
Fraction of national income spent on imports

PARAMETER :
T
- Tax rate
Equations:

1:

Total investment equals total savings


I*Y(-1)+X = Y+M*Y-C*((1-H)*(Y-T*Y)+H*(Y(-1)-T*Y(-1)))-G

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. MULTIPLE-EQUATION 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, self-explanatory 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*((1-h)*(y-t*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

:
-

Rate of consumption out of disposable income


Fraction of consumption based on prior-year income
Rate of investment "acceleration" as output increases
Fraction of national income spent on imports

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+IMPORT-CONS-G
Consumption function
4: CONS
CONS = C*((1-H)*(Y-T*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*(e-e0) ;
MODEDIT Command: eqcom bottom Export demand ;
MODEDIT Command: addeq bottom FOREX: r = rus + a*(e-e0) ;
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

:
-

Exchange rate sensitivity to interest rate differential


Export sensitivity to exchange rate
Rate of consumption out of disposable income
Parity exchange rate

F
H
I
J
M

Export sensitivity to foreign income


Fraction of consumption based on prior-year income
Rate of investment "acceleration" as output increases
Investment sensitivity to interest rate
Fraction of national income spent on imports

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+IMPORT-CONS-G
Consumption function
4: CONS
CONS = C*((1-H)*(Y-T*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*YUS-B*(E-E0)
International financial market equilibrium
8: FOREX
R = RUS+A*(E-E0)

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. NON-LINEAR 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 "out-of-block" 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 "pseudo-nonlinearities". 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+IMPORT-CONS-G
CONS = C*((1-H)*(Y-T*Y)+H*(Y(-1)-T*Y(-1)))
IMPORT = M*Y
DOMINVEST = I*Y(-1)-J*R**P
X = F*YUS-B*(E**S-E0)
R = RUS+A*(E-E0)

... And now for something completely nonlinear... We'll revise the consumption function to incorporate a more
sophisticated habit-formation 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*(h-cons(-1)/(y-t*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

:
-

Exchange rate sensitivity to interest rate differential


Export sensitivity to exchange rate
Rate of consumption out of disposable income
Parity exchange rate
Export sensitivity to foreign income
Fraction of consumption based on prior-year income
Rate of investment "acceleration" as output increases
Investment sensitivity to interest rate
Fraction of national income spent on imports
Investment function power parameter
Export demand function power parameter

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+IMPORT-CONS-G
Consumption function
4: CONS
CONS/CONS(-1)-1 = C*(H-CONS(-1)/(Y-T*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*YUS-B*(E**S-E0)
International financial market equilibrium
8: FOREX
R = RUS+A*(E-E0)
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 ?e-e0?log(e/e0)? forex ;
MODEDIT Command: changeq ?e**s-e0?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

:
-

Exchange rate sensitivity to interest rate differential


Export sensitivity to exchange rate
Rate of consumption out of disposable income
Parity exchange rate
Export sensitivity to foreign income
Fraction of consumption based on prior-year income
Rate of investment "acceleration" as output increases
Investment sensitivity to interest rate
Fraction of national income spent on imports
Investment function power parameter
Export demand function power parameter

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+IMPORT-CONS-G
Consumption function
4: CONS
CONS/CONS(-1)-1 = C*(H-CONS(-1)/(Y-T*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*YUS-B*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 non-positive 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. FORWARD-LOOKING SIMULATION
Everything so far has simply been a prelude. We're now ready for the main event: forward-looking 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 forward-looking 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 ;

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

:
-

Exchange rate sensitivity to interest rate differential


Export sensitivity to exchange rate
Rate of consumption out of disposable income
Parity exchange rate
Export sensitivity to foreign income
Fraction of consumption based on prior-year income
Rate of investment "acceleration" as output increases
Investment sensitivity to interest rate
Fraction of national income spent on imports
Investment function power parameter
Export demand function power parameter

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+IMPORT-CONS-G
Consumption function
4: CONS
CONS/CONS(-1)-1 = C*(H-CONS(-1)/(Y-T*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*YUS-B*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 forward-looking
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 Forward-Looking 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 forward-looking simulation looks like:

SIMULATE Command: simulate stack 20 ;


Constructing stacked-time incidence matrix and code.
Simulations can start from 1975A to 1995A and must end by 1995A.
SIMULATE Command: list solutions endogenous ;
SIMULATE Command: simstart 1975a ;
SIMULATE Command: dosim 20 ;
Date:
What:
Value:
1975A
Solution: X [1975A]
60.55083
[1976A]
70.139328
[1977A]
80.112839
[1978A]
88.568098
[1979A]
93.611744
[1980A]
94.773581
[1981A]
100.999735
[1982A]
97.620867
[1983A]
104.586129
[1984A]
116.542203
[1985A]
122.837069
[1986A]
130.867797
[1987A]
138.962545
[1988A]
148.281306
[1989A]
156.81423
[1990A]
162.392391
[1991A]
164.436804
[1992A]
173.273723
[1993A]
181.506639
[1994A]
190.471904
Y [1975A]
479.010047
[1976A]
490.694271
[1977A]
496.061115
[1978A]
506.768279
[1979A]
517.218295
[1980A]
522.651687
[1981A]
528.097596
[1982A]
529.105653
[1983A]
545.334132
[1984A]
562.6046
[1985A]
571.376619
[1986A]
586.707442
[1987A]
600.310562
[1988A]
614.755847
[1989A]
635.726433
[1990A]
655.642537
[1991A]
669.104311
[1992A]
688.549666
[1993A]
706.227218
[1994A]
727.670149
CONS [1975A]
296.896178
[1976A]
300.070429
[1977A]
303.297536
[1978A]
307.392894
[1979A]
312.093442
[1980A]
316.489323
[1981A]
320.653307
[1982A]
323.947486
[1983A]
328.940693
[1984A]
335.330404
[1985A]
341.527085
[1986A]
348.53698
[1987A]
355.916835
[1988A]
363.70281
[1989A]
372.726924
[1990A]
382.552368
[1991A]
392.10448
[1992A]
402.277182
[1993A]
412.687934
[1994A]
423.806455
DOMINVEST [1975A]
47.433453
[1976A]
47.234046
[1977A]
48.515081
[1978A]
49.022873
[1979A]
49.956434
[1980A]
50.906457
[1981A]
51.519179
[1982A]
52.108665
[1983A]
52.274091
[1984A]
53.902752
[1985A]
55.56065
[1986A]
56.476073
[1987A]
58.047901
[1988A]
59.388276
[1989A]
60.730355
[1990A]
62.804182

[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).
Forward-looking 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 interest-rate policy that simply tracks the U.S.
interest-rate.
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 interest-rate parity, but our artificial data has interest-rate 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 1980-1983 period.
SIMULATE
SIMULATE
SIMULATE
SIMULATE
Date:
1975A

Command:
Command:
Command:
Command:

do r = rus + if (dates(r)>1979a and dates(r)<1984a) then 1 else 0 ;


newvals 1980a to 1983a r ;
simstart 1975a ;
dosim 20 ;
What:
Value:
Solution: E [1975A]
1.636049
[1976A]
1.636049
[1977A]
1.636049
[1978A]
1.636049
[1979A]
1.636049
[1980A]
1.636049
[1981A]
1.621498
[1982A]
1.607401
[1983A]
1.593
[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

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 stacked-time 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 interest-rate 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 date-range 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

G. CALCULATING ADD FACTORS


An alternative approach to examining the effects of shocks is to use empirical data as the baseline. To do so, you must
make the model fit the empirical data. The usual way of doing so is to use "adjustment factors" or "add factors" -exogenous variables that represent the residuals from the original model. When you revise the model to include the add
factors, it will fit exactly the empirical data. Then you can "shock" the data (leaving the add factors unchanged) and
compare the new results to the historical experience.
Add factors are also used to make subjective adjustments to models, so that results can incorporate aspects of modelers
thinking that cannot be formulated explicitly in terms of objective modelling constructs. That use of add factors is
generally beyond the scope of this Guide. For out-of-sample observations which do not correspond to any empirical
data, the question of how to set add factors becomes subjective. Generally the assumption here will be that add factors
represent unpredictable residuals and therefore should be set to zero when no data exist.
This section concerns the calculation of add factors from existing data. Before doing so, let's revise the previous model
to include add factors. In theory, add factors are not necessary for identity equations. In practice, equations often do not
hold exactly when data from the usual statistical sources are used. In theory, the purpose of add factors is not to
compensate for statistical discrepancies but to represent aspects of particular historical experience that are not captured
by the underlying model. In practice, add factors are often used for the former purpose. Here we create add factors only
to represent the residuals in each of the model's behavioral equations. The problem with this limited strategy will
become apparent.
SIMULATE Command: addsym exogenous res_cons res_import res_dominvest res_x res_e ;
MODEDIT Command: symcom res_cons Add factor for consumption ;
MODEDIT Command: symcom res_import Add factor for imports ;
MODEDIT Command: symcom res_dominvest Add factor for domestic investment ;
MODEDIT Command: symcom res_x Add factor for exports ;
MODEDIT Command: symcom res_e Add factor for exchange rate ;
MODEDIT Command: changeq ?cons/?(cons-res_cons)/? cons ;
MODEDIT Command: changeq /=/= res_import+/ import ;
MODEDIT Command: changeq /=/= res_dominvest +/ invest ;
MODEDIT Command: changeq /=/= res_x +/ export ;
MODEDIT Command: changeq /= e/= (e-res_e)/ forex ;
MODEDIT Command: filemod addfactors ;
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 :
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

Exchange rate sensitivity to interest rate differential


Export sensitivity to exchange rate
Rate of consumption out of disposable income
Parity exchange rate
Export sensitivity to foreign income
Fraction of consumption based on prior-year income
Rate of investment "acceleration" as output increases
Investment sensitivity to interest rate
Fraction of national income spent on imports
Investment function power parameter
Export demand function power parameter

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+IMPORT-CONS-G
Consumption function
4: CONS
(CONS-RES_CONS)/CONS(-1)-1 = C*(H-CONS(-1)/(Y-T*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*YUS-B*LOG(E**S/E0)
International financial market equilibrium
8: FOREX
1+R/100 = (E-RES_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 non-simultaneous 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.

SIMULATE Command: simstart 1975a ;


SIMULATE Command: dosim 20 ;

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 re-load 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 stacked-time 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:

Time dimension -->


2.339042
1.919495

1974A to 1996A (23 observations)

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:

Time dimension -->


480.713658
519.448436
524.60376
602.162089
679.875902
706.007872

1974A to 1996A (23 observations)

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:

do r = r + if (dates(r)>1982a and dates(r)<1987a) then 5 else 0;


newvals 1983a to 1986a r ;
simstart 1975a ;
list solutions e y ;
dosim 20 ;
What:
Value:
Solution: Y [1975A]
483.325809
[1976A]
496.443967
[1977A]
507.992739
[1978A]
526.698394
[1979A]
542.83232
[1980A]
532.898726
[1981A]
525.851682
[1982A]
534.016605
[1983A]
552.810554
[1984A]
567.023138
[1985A]
590.364488
[1986A]
619.443691
[1987A]
652.745565
[1988A]
685.811252
[1989A]
702.207385
[1990A]
706.825493
[1991A]
694.974416
[1992A]
692.712447
[1993A]
707.413774
[1994A]
737.692827
E [1975A]
2.587473
[1976A]
2.157272
[1977A]
2.077159
[1978A]
2.243709
[1979A]
2.441832
[1980A]
2.638326
[1981A]
2.326071
[1982A]
2.048979
[1983A]
1.811003
[1984A]
1.555662
[1985A]
1.448927
[1986A]
1.544328
[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 shocked : e y ;

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. Newton-Raphson
The default Newton-Raphson 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 non-assignability 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.

2. Relaxation (First-Order) Methods


Relaxation methods work by repeatedly solving the model one-equation-at-a-time and substituting the results
into the model for subsequent solutions. The general advantage of such methods is that they do not, in their pure
form, depend on a linear approximation. Therefore, they may perform better than the Newton-Raphson method
in the early phase of solving a highly nonlinear model when the initial guess is far from the true solution.
Relaxation methods have two primary disadvantages. First, they converge slowly in the neighborhood of the
solution. Second, they require a specific pairing of equations with endogenous variables. Results may be
sensitive to the pairing (normalization) chosen, some pairings (normalizations) may produce unstable results,
and in some cases no normalization will be possible.
In their pure form, relaxation methods require that each equation be "normalized", that is, solved algebraically
for its assigned variable, before the algorithm begins. TROLL avoids this requirement by using a linear
approximation (at each iteration) for the dependence of each equation on its assigned variable. If the equations
are already normalized, of course, this dependence is already linear, so the approximation has no effect.
a. gauss-seidel
The most "standard" of the relaxation methods is the Gauss-Seidel algorithm. Under this algorithm,
solution values from a given equation during a given iteration are substituted into subsequent equations
during the same iteration. Thus, the algorithm makes full use of the information gained from a given
equation solution. Use "simulate gauss;".
b. jacobi
The Jacobi method goes through each iteration completely before updating the variable values. This is
generally less efficient than Gauss-Seidel, but it is simpler and therefore often useful for debugging. Use
"simulate jacobi;".
c. successive over-relaxation (SOR)
The SOR method is like Gauss-Seidel, but it applies an over-relaxation factor to each variable after each
time its equation is solved. Thus, when Gauss-Seidel goes from X[i](k) to X[i](k+1), SOR goes from
X[i](k) to X[i](k)+R*(X[i](k+1)-X[i](k)), where R is the over-relaxation factor. In TROLL, the
over-relaxation factor is set by CONOPT DAMP.
d. fast gauss-seidel (FGS)
The FGS method is like SOR, but the factor is applied to all variables at the end of each full iteration,
rather than to each variable after its equation is solved. In TROLL, the factor for FGS is set by CONOPT
FGS.

3. Stacked Time
There is OLDSTACK and NEWSTACK (the default). NEWSTACK is usually better.
You can also use the Fair-Taylor macro (&FT), but why bother?

I. REPORTING AND SAVING RESULTS


1. Saving Results with SAVESIM and FILESIM
The command "savesim results endogenous;" would save simulated values for the ENDOGENOUS variables in
locations prefixed by "results_", so you end up with "results_x" and "results_y" if x and y are the ENDOGENOUS

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. Printing Results with &PRTDSET


By now you're probably sick of paging back and forth trying to compare columns of numbers from different
simulations. There's actually a much easier way. If you save the results of several simulations using SAVESIM or
FILESIM, you can display them side-by-side using &PRTDSET. You can learn about &PRTDSET in the Reference
Manual. To get you started, here's an example using the results from the earlier simulations:
SIMULATE Command: do actual_y = y ;
SIMULATE Command: do actual_e = e ;
SIMULATE Command: &prtdset variable e y, range all, dsets actual baseline shocked ;
Data Set by Variable
E
ACTUAL
1974A
1975A
1976A
1977A
1978A
1979A
1980A
1981A
1982A
1983A
1984A
1985A
1986A
1987A
1988A
1989A
1990A
1991A
1992A
1993A
1994A
1995A
1996A

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

Data Set by Variable


Y
ACTUAL
1974A
1975A
1976A
1977A
1978A
1979A
1980A
1981A
1982A
1983A
1984A
1985A
1986A
1987A
1988A
1989A
1990A
1991A
1992A
1993A
1994A
1995A

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

3. Plotting Results with &PLOT

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 TROLL-for-Windows 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:

&PLOT [keyword...,] argument, argument, argument ;

keyword =

VALUE
ER
FD
PCER
PCFD
COMPlete
ALPHA
NAFILL

argument =

DSETs aliasname... or
ARCHive aliasname... or
PREFIX aliasname...
RANGE rangespec...
VARIables varspec...

rangespec =

ALL (default if RANGE is not specified)


date TO date or
date :: date

varspec =

variable
symboltype
@varlist
ALL

(all symbols of this type in the current model)


(retrieve names from a string array)
(all variables in the current model)

variable =

a variable name

varlist =

the name of a string array that contains a list of variable


names to be displayed.

Usage:

Utility macro

&PLOT macro displays in a separate window the graphs of variables (or


information about the values; see PR, ER, PCER, PCFD). &PLOT must include one
VARIABLES argument. If RANGE is not specified ALL is used as default. The
ARCHIVE(DSET) argument is optional and if not specified &PLOT macro will be
looking for data according to current SEARCH/ACCESS rules. If ARCHIVE argument
is specified , then &PLOT will search for data in the location specified by
aliasname.
The arguments can be given in any order, but the ordering is
significant. Each argument (except RANGE) can include a single item or a list
of several items, e.g., the DSETS argument can include one or more filenames.
RANGE can include a single range only. If varspec is not a variable, then the
CURRENT model must already have been specified, by the USEMOD command. The
keywords ER, FD, PCER, and PCFD print information about the differences between
the values specified by the command.
If the varspec ALL is given, values for all DEFINITION, ENDOGENOUS, EXOGENOUS,
and POLICY variables in the ARCHIVEs are displayed. If a symboltype is included
in the VARIABLES argument, all variables of that symboltype in each ARCHIVE are
displayed. Otherwise, the individual variables specified in the command are
displayed. The short form indicated by upper case letters may be used in place
of any argument. If the keyword ALPHA is given, the names in the VARIABLES
argument are arranged in alphabetic order before the rest of the command is
processed.
If the keywords ER, FD, PCER, or PCFD are given, the graphs described below
are displayed, but the actual data values from the ARCHIVEs are not
automatically included. To display the data values in this case, the keyword
VALUE must be specified.
COMPLETE is equivalent to the keywords ER, FD, PCER,
PCFD, and VALUE.
The keyword NAFILL causes NA values in variables to be
displayed as zeros.
The symboltype must be defined from one of the symboltypes DEFINITION,
ENDOGENOUS, EXOGENOUS, or POLICY

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.

===============================================================================

II. SIMULATION CHOICES IN TROLL


Simulation with TROLL entails a number of choices. Most of these choices will be made by default if you don't specify a
choice, but you should be aware of the options. If you're content to accept TROLL's defaults (and assuming you already have a
properly specified model), the only choices you need to make are date range and -- if you are doing forward-looking simulation
-- dynamic leads. If so, you may prefer to read only those subsections and then skip to the section on Simulation Requirements.

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 "forward-looking" 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 Newton-Raphson algorithm.
Other possibilities are the Gauss-Seidel 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 Newton-Raphson
algorithm using SIMALG command.
If your model contains endogenous leads (in other words, if it is "forward-looking", 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 forward-looking models is to use the &FT macro provided with TROLL. &FT simulates
using the Fair-Taylor 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)

Numeric scalar timeseries -Time dimension: Periodicity 1,

1A
5A
9A
13A
17A

:
:
:
:
:

Time dimension -->


1
5
9
13
17

2
6
10
14
18

1A to 20A (20 observations)

3
7
11
15
19

4
8
12
16
20

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 2A to 21A.
SIMULATE Command: list solutions all ;
SIMULATE Command: simstart 2a ;
SIMULATE Command: dosim 10 ;
Date:
What:
Value:
2A
Solution: X
2
Y
-1
3A
Solution: X
7
Y
-5
4A
Solution: X
26
Y
-19
5A
Solution: X
97
Y
-71
6A
Solution: X
362
Y
-265
7A
Solution: X
1351
Y
-989
8A
Solution: X
5042
Y
-3691
9A
Solution: X
18817
Y
-13775
10A
Solution: X
70226
Y
-51409
11A
Solution: X
262087
Y
-191861
SIMULATE Command: drop 4a to 8a x ; /* Make x exogenous for years 4 through 8 */
SIMULATE Command: simstart 2a ;
SIMULATE Command: dosim 10 ;
Date:
What:
Value:
2A
Solution: X
2
Y
-1
3A
Solution: X
7
Y
-5
4A
Solution: X
4
Y
3
5A
Solution: X
5
Y
-1
6A
Solution: X
6
Y
-1
7A
Solution: X
7
Y
-1
8A
Solution: X
8
Y
-1
9A
Solution: X
25
Y
-17
10A
Solution: X
92
Y
-67
11A
Solution: X
343
Y
-251

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 as-yet-undefined
DEFINITION symbols on the right-hand side. Second, a DEFINITION symbol must appear alone on the left-hand
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 "what-if 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.

D. HOW "DYNAMICALLY" TO SIMULATE


1. Dynamic Lags
Most econometric simulations are "dynamic", in the sense that results from one time period become data for
another time period. In TROLL, lagged variables are treated dynamically by default -- that is, whenever
possible, results from the appropriate earlier periods are substituted for lagged variables before solving the
current period.
TROLL can also perform both "static" and "partially dynamic" simulations. A "static" simulation uses the
original input data ("historical data") for lagged variables. A "partially dynamic" simulation combines the two
approaches by periodically solving one period using historical data for the lags and then solving the subsequent
period(s) using simulation results for lags. For example, a partially dynamic simulation with a five-year refresh
interval might simulate 1970 using historical data from 1969, then simulate 1971 using the results from 1970,
simulate 1972 using the results from 1971, and so on, until 1974. Then it would simulate 1975 using historical
data from 1974.
The SIMPER command instructs TROLL to perform static or partially dynamic simulations. The form of the
command is "simper n;," where "n" is the refresh interval. So, for example, the statement "simper 1;" would
instruct TROLL to perform subsequent simulations statically. A value of zero ("simper 0;") is used to return
TROLL to fully dynamic simulation mode.

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" forward-looking 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 stacked-time 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 forward-looking 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" forward-looking 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 long-term behavior of the model rather than to produce a
reasonable-looking 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 forward-looking 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 stacked-time 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

the simulation task when you invoke it, or in response to LKDATES).

E. WHERE TO GET STARTING GUESSES


The TROLL simulator requires starting guesses for the ENDOGENOUS variables so that it can begin its solution algorithm.
By default it uses the solution from the previous time period as the starting guess for the current time period. (For the
first period being stimulated, it uses input data, since there is not yet a previous-period solution.)
If you prefer, the simulator can use input data ("historical data") from the current period to initialize the solution
algorithm in each period. This procedure might be preferable when the endogenous values are expected to vary widely
from one period to the next. To put this option into effect, issue the command, "conopt simguess current;". To restore
the default, "conopt simguess lagged;".

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.

G. WHETHER TO SOLVE SIMULTANEOUSLY


A final decision about simulation is whether to allow contemporaneous feedback by solving equations simultaneously
within a given time period. Strictly speaking, the SIMULATE task always solves simultaneously, and in most cases, you
will probably want to do so.
Occasionally, you may want to examine the behavior of several processes operating in isolation. For those occasions,
TROLL offers the FORECAST task, which behaves analogously to the SIMULATE task but solves each equation separately.
For each equation, all but one endogenous variable is treated as if it were exogenous.
You have indirect control -- via the RENORM command -- over TROLL's decision about which variable to treat as
endogenous in a given equation. You can use the LKORD command to see TROLL's pairing between variables and
equations. LKORD and RENORM will be discussed in greater detail in the next chapter under "Block Ordering" and
"Normalization" in the section on "Model Analysis".

III. SIMULATION REQUIREMENTS


The two fundamental requirements for a simulation are (1) a model to simulate, and (2) data with which to simulate the model
(usually). The model must be well-specified, and the data must include numeric values for items used in the simulation. The
design of TROLL's simulator determines the specifics of these requirements, and it places certain additional restrictions on the
model and the data. These requirements and restrictions are discussed in the following subsections.

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 left-hand-side of its "identity equation", and it may not
appear on the right-hand-side 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 one-dimensional
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 well-formulated 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
well-formulated 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 one-dimensional 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 one-dimensional 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.

IV. THINGS TO KEEP IN MIND


A. ADVANTAGE OF A LOGICAL NAMING STRUCTURE
Simulation planning begins with the modelling process. When you choose symbolnames for a large simulation model,
you should consider using a logical naming structure in which related symbols share a common prefix (or suffix). Such
common lexical elements make it easier to work with a set of symbols by using the "wildcard" syntax available in many
of TROLL's simulation commands. For example, if you begin variable names with a prefix designating a country, then
you can refer to all variables for a given country with a single word, such as "US_*". Then you can issue a command
like, "list solutions us_*;" to tell TROLL to display simulation results for the U.S.

B. CHECK YOUR MODEL BEFORE SIMULATING

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;".

C. DEFINITION SYMBOLS DO NOT USE DATA


If your database contains a variable called income, and your model includes a DEFINITION symbol called income, the two
have nothing to do with each other as far as TROLL is concerned. TROLL will never look for that variable in the
database. During simulation, TROLL will calculate the variable from its identity equation, just as if no corresponding
data object existed.
Footnotes
1. The data are necessary only to provide values for "known variables and constants" -- of which there may be none -- and starting guesses for ENDOGENOUS variables in
the first time period. Theoretically, you could simulate a model containing only identity equations, so that data would be unnecessary.

Commands
Functions
Programming

User's Guide

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter Nine. Advanced Simulation


I. CONVERGENCE ISSUES
A. PRECISION vs. EFFICIENCY
B. THE CONVERGENCE TEST AND ITS PARAMETERS
1. The Convergence Test
2. Choosing Parameters
a. CONCR
b. STOP
c. GAMMA
d. DIVCR and START
e. DAMP

C. DIFFERENCES AMONG ALGORITHMS


D. ALTERING CONVERGENCE PROPERTIES OF RELAXATION METHODS
1. Renormalizing the Equations
2. Reordering the Equations

II. MODEL ANALYSIS


A. SYMBOL TABLE ANALYSIS
B. INCIDENCE MATRIX
C. BLOCK ORDERING
D. NORMALIZATION
E. SIMULATION CODE
F. LIMITS IMPOSED BY DATA
G. EIGENANALYSIS

III. FORWARD-LOOKING SIMULATION


A. THE NATURE OF FORWARD-LOOKING SIMULATION
B. PREPARING FOR FORWARD-LOOKING SIMULATION
1. Establishing Endpoints
C. USING THE STANDARD STACKED TIME METHOD
1. Temporary Shocks
2. How Many Periods to Stack
3. OLDSTACK vs. NEWSTACK
4. Permanent Shocks
D. USING THE FAIR-TAYLOR MACRO
E. IMPERFECT FORESIGHT
1. One-Time Unanticipated Shock
2. Ongoing Shock with Unanticipated Realizations
a. multiple simulations
b. multiple explicit expectations

3. Rational Expectations with Multiple Random Draws

Portable TROLL User's Guide

Chapter Nine. Advanced Simulation


I. CONVERGENCE ISSUES
A. PRECISION vs. EFFICIENCY
Simulation of nonlinear models always entails a tradeoff between efficiency and precision. If a model is well
constructed and well behaved, TROLL can produce an arbitrarily precise solution (subject to hardware limitations) -- at
an arbitrarily high cost in terms of time and resources. The terms of the tradeoff will depend on how difficult the model
is to solve. TROLL is not designed to make that tradeoff explicitly, only to find a solution with whatever level of
precision you specify. Accordingly, if you simulate difficult models, you will likely find it useful to adjust the
convergence parameters so as to achieve the best tradeoff.

B. THE CONVERGENCE TEST AND ITS PARAMETERS


It's not obvious what one would mean -- or what one should mean -- by a level of precision. TROLL's convergence
criterion offers at least some flexibility in defining precision.
After each iteration of its solution algorithm, TROLL calculates a convergence rate for each of the ENDOGENOUS variables
in a given block of equations. It then compares that convergence rate to its convergence criterion parameter (CONCR). If
all variables have convergence rates smaller than CONCR, the block has converged.
The flexibility appears in the definition of "convergence rate". It can be a relative convergence rate, an absolute
convergence rate, or (most commonly) something in between. There is a parameter (GAMMA) to control the degree of
"absoluteness".
TROLL also has the possibility of exiting before convergence, either because it detects divergence or because it has
continued for too many iterations.

1. The Convergence Test


TROLL determines the convergence rate by taking the (absolute) change in a variable from one iteration to the
next and dividing that change by a normalization factor. The normalization factor has two terms: first, the
minimum of the current and previous iteration (absolute) value of the variable; second, the parameter GAMMA. A
relative convergence test corresponds to a GAMMA value of 0. An absolute convergence test corresponds to a GAMMA
value of Infinity. By default, GAMMA is one.
Symbolically, if we use brackets [] to index the ENDOGENOUS variables y and parentheses () to index iterations,
then the convergence rate of variable j at iteration k is:
| y[j](k) - y[j](k-1) |

gamma + min(|y[j](k)|, |y[j](k-1)|)

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 general-purpose 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 not-tooexacting application and sufficient practicability for any not-too-difficult 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 re-specify 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 too-slow 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 Newton-Raphson
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.)

C. DIFFERENCES AMONG ALGORITHMS


Even though TROLL defines convergence the same way for different simulation algorithms, the convergence
parameters really have a different meaning. TROLL defines convergence in terms of the change in the endogenous
variable estimates over "one iteration", but a Gauss-Seidel iteration is not directly comparable to a Newton-Raphson
iteration. For one thing, a Gauss "iteration" involves a separate step for each equation, with each step effectively
followed by a new set of substitutions. A Newton "iteration", on the other hand, processes all the equations in a block
simultaneously.
On a practical level, the difference in convergence patterns is of greatest concern. The Gauss-Seidel algorithm begins
robustly but does not accelerate quickly in the neighborhood of the solution. The Newton-Raphson algorithm may not
make much progress at the beginning, but it converges very quickly as it approaches the solution. (Essentially the
difference is between linear and quadratic convergence.) Therefore, the Newton-Raphson algorithm can often achieve in
reasonable time an extremely precise convergence criterion that would be completely impractical for use with the
Gauss-Seidel algorithm.

D. ALTERING CONVERGENCE PROPERTIES OF RELAXATION METHODS


Another difference between Newton-Raphson and the relaxation methods arises from the fact that the relaxation
methods process equations separately and therefore in a specific order. Changing the order of the equations, or changing
the association between variables and equations (the normalization), will affect the algorithm's convergence properties.
With Newton-Raphson, the order and association are irrelevant, since all equations (within a block) are processed at
once and with respect to all associated endogenous variables.
By changing the order and/or association of equations and variables, you may be able to improve the convergence
properties of a Gauss-Seidel simulation.

1. Renormalizing the Equations

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 Gauss-Seidel:
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 non-positive 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 non-positive 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

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

Y
CONS
IMPORT

In this example the Gauss-Seidel simulation encounters the same arithmetic failure that Newton-Raphson
encountered earlier. In earlier versions of TROLL, this would have caused Gauss-Seidel 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 Gauss-Seidel 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

SIMULATE Command: renorm 3 import ;


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 15045
Iteration limit has been reached:
Date: 1975A; Block: 6; Iteration: 11
Worst Variable: Y
Last iteration value: 1.94749e+007; Relative Change: 6.00086
Maximum Residual: Equation: 3; Value: 4.67383e+006

SIMULATE Command: conopt stop 1000 ;


SIMULATE Command: simstart 1975a ;
SIMULATE Command: dosim 20 ;
Date:
What:

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

SIMULATE Command: renorm 3 import, 4 y ;


ERROR 3213
It was not possible to normalize all equations.
Only 7 of 8 equations could be normalized.

Well, renormalization didn't work for this example. Sometimes it does help.

2. Reordering the Equations


Reordering is rather more difficult than renormalization. Essentially, you have to re-specify the model with the
equations in a different order. At the least, reordering will involve replacing two of the equations with each
other.
Whenever you reorder the equations, you will obviously end up with an exactly equivalent model, and indeed
your Newton-Raphson results should always be identical. Since relaxation methods solve the equations
separately, and since Gauss-Seidel always substitutes results from one equation into subsequent equations, the
order of the equations makes a difference.
Since the mechanics of reordering are straightforward (although often time-consuming), we won't go through an
example here. But reordering is always a possibility to consider when other techniques have failed to produce
convergence (or failed to produce sufficiently rapid convergence) in a simulation using Gauss-Seidel or a related
algorithm.

II. MODEL ANALYSIS


To successfully design and debug TROLL models you must become familiar with the analysis process used to prepare a model
for simulation. Simulation problems can often be traced to difficulties in the analysis stage. Even if a problem begins during the
simulation, you need to understand the model analysis in order to understand what happens during the simulation, and in order
to interpret diagnostics. Model analysis can also be useful in understanding the long term properties of a model.

A. SYMBOL TABLE ANALYSIS


The starting point for model analysis is the model's "symbol table," which tabulates the symbols used in the model,
along with their symboltypes and the lags or leads with which they appear. The symbol table is created when the model
is first specified. Although the symbol table contains the most basic information about the model, users are not always
aware of its contents. It's easy to make careless mistakes while specifying a model, and the result is often a symbol table
that is not as one had intended. If a simulation fails in a way that doesn't seem to make sense, the symbol table is the
first place to look for problems. The SYMTAB gives information about the status of specified symbols in the symbol table:

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 N-by-N
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

Used Unlagged in Equations


3
2
7
3
1
1
2
3

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 ;

= x1'n + x2'n + x4'n ;


y = y(-1) + x1*x2 ;
x3'n = x4**2 ;
x4 = 0.9*x1(-1) ;

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 Newton-Raphson 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 time-consuming process of estimating derivatives numerically.
Unlike block ordering and normalization, the code-generation 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".)

F. LIMITS IMPOSED BY DATA


Once TROLL has produced its simulation code, the model is ready to be matched with data and then simulated. The
possible time periods for simulation are limited by the availability of data, given the particular lags and leads on
symbols in the model. When you enter the simulation task, TROLL announces the feasible date range for simulation. If
the feasible date range is insufficient, you need to get more data for one or more of the variables. (In some cases, "to get
more data" may simply mean changing your search list to point to the correct data.) But how do you know which
variables require more data? The answer is given by the macro &LKLIMIT.
TROLL Command: usemod addfactors ;
TROLL Command: &lklimit ;
Simulations can start from 1975A; Limiting variables: CONS Y RES_CONS
RES_DOMINVEST RES_E RES_IMPORT RES_X
Simulations can start to
1994A; Limiting variables: RES_CONS RES_DOMINVEST
RES_E RES_IMPORT RES_X
Simulations must end by
1994A; Limiting variables: RES_CONS RES_DOMINVEST
RES_E RES_IMPORT RES_X

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 stacked-time incidence matrix and code.
Simulations can start from 1975A to 1994A and must end by 1994A.
SIMULATE Command: simstart 1975a ;
SIMULATE Command: lkroots ;
State-space eigenanalysis of ADDFACTORS linearized around 1975A:
There are 3 eigenvalues with modulus between 0.001 and 1000,
consisting of 3 real roots and 0 complex-conjugate 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 backward-looking model, any root with a magnitude greater than 1.0 indicates an explosive growth mode
wherein the model will fail to equilibrate.
In a forward-looking 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 long-run 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 two-period 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 log-linear coefficients derived from a linearized version of a model that is
probably neither linear nor log-linear. 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 ;
State-space eigenanalysis of ADDFACTORS linearized around 1975A:
There are 3 eigenvalues with modulus between 0.001 and 1000,
consisting of 3 real roots and 0 complex-conjugate 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

There are 18 elasticities above 0.1:


Root 1:
0.96007806
Equation 8
E
1
E
0
Root 2:
0.87155043
Equation 3
CONS
0
Y
0
Equation 4
CONS
0
CONS
-1
Y
0
Root 3:
0.08193955
Equation 1
TOTINVEST
0
TOTSAVE
0
Equation 2
DOMINVEST
0
TOTINVEST
0
Equation 3
IMPORT
0
TOTSAVE
0
Y
0
Equation 5
IMPORT
0
Y
0
Equation 6
DOMINVEST
0
Y
-1

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 ;
State-space eigenanalysis of ADDFACTORS linearized around 1975A:
There are 3 eigenvalues with modulus between 0.001 and 1000,
consisting of 3 real roots and 0 complex-conjugate 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

There are 20 partial derivatives:


Eqn

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'N-RES_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'C-1)/E'N**S'C
1
-1
-1
1
1
-1
1
-1
1
-1
-(C'C*(-(-(CONS'N(-1)*(1-T'P)/(Y'N-T'P
*Y'N))/(Y'N-T'P*Y'N))))
-((CONS'N-RES_CONS'X)/CONS'N(-1))/
CONS'N(-1)-C'C*-1/(Y'N-T'P*Y'N)
1/CONS'N(-1)
-M'C
1

Just to clean up before the next section:


SIMULATE Command: delsearch all ;

III. FORWARD-LOOKING SIMULATION


A. THE NATURE OF FORWARD-LOOKING SIMULATION
Forward-looking simulation resembles the television game show Jeopardy, in which contestants offer questions to match
the answers appearing on the show's game board. A backward-looking simulation might be designed to answer a
question like, "What will happen if the rate of technological progress increases?" A forward-looking simulation, by
contrast, must start with a premise about what will happen in the long run. So when Alex Trebec reads, "Faster
technological progress will produce higher stock prices and higher wages. Asset markets adjust faster than labor
markets," a well-prepared simulator will push its game buzzer and respond, "Why will there be a redistribution of
relative wealth from labor to capital in the short run?"
As with most figures of speech, the equivalence between Jeopardy and forward-looking simulation breaks rather quickly
when stretched. Any observant viewer will quickly realize that Jeopardy merely exchanges the forms of questions and
answers: the so-called answer is just a question that has been rephrased, and (as contestants are often unhappily
reminded) the appropriate response is just an answer stated "in the form of a question". An analogous phenomenon
might be found in a "purely" forward-looking simulation -- that is, a simulation with leads but no lags. From a structural
point of view, such a simulation is just like a backward-looking simulation, except that we interpret the time sequence as
running in reverse.
Most interesting forward-looking simulations depart from the Jeopardy analogy in that they do involve lags. Before
providing a question to the modeler's answer, the simulation must ask some questions of its own. The direction of
causation becomes ambiguous -- or at least very complicated -- because agents are both reacting to past events and
anticipating future conditions. Accordingly, such simulations require sophisticated algorithms and ample computer
resources, and the meanings of the results are not always immediately clear.
While designing, debugging, and interpreting forward-looking simulations, you may find it helpful to bear in mind the
philosophical context in which such techniques arise. The premise that causation can run backward in time seems to
contradict common sense. In fact, forward-looking simulation does not rest on that premise. Forward-looking models
are designed to solve a problem encountered by analysts with very sensible (perhaps too sensible) notions of causality.
The problem -- in economics, at least -- is that human behavior is too complicated to model effectively by attempting to
account directly for causation. Instead, it is often convenient to delegate part of the modelling task to the agents within
the model. Agents respond to complicated sets of signals about the future. Rather than attempting to model those
signals, the forward-looking approach simply assumes that those signals provide the same information that the model
itself provides (or some specified subset of that information), and that the agents know how to use that information. The
remaining task of modelling agents' responses is often trivial (though not always as trivial as some modellers assume).
This approach has two obvious shortcomings and one obvious advantage over even very careful backward-looking
modelling. The greatest shortcoming, perhaps, is that the forward-looking approach tends to compound existing flaws in
a model. Everyone makes mistakes, but when a forward-looking modeller makes a mistake, he (or she) implicitly makes
the additional mistake of attributing his (or her) own error to the model's agents. "Rational expectations" are only as
rational as the model itself.

The other shortcoming is just the opposite: the forward-looking 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 forward-looking models can still be useful in studying such "boundedly rational" behavior. For
example, by assuming that some fraction of all agents is forward-looking, one can parametrize the degree of
irrationality.
The great advantage of forward-looking simulation, from the point of view of policy analysis, is that a forward-looking
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
well-understood 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 forward-looking 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).

B. PREPARING FOR FORWARD-LOOKING SIMULATION


Before you can simulate a forward-looking model, you have to have one. For this chapter, we have one to use as an
example. Your own model will of course be different, but many of the same considerations will apply.
The model's name is PONDFROG, which stands for "Paradigm for Observation of Nonlinear Dynamics with Factor
Redundancy, Overshooting, and Growth." The model's name pretty much summarizes its content, except for the
forward-looking aspect, which is of greatest interest here. PONDFROG is based on the standard Keynesian IS-LM-PC
macro model with the usual Mundell-Fleming open economy extensions and Dornbusch-style exchange rate dynamics,
along with a capital accumulation equation and a bunch of gratuitous nonlinearities and endogenous leads to make it
interesting.
The model begins with a bunch of symbols, which we will allow to speak for themselves:
SIMULATE Command: usemod ;
New model: (nameless)
TROLL Command: addsym endogenous infl p y c i x im e er mpk u k l r rr ;
MODEDIT Command: addsym exogenous lf tech rw yw ;
MODEDIT Command: addsym policy ms gov ;
MODEDIT Command: addsym parameter capshr depr ;
MODEDIT Command: addsym coefficient pc1 pc0 c1 c2 c3 x0 x1 x2 ;
MODEDIT Command: addsym coefficient im0 im1 im2 md0 md1 md2 i1 ;
MODEDIT Command: symcom infl inflation rate ;
MODEDIT Command: symcom p price level ;
MODEDIT Command: symcom y real national income ;
MODEDIT Command: symcom c real personal consumption ;
MODEDIT Command: symcom i real private investment ;
MODEDIT Command: symcom im real imports ;
MODEDIT Command: symcom x real exports ;
MODEDIT Command: symcom e nominal exchange rate (price of foreign currency) ;
MODEDIT Command: symcom er real exchange rate (relative cost of imports) ;
MODEDIT Command: symcom mpk marginal product of capital ;
MODEDIT Command: symcom u unemployment rate ;
MODEDIT Command: symcom k capital stock ;
MODEDIT Command: symcom l employed labor ;
MODEDIT Command: symcom r nominal interest rate ;
MODEDIT Command: symcom rr real interest rate ;
MODEDIT Command: symcom lf labor force ;
MODEDIT Command: symcom tech total factor productivity ;
MODEDIT Command: symcom rw world interest rate ;
MODEDIT Command: symcom yw world income ;
MODEDIT Command: symcom ms money supply ;
MODEDIT Command: symcom gov real government purchases ;
MODEDIT Command: symcom capshr capital share ;
MODEDIT Command: symcom depr depreciation rate ;

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 Cobb-Douglas production function (with a time-dependent scale factor or "Solow residual") and a standard
capital growth equation (which may look a little strange because of the discrete-time 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) + (1-capshr)*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*(k-k(-1))/log(k/k(-1)) + i(-1);
MODEDIT Command: // note: "(k-k(-1))/log(k/k(-1))" is "k(-1)"
MODEDIT Command: //
with a discrete-time correction
MODEDIT Command: eqcom accum Capital Accumulation ;

In case you're interested, the discrete-time correction factor allows us to specify growth rates in continuous time, so that
we can later use logs in the steady-state 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 forward-looking" 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*(mpk-rr)) ;
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))+(1-x1)*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
long-run 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

bottom money: log(ms/p)=md0-md1*log(r)+md2*log(y) ;


money Money Demand ;
bottom parity: rw=r-log(e(+1)/e) ;
parity Interest Rate Parity ;

The final behavioral equation is the Phillips curve, which has a widely-used 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+x-im ;
income National Income Identity ;
Note: "Definitions" below do NOT use DEFINITION symbols!
bottom employ: u = 1-l/lf ;
employ Definition of Unemployment ;

MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT
MODEDIT

Command:
Command:
Command:
Command:
Command:
Command:

addeq
eqcom
addeq
eqcom
addeq
eqcom

bottom realex: er=e/p ;


realex Definition of Real Exchange Rate ;
bottom realrate: rr=r-infl ;
realrate Definition of Real Interest Rate ;
bottom infl: infl=log(p(+1)/p) ;
infl Definition of Inflation Rate ;

Finally we add a comment, then display and save the model.


MODEDIT Command: modcom Paradigm for Observing Nonlinear Dynamics
Comment or ';': with Factor Redundancy, Overshooting, and Growth ;
MODEDIT Command: print comment all ;
Paradigm for Observing Nonlinear Dynamics
with Factor Redundancy, Overshooting, and Growth
Symbols:
ENDOGENOUS :
C
E
ER
I
IM
INFL
K
L
MPK
P
R
RR
U
X
Y
-

real personal consumption


nominal exchange rate (price of foreign currency)
real exchange rate (relative cost of imports)
real private investment
real imports
inflation rate
capital stock
employed labor
marginal product of capital
price level
nominal interest rate
real interest rate
unemployment rate
real exports
real national income

EXOGENOUS :
LF
- labor force
RW
- world interest rate
TECH
- total factor productivity
YW
- world income
POLICY :
GOV
MS

- real government purchases


- money supply

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)+(1-CAPSHR)*LOG(L)+TECH
Marginal Product of Capital
2: MPK
MPK = CAPSHR*Y/K
Capital Accumulation
3: ACCUM
K = K(-1)-DEPR*(K-K(-1))/LOG(K/K(-1))+I(-1)
Investment Demand
4: INVEST
I = Y*MAX(0,I1*(MPK-RR))
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))+(1-X1)*LOG(Y(-1)/YW(-1))+X2*
LOG(ER)
Money Demand
8: MONEY
LOG(MS/P) = MD0-MD1*LOG(R)+MD2*LOG(Y)
Interest Rate Parity
9: PARITY
RW = R-LOG(E(+1)/E)
Phillips Curve
10: PHIL
LOG(P(+1)/P(-1))/2 = PC1/U-PC0+(INFL(-2)+INFL(+1))/2
National Income Identity
11: INCOME
Y = C+I+GOV+X-IM
Definition of Unemployment

12: EMPLOY
U = 1-L/LF
Definition of Real Exchange Rate
13: REALEX
ER = E/P
Definition of Real Interest Rate
14: REALRATE RR = R-INFL
Definition of Inflation Rate
15: INFL
INFL = LOG(P(+1)/P)

MODEDIT Command: filemod pondfrog ;

1. Establishing Endpoints
Now that we have a model, we need some data. With a forward-looking 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 steady-state 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 non-constant 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 long-run 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
long-run assumptions. Some long-run assumptions may be implicit in your dynamic model, but may not
be readily apparent until you try to put the model in steady-state 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 long-run 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 discrete-time 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*(k-k(-1))/log(k/k(-1))+i(-1)$
$oldstr$newstr$ [G] positionspec: (i/k)*(gr/(exp(gr)-1))$ 3 ;
MODEDIT Command: // note: discrete-time 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 $=$*(1-c3)=$ 5 ;
changeq $c1$(c1+c2)$ 5 ;
changeq $c2*log(y(+1))+c3*log(c(-1))$(c2-c3)*gr$ 5 ;
print equation 5 ;

Equations:
5: CONSUME

LOG(C)*(1-C3) = (C1+C2)*LOG(Y)+(C2-C3)*GR

The import equation is quite simple.


MODEDIT Command: changeq $=$*(1-im1)=$ 6 ;
MODEDIT Command: changeq $+im1*log(im(-1)/y(-1))$$ 6 ;
MODEDIT Command: print equation 6 ;
Equations:
6: IMPORT

LOG(IM/Y)*(1-IM1) = IM0-IM2*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 $=$*(1-x1)=$ 7 ;
MODEDIT Command: changeq $x1*log(x(-1)/yw(-1))+(1-x1)*log(y(-1)/yw(-1))$
$oldstr$newstr$ [G] positionspec: xgr-gr$ 7 ;
MODEDIT Command: changeq $yw$y$ 7 ;
MODEDIT Command: print equation 7 ;
Equations:
7: EXPORT

LOG(X/Y)*(1-X1) = X0+XGR-GR+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 interest-rate.
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 steady-state 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/U-PC0

Finally there is the definition of inflation. Technically, to put this equation into steady-state 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)+(1-CAPSHR)*LOG(L)+TECH
MPK = CAPSHR*Y/K
GR+DEPR = I/K*GR/(EXP(GR)-1)
I = Y*MAX(0,I1*(MPK-RR))
LOG(C)*(1-C3) = (C1+C2)*LOG(Y)+(C2-C3)*GR
LOG(IM/Y)*(1-IM1) = IM0-IM2*LOG(ER)
LOG(X/Y)*(1-X1) = X0+XGR-GR+X2*LOG(ER)
LOG(MS/P) = MD0-MD1*LOG(R)+MD2*LOG(Y)
RW = RR
0 = PC1/U-PC0
Y = C+I+GOV+X-IM
U = 1-L/LF
ER = E/P
RR = R-INFL

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 long-run 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
steady-state model doesn't say anything about money supply growth. To get money supply growth into the
model, we need to first-difference 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 steady-state 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: (tech-tech(-1))/(1-capshr) + 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 steady-state model we have to create data sets for the exogenous variables. Then, if we want to re-simulate
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 data-generation 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

- real government purchases


- money supply

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)+(1-CAPSHR)*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*(MPK-RR))
Consumption Demand
5: CONSUME LOG(C)*(1-C3) = (C1+C2)*LOG(Y)+(C2-C3)*GR
Import Demand
6: IMPORT
LOG(IM/Y)*(1-IM1) = IM0-IM2*LOG(ER)
Export Demand
7: EXPORT
LOG(X/Y)*(1-X1) = X0+XGR-GR+X2*LOG(ER)
Money Demand
8: MONEY
LOG(MS/P) = MD0-MD1*LOG(R)+MD2*LOG(Y)
Interest Rate Parity
9: PARITY
RW = RR
Phillips Curve
10: PHIL
0 = PC1/U-PC0
National Income Identity
11: INCOME
Y = C+I+GOV+X-IM
Definition of Unemployment
12: EMPLOY
U = 1-L/LF
Definition of Real Exchange Rate
13: REALEX
ER = E/P
Definition of Real Interest Rate
14: REALRATE RR = R-INFL
Money First Difference
15: MONEYDIF LOG(MS(+1)/MS) = GR+INFL
Growth Rate Depends on Labor and Technology
16: GROWTH
GR = (TECH-TECH(-1))/(1-CAPSHR)+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 re-parametrization. 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:

addsym parameter progress lgr ; /* can model these explicitly */


symcom progress rate of technological progress ;
symcom lgr labor force growth rate ;
changesym endogenous tech lf ;
addeq bottom solowres: tech = tech(-1) + progress ;
eqcom solowres Evolution of Total Factor Productivity ;
addeq bottom workers: lf = exp(lgr)*lf(-1) ;
eqcom workers Growth of Labor Force ;
addsym parameter mgr ;
symcom mgr money supply growth rate ;

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 rest-of-world 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 content-blocking 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)+(1-CAPSHR)*LOG(L)+TECH
MPK = CAPSHR*Y/K
GR+DEPR = I/K*GR/(EXP(GR)-1)
I = Y*MAX(0,I1*(MPK-RR))
LOG(C)*(1-C3) = (C1+C2)*LOG(Y)+(C2-C3)*GR
LOG(IM/Y)*(1-IM1) = IM0-IM2*LOG(ER)
LOG(X/Y)*(1-X1) = X0+XGR-GR+X2*LOG(ER)
LOG(MS/P) = MD0-MD1*LOG(R)+MD2*LOG(Y)
RW = RR
0 = PC1/U-PC0
Y = C+I+GOV+X-IM
U = 1-L/LF
ER = E/P
RR = R-INFL
MGR = GR+INFL
GR = (TECH-TECH(-1))/(1-CAPSHR)+LOG(LF/LF(-1))
TECH = TECH(-1)+PROGRESS
LF = EXP(LGR)*LF(-1)
MS = MS(-1)*EXP(MGR)
YW = EXP(XGR)*YW(-1)

MODEDIT Command: lkord all ;


Analyzing Model's Incidence Matrix
Analyzing Model's Block Structure
The model has 15 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

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 well-parametrized 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)+(1-CAPSHR)*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*(MPK-RR))
Consumption Demand
5: CONSUME LOG(C)*(1-C3) = (C1+C2)*LOG(Y)+(C2-C3)*GR
Import Demand
6: IMPORT
LOG(IM/Y)*(1-IM1) = IM0-IM2*LOG(ER)
Export Demand
7: EXPORT
LOG(X/Y)*(1-X1) = X0+XGR-GR+X2*LOG(ER)
Money Demand
8: MONEY
LOG(MS/P) = MD0-MD1*LOG(R)+MD2*LOG(Y)
Interest Rate Parity
9: PARITY
RW = RR
Phillips Curve
10: PHIL
0 = PC1/U-PC0
National Income Identity
11: INCOME
Y = C+I+GOV+X-IM
Definition of Unemployment
12: EMPLOY
U = 1-L/LF
Definition of Real Exchange Rate
13: REALEX
ER = E/P
Definition of Real Interest Rate
14: REALRATE RR = R-INFL
Money First Difference
15: MONEYDIF MGR = GR+INFL
Growth Rate Depends on Labor and Technology
16: GROWTH
GR = (TECH-TECH(-1))/(1-CAPSHR)+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 steady-state model performs in a manner
consistent with a steady-state. 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 time-dependent, 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

Command: addeq bottom kverify: res_k = log(k/k(-1)) - gr ;


Command: eqcom kverify Capital Growth Verification ;
Command: addeq bottom imverify: res_im = log(im/im(-1)) - gr ;
Command: eqcom imverify Import Growth Verification ;
Command: addeq bottom xverify: res_x = log(x/x(-1)) - gr ;
Command: eqcom xverify Export Growth Verification ;
Command: addeq bottom rverify: res_r = r(-1)-rw(-1)-log(e/e(-1)) ;
Command: eqcom rverify Interest Rate Parity Verification ;
Command: addeq bottom erverify: res_er = log(er/er(-1)) ;
Command: eqcom rverify Exchange Rate Stability Verification ;
Command: addeq bottom rrverify: res_rr = rr - rr(-1) ;
Command: eqcom rrverify Real Interest Rate Stability Verification ;
Command: modcom Residual Analysis for Verification
or ';': of Acceptable Growth in the Equilibrium State ;
Command: filemod ravages ;

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

TROLL Command: simulate ;


Generating Simulation Code
Use FILEMOD or SAVEMOD before USEMOD to save code.
Simulations can start from NA to NA.
SIMULATE Command: simstart 2a ;
SIMULATE Command: list solutions res_* ;
SIMULATE Command: dosim 10 ;
Date:
What:
Value:
2A
Solution: RES_P
2.883307
RES_INFL
0.098667
RES_Y
0.422236
RES_C
0.726368
RES_I
-0.526562
RES_K
0.108847
RES_IM
0.996515
RES_X
0.396096
RES_R
-3.32393
RES_ER
0.440624
RES_RR
0
3A
Solution: RES_P
-5.0587134e-010
RES_INFL
0
RES_Y
9.02776298e-010
RES_C
2.92411786e-008
RES_I
-3.3824876e-010
RES_K
4.47992181e-009
RES_IM
-8.5721018e-006
RES_X
-1.5822892e-005
RES_R
-2.1855700e-006
RES_ER
2.18607591e-006
RES_RR
0
4A
Solution: RES_P
-9.7144515e-017
RES_INFL
1.94289029e-016
RES_Y
0
RES_C
4.02455846e-016
RES_I
-6.1062266e-016
RES_K
5.96744876e-016
RES_IM
8.87579056e-006
RES_X
1.61795818e-005
RES_R
1.89216526e-006
RES_ER
-1.8921653e-006
RES_RR
0
5A
Solution: RES_P
1.11022302e-016
RES_INFL
-1.9428903e-016
RES_Y
-1.9428903e-016
RES_C
-4.0245585e-016
RES_I
4.02455846e-016
RES_K
-5.9674488e-016
RES_IM
5.67879077e-014
RES_X
1.04333209e-013
RES_R
1.57929225e-014
RES_ER
-1.5987212e-014
RES_RR
0
6A
Solution: RES_P
9.71445147e-017
RES_INFL
0
RES_Y
-1.9428903e-016
RES_C
-1.9428903e-016
RES_I
0
RES_K
-1.9428903e-016

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.08166817e-016
-5.9674488e-016
3.05311332e-016
-4.4408921e-016
0
9.71445147e-017
0
-1.9428903e-016
-4.0245585e-016
-4.0245585e-016
-1.9428903e-016
-1.4016566e-015
9.99200722e-016
-1.3045121e-015
1.33226763e-015
0
-3.0531133e-016
0
2.08166817e-016
4.02455846e-016
2.08166817e-016
2.08166817e-016
1.40165657e-015
-1.4016566e-015
1.70696790e-015
-1.4432899e-015
0
9.71445147e-017
0
2.08166817e-016
-1.9428903e-016
2.08166817e-016
0
-8.0491169e-016
1.40165657e-015
-9.0205621e-016
6.66133815e-016
0
-9.7144515e-017
0
2.08166817e-016
4.02455846e-016
0
0
5.96744876e-016
-9.9920072e-016
7.07767178e-016
-5.5511151e-016
0
7.07767178e-016
0
-4.0245585e-016
-4.0245585e-016
-1.9428903e-016
-4.0245585e-016
-4.0245585e-016
-1.9428903e-016
-7.0776718e-016
0
0

Basta. Compared to the scale of the data, all those numbers are zero (except for the first year, when there are no
prior-year 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 steady-state 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 steady-state 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 ultra-minimal calibration procedure. Essentially, we
begin with a few semi-arbitrary assumptions about the coefficient values, and then we calculate the rest from

point-in-time 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:

access cass mode c type formdata id cass.frm ;


search first cass w ;
do y=798, c=523, k=1244, i=84, im=281, x=307, gov=165 ;
// The following are rounded to facilitate hand computation
do ms=35, lf=15000, l=13500, p=1, e=1.4, u=.1, r=.04 ;
do infl=.01 ; /* five-year trailing average */
do gr=.02 ; /* ten-year trailing average */
do lgr=.012 ;
// The following are just rough guesses
do xgr=.025, yw=50000, rw=.03 ;
// Computed from definitions
do rr=.03, er=1.4, govfrac=.2 ;

For one critical parameter, we rely on someone else's estimate:


TROLL Command: // IMF estimate lifted from MULTIMOD data
TROLL Command: do capshr=.33 ;

We back out the remaining parameters from model's structural equations


TROLL Command: // Computed from model equations given values above
TROLL Command: do mpk=.2, tech=-2, progress=.005, mgr=.03, depr=.05 ;

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 steady-state 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 steady-state 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

Those results look reasonable. Let's continue.


SIMULATE Command: delist solutions all ;
SIMULATE Command: dosim 500 ;

No complaints: looks like it worked. Now save these results to use as input data for dynamic simulations.
SIMULATE Command: filesim cass ;

Just as a sanity check, let's look at the last data point.


SIMULATE Command: &prtdset arch cass, range 2500a::2500a, vari all ;
Data Set by Archive
CASS
INFL
2500A

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.)

C. USING THE STANDARD STACKED TIME METHOD


By default TROLL performs forward-looking simulation via the stacked time method, which is recommended for most
purposes. To invoke the stacked time simulator, you type "simulate stack" followed by an integer representing the
number of periods to stack. (For a review of the usage basics, see the description earlier in this chapter.)
We will proceed by simulating the PONDFROG model in forward-looking mode. We'll use the data generated by our
steady-state simulation.
If we just do a forward-looking simulation using the same data, the result won't be very interesting. After all, by
definition, if you start out in the steady state and experience no shocks, then you remain in the steady state. And recall
that we calibrated the model under the assumption that the previous year was a steady state.

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 steady-state results to use as input data for the
"shocked" simulation. Or perhaps you could figure out analytically what the long-run effect of the shock would
be -- in which case you could change the data series directly instead of running a new steady-state 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:

Time dimension -->


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

1996A to 2145A (150 observations)

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 stacked-time 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 ;

Now for the fun part.


TROLL Command: do ms = ms * shock ;

TROLL Command: simulate stack 100 ;


Constructing stacked-time incidence matrix and code.
Simulations can start from 1999A to 2145A and must end by 2145A.
SIMULATE Command: simstart 2000a ;
SIMULATE Command: dostack 1 ;
SIMULATE Command: savesim shocked ;
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:

Time dimension -->


0.999939
0.999822
0.999985
1.006956
1.093729
1.103706
1.100341
1.100341
1.100247
1.100204
1.100171
1.100149
1.100146
1.100164
1.099743
1.094045
1.054832
1.001684
1.000072
1.000099
1.00011
1.000089
1.000075
1.000061
1.000039

2000A to 2099A (100 observations)

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

TROLL Command: do prt.(shocked_er/baseline_er) ;


SHOCKED_ER/BASELINE_ER:
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:

Time dimension -->


0.999938
0.999816
0.999063
0.996623
1.009983
1.003447
0.999938
1.000237
1.000142
1.000136
1.000125
1.000115
1.000114
1.000166
1.000399
1.000636
0.997115
1.008669
0.99926
1.000118
1.000089
1.000078
1.00007
1.000061
1.000046

2000A to 2099A (100 observations)

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

TROLL Command: do prt.(shocked_u) ;


SHOCKED_U:
Numeric scalar timeseries --

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,

Time dimension -->


0.100029
0.100119
0.100803
0.105034
0.07709
0.100852
0.100177
0.09996
0.100005
0.099999
0.1
0.1
0.099997
0.099974
0.099817
0.098986
0.096624
0.092636
0.100861
0.099927
0.100003
0.1
0.1
0.1
0.100002

2000A to 2099A (100 observations)

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 backward-looking 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 backward-looking horizon (with only one lag on the right-hand 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 steady-state 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 stacked-time 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:

Time dimension -->


1.105116
1.098097
1.097477
1.097876
1.098182
1.098471
1.098716
1.098926
1.09912
1.099302
1.099021
1.093448

2016A to 2095A (80 observations)

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

TROLL Command: do prt.(suddenshock_er/baseline_er) ;


SUDDENSHOCK_ER/BASELINE_ER:
Numeric scalar timeseries -Time dimension: Periodicity 1,

2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:

Time dimension -->


1.036114
0.999928
1.000441
0.999812
0.999508
0.99938
0.999334
0.999343
0.99939
0.999506
0.999808
1.000116
0.99666
1.008275
0.99892
0.999827
0.99984
0.999867
0.999892
0.999922

2016A to 2095A (80 observations)

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

TROLL Command: do prt.(suddenshock_u) ;


SUDDENSHOCK_U:
Numeric scalar timeseries -Time dimension: Periodicity 1,

2016A:
2020A:
2024A:
2028A:
2032A:
2036A:
2040A:
2044A:
2048A:
2052A:
2056A:
2060A:
2064A:
2068A:
2072A:
2076A:
2080A:
2084A:
2088A:
2092A:

Time dimension -->


0.073998
0.102826
0.099804
0.100007
0.100003
0.1
0.100001
0.1
0.099997
0.099974
0.099817
0.098985
0.096623
0.092635
0.100862
0.099927
0.100003
0.1
0.099999
0.099995

2016A to 2095A (80 observations)

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 stacked-time incidence matrix and code.
Simulations can start from 1999A to 2145A and must end by 2145A.
SIMULATE Command: simstart 2016a ;
SIMULATE Command: lkroots elasticity ;
State-space eigenanalysis of PONDFROG linearized around 2016A:
There are 10 eigenvalues with modulus between 0.001 and 1000,
consisting of 6 real roots and 2 complex-conjugate 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

There are 89 elasticities above 0.1:


Root 1:
127.35671865
Equation 4
I
0
RR
0
Equation 5
C
0
Y
1
Equation 6
IM
0
Y
0
Equation 8
R
0
Y
0
Equation 11
C
0
I
0
IM
0
Y
0
Equation 14
R
0
RR
0
Root 2:
1.58323319
Equation 7
X
0
Equation 8
P
0
R
0
Equation 9
E
1
E
0
Equation 10
INFL
1
P
1
Equation 15
INFL
0
P
1
P
0
Root 4:
-1.58026206
Equation 1
L
0
Y
0
Equation 4
I
0
RR
0
Equation 8
P
0
Y
0
Equation 10
INFL
1
INFL
-2
P
1
U
0
Equation 11

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 non-cyclical 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.)

2. How Many Periods to Stack


Stack them all.
To fully model forward-looking behavior, you need to link your simulation to your terminal conditions. The
thorough, efficient way to do that is to set the STACK parameter equal to the entire length of your simulation.
In some cases you may have reason to believe that your input data provide a reasonable approximation of the
conditions anticipated by your model's agents. (For example, the input data may have been generated by an
earlier simulation which incorporated relevant expectation-generating factors.) In such cases, it may be
reasonable to stack fewer periods at once, especially if computer resource limitations make larger simulations
prohibitive.
But watch out.
SIMULATE Command: simulate stack 20 ;
Constructing stacked-time incidence matrix and code.
Simulations can start from 1999A to 2145A and must end by 2145A.
SIMULATE Command: simstart 2000a ;
SIMULATE Command: dostack 5 ;
SIMULATE Command: savesim smallstack ;
SIMULATE Command: quit ;
TROLL Command: do prt.(smallstack_u) ;
SMALLSTACK_U:
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:

Time dimension -->


0.100021
0.100087
0.100589
0.103683
0.074242
0.09067
0.103226
0.099433
0.099208
0.09553
0.089746
0.102999
0.099467
0.0992
0.09549
0.09049
0.099464
0.092204
0.100917
0.099917
0.100094
0.099981
0.100001
0.099996
0.099965

2000A to 2099A (100 observations)

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

TROLL Command: do prt.(smallstack_u-shocked_u) ;


SMALLSTACK_U-SHOCKED_U:
Numeric scalar timeseries -Time dimension: Periodicity 1,
Time dimension -->

2000A to 2099A (100 observations)

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.8730808e-006
-3.2132180e-005
-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.52560011e-005
-9.8282828e-006
9.03653893e-005
-1.9589439e-005
1.51310888e-006
-4.0025019e-006
-3.7642310e-005

6.14197820e-006
3.89752558e-005
0.000214
0.000961
0.007441
-0.018612
0.002044
-7.7990101e-005
0.000463
0.005149
-0.018884
0.002076
-8.4028869e-005
0.000483
0.005262
-0.017764
0.002237
-0.000208
1.81689638e-005
-6.2459550e-006
9.24437720e-005
-1.0171988e-005
2.40717682e-006
8.62229189e-006
3.11513855e-005

-1.2066885e-005
-8.3993102e-005
-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.25737340e-006
-5.3381795e-006
-4.2944064e-005
3.02326216e-005
-1.4793386e-006
-1.4220049e-006
-1.2311662e-005
-0.000109

1.72779683e-005
9.12693038e-005
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.90522509e-005
-0.000216
7.61579870e-005
-4.4551699e-006
-5.2981089e-005
-1.1670389e-005
3.05558596e-006
3.81217691e-006
1.69016135e-005
5.55179000e-005

TROLL Command: do stats(smallstack_u-shocked_u) ;


SMALLSTACK_U-SHOCKED_U:
NVals:
100
Mean:
Min:
-0.018884 Max:
Standard Deviation:

-0.000683
0.018702
0.005477

TROLL Command: do stats(shocked_u-baseline_u) ;


SHOCKED_U-BASELINE_U:
NVals:
100
Mean:
Min:
-0.02291
Max:
Standard Deviation:

0.000149
0.017618
0.003779

3. OLDSTACK vs. NEWSTACK


By default, TROLL uses the Laffargue-Boucekkine-Juillard algorithm (or its latest enhancement) to solve
forward-looking models. Traditionally, this algorithm is invoked with the NEWSTACK option in the SIMULATE
command. As of this writing the NEWSTACK option is equivalent to the standard STACK option.
An alternative algorithm can be invoked with the option OLDSTACK (as in "simulate oldstack 100;"). Currently,
the OLDSTACK algorithm simply combines all the stacked periods into a single model and solves that model as if it
were a static model. The NEWSTACK algorithm is usually more efficient and more robust, but results can differ
from one model to another. If you're having trouble with a simulation, or if you just want to experiment, you
may want to try OLDSTACK.

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 steady-state simulation again with the new set of parameters.
Someday perhaps this Guide will contain an example.

D. USING THE FAIR-TAYLOR MACRO


Before efficient stacked time methods were developed, the usual approach to forward-looking simulation was to
simulate iteratively until the simulated values of leaded variables matched their contemporaneous counterparts in the
periods to which the leads referred. The approach reached its greatest refinement in the multi-level iterative algorithm
developed by Fair and Taylor. Although TROLL does not have a built-in Fair-Taylor simulator, you can use TROLL for
Fair-Taylor simulation via the &FT macro that is distributed with TROLL. Documentation for the macro is contained in
the file ft.doc, which is normally placed in the main TROLL directory.

E. IMPERFECT FORESIGHT
1. One-Time Unanticipated Shock
To model a one-time unanticipated shock (an "unseen one-shot shock"), one approach is as follows:

Simulate once without the shock.


Save the results to use as "pre-shock expected values."
For each equation containing a lead, rewrite the equation with a conditional (e.g.,"y = if (year<2000)
then yexp else yact;") that incorporates the changing state of expectations.)
Re-simulate with the new model, using the shocked data for "actual" variables, and the unshocked data,
along with its simulation results, for "pre-shock expected" variables.
Alternatively, since this type of shock is a special case of the type of shock described below, you can use either
of the methods described below.

2. Ongoing Shock with Unanticipated Realizations


There are (at least) two methods for modelling ongoing unanticipated shock processes. You can simulate each
period separately with its own state of expectations (generated by including "virtual" instances of all future
periods in the same simulation), and then combine the simulation results. Or you can make expectations explicit
in the model by creating a new variable for each expectation each time it changes, and then simulate the new,
huge model only once. Neither method is simple, and neither is particularly elegant. For practical use, either
method requires the writing of a macro. In principle, either method could be implemented in a general macro
with replaceable parameters, but to write such a macro is no small task.
a. multiple simulations
A rough description of the algorithm follows. The description is necessarily rough, because the
implementation depends on the details of the particular case. (For example, if you use an "incomplete
stack", you can fairly easily do the whole algorithm from within the SIMULATE task -- using NEWVALS. But
with all periods stacked, that feat would also require some fancy footwork involving the DROP command.)
In some special cases, you may be able to skip steps. (For example, if you have no endogenous lags,
there is no need to update the endogenous values at each iteration, provided you save any results that you
will want to examine later.) In other cases you may need to augment the method. As of this writing, there
are no "canned" examples, so you have to use some ingenuity.
Assume you have N time periods, numbered 1 through N (plus any data needed outside the range
for lags and leads).
Start with unshocked data.
For each time period T from 1 to N,
Change exogenous values for period T to reflect the shock.
Simulate periods T through N.
Save simulation results in a temporary database.
Change endogenous values for period T to those in the temporary database.
b. multiple explicit expectations
Warning: the following algorithm as described has not been tested. Use at own risk.
Why would you want to use it? The main advantage is that it allows you to simulate once with explicit
expectations (but without any guarantee of efficiency). In the special case where there are no
endogenous lags, the method could be abbreviated by excluding "superscripts" greater than one plus the
maximum lag (absolute value) on a shocked exogenous variable. (Obviously that special case becomes
even more special when there are no lags on any shocked variable, so that you only need zero and one as
"superscripts".) In that special case, this algorithm, with the appropriate alteration, is probably more
efficient. Unfortunately, as of this writing, the altered algorithm for that special case has not even been
formulated explicitly, much less tested.
Assume you have N time periods (1 through N) plus any necessary lag/lead data from outside the
range.
For each shock variable to be imperfectly foreseen,
Create an "actual" and an "expected" version containing the appropriate data.
For each endogenous variable,
Replicate the variable with "superscripts" ranging from 0 to N-1 (e.g., replace X with X0,
X1, X2, etc., and then refer to "X3(-1)" as "X with superscript 3 and lag 1")
For each equation,
Replicate N times, replacing the original endogenous variables with their corresponding
replicated versions (e.g., in the fifth replication of an equation, X becomes X4)
For all replications except the first (0), replace any actual shock variables with their

"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 N-1, 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.

3. Rational Expectations with Multiple Random Draws


Models that involve "rational expectations" in the Muth sense -- expectations that are "perfect" on average but
subject to the occurrence of random unexpected shocks -- can be simulated by repeating one of the methods
described above for a series of alternative shocks generated by a random number function. Don't try that on a
486. (Actually, though, a network of less powerful machines working in parallel is a reasonable possibility for
this kind of problem.)

Commands
Functions
Programming

User's Guide

1. Introduction And Overview


1. PORTABLE TROLL
2. GETTING STARTED
3. WHIRLWIND TOUR
4. WHAT NEXT?
2. Understanding TROLL
1. USING THIS CHAPTER
2. DISTINCTIONS TO KEEP IN MIND
3. THE ELEMENTS OF TROLL
4. USING TROLL
5. TROLL SYNTAX
6. EXPLANATIONS OF OTHER TERMS USED IN THIS GUIDE
3. Using And Managing Information
1. THE ACCESS AND SEARCH LISTS
2. HOST CONSIDERATIONS
3. ENTERING DATA
4. IMPORTING DATA
5. USING TROLL DATA FILES
6. EXPORTING DATA
7. OTHER DATA ISSUES
4. Automating TROLL Tasks
1. USING INPUT FILES
2. A QUICK INTRODUCTION TO MACRO PROGRAMMING
5. Manipulating Data in Portable TROLL
1. DATA TYPES AND SHAPES
2. DO COMMANDS
3. THE TROLL MODELLING LANGUAGE
4. BUILT-IN FUNCTIONS
6. Creating And Working With Models
1. MODEL SPECIFICATION
2. MODEL FILES
3. USING MODELS
7. Estimating Model Coefficients
1. OVERVIEW OF HOW TO USE ESTIMATION TASKS
2. ORDINARY LEAST SQUARES
3. ADVANCED SINGLE-EQUATION TECHNIQUES
4. MULTIPLE EQUATION TECHNIQUES
8. Simulating A Model
1. BASIC SIMULATION
2. SIMULATION CHOICES IN TROLL
3. SIMULATION REQUIREMENTS
4. THINGS TO KEEP IN MIND
9. Advanced Simulation
1. CONVERGENCE ISSUES
2. MODEL ANALYSIS
3. FORWARD-LOOKING SIMULATION
10. Simulation Troubleshooting
1. DIVERGENCE
2. CYCLING

3. NON-ASSIGNABILITY
4. SINGULAR JACOBIAN
5. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)
6. SPEED vs. STABILITY
7. MISCELLANEOUS DEBUGGING TECHNIQUES
11. TABLE OF CONTENTS

Portable TROLL User's Guide

Chapter Ten. Simulation Troubleshooting


I. DIVERGENCE
II. CYCLING
III. NON-ASSIGNABILITY
IV. SINGULAR 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

VI. SPEED vs. STABILITY


A. SPARSE MATRIX TUNING IN NEWTON-RAPHSON

VII. MISCELLANEOUS DEBUGGING TECHNIQUES


A. USING JACOBI TO DEBUG GAUSS-SEIDEL
B. SINGLE-EQUATION MODE (FORECAST)
C. ONE-STEP-AHEAD MODE (SIMPER)

Portable TROLL User's Guide

Chapter Ten. Simulation Troubleshooting


I. DIVERGENCE
If your iterations terminate due to divergence, you have two choices: you can try to fix the divergence, or you can change the
definition of divergence. Obviously, the second alternative only helps when the apparent divergence is only temporary, which
isn't usually the case. To change the definition of divergence, you change the START and DIVCR parameters. To fix divergence, try
applying the same solutions as for illegal iterations (see below). DAMP, in particular, may be helpful.

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. NON-ASSIGNABILITY
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.

IV. SINGULAR JACOBIAN

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 round-off 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.

V. ILLEGAL ITERATIONS (ARITHMETIC FAILURES AND IMPOSSIBLE VALUES)


A. SYMPTOMS
Usually you will get some kind of arithmetic error message, such as, "Log of a nonpositive" or "Divide by zero."
(Sometimes you get such a message as only a warning, in which case you can ignore it, because TROLL will try again.)
Sometimes you may get results that are arithmetically correct but don't make any sense (for example, negative
employment).

B. NEW STARTING VALUES


Assuming you have a model that can be solved, a change in the starting values is the most promising strategy. If your
original starting values are far from the solution, the algorithm may have "barked up the wrong tree", and this
misdirected search might result in illegal values. One approach is to use progressive shocks. For example, if you can't
solve a particular shock with the baseline input dataset, but you can solve a shock that's half as large, then you could
take the solution values from the smaller shock as starting guesses for the larger shock.

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.

D. EXPLICIT CONSTRAINTS WITHIN EQUATIONS


If you can locate the problem in a particular equation, you may be able to change the equation so that the offending
calculation won't happen. For example, change "y=1/x" to "y=1/max(x,1e-10)".

E. USING CONSTRAIN TO PREVENT ILLEGAL ITERATIONS


This is something to try as a last resort, perhaps. CONSTRAIN lets you restrict iteration values for selected variables. For
example, you could say "constrain >=0 <=1e10: x;", which would prevent TROLL from trying negative values or
very large values for the ENDOGENOUS variable X. If an iteration takes a variable outside the specified range, TROLL will
reset the variable to the closest in-range value before the next iteration. Generally, TROLL's default backtracking will
already have handled effectively most situations where CONSTRAIN might otherwise have been useful. In some of the
cases where backtracking fails, CONSTRAIN may still be useful, as an additional "trial-and-error" option; it will at least
change, if not necessarily improve, the solution procedure.
Note that CONSTRAIN is not the same as putting an explicit constraint in an equation, for two reasons. First, in the
example given in the section above, the partial derivative with respect to X would be zero within the restricted region;
whereas, with CONSTRAIN, the value would be reset to a location where the partial derivative might not be zero. Second,
in that example, there is nothing to prevent the value of X from going deep into the restricted region and perhaps
becoming divergent; with CONSTRAIN, the effective value of X will be constant as long as iterations take it into the
restricted 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.

VI. SPEED vs. STABILITY


A. SPARSE MATRIX TUNING IN NEWTON-RAPHSON

If you want, you can fiddle with SMTUNE.

VII. MISCELLANEOUS DEBUGGING TECHNIQUES


A. USING JACOBI TO DEBUG GAUSS-SEIDEL
The Jacobi algorithm is like Gauss-Seidel but simpler and slower. At each iteration, each equation uses the same values
from the beginning of the iteration, instead of replacing them as you go along. That makes it much easier to follow: you
take the values, you plug them in, you solve, and you got new values, and that's an iteration. If you're having problems
with Gauss-Seidel, it can be a mess try to figure it out directly, so try using Jacobi instead (invoke the simulator with
"simulate jac" or issue "simalg jac" within the simulation task).

B. SINGLE-EQUATION MODE (FORECAST)


If your problem is not with simultaneity, you can reproduce it in a simpler context using FORECAST. FORECAST is a
high-level command that is an alternative to SIMULATE, with identical syntax. With FORECAST, each equation is solved
independently for its associated endogenous variable, with the other variables taken from the data.

C. ONE-STEP-AHEAD MODE (SIMPER)


If your problem doesn't have to do with dynamics, you needn't concern yourself with lags. You can use SIMPER to
simulate in a simpler context (no pun intended). The simulator will get lag values directly from the data, so you can
isolate what's going on in each period. SIMPER is a low-level command within the SIMULATE task.