dynare.texi 539 KB
Newer Older
1 2 3 4
\input texinfo
@c %**start of header
@setfilename dynare.info
@documentencoding UTF-8
5
@set txicodequoteundirected
6

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
@settitle Dynare Reference Manual
@afourwide
@dircategory Math
@direntry
* Dynare: (dynare).             A platform for handling a wide class
                                  of economic models.
@end direntry

@include version.texi

@c Define some macros

@macro descriptionhead
@ifnothtml
@sp 1
@end ifnothtml
@emph{Description}
@end macro

@macro optionshead
@iftex
@sp 1
@end iftex
@emph{Options}
@end macro

33 34 35 36 37 38 39
@macro flagshead
@iftex
@sp 1
@end iftex
@emph{Flags}
@end macro

40 41 42 43 44 45 46
@macro examplehead
@iftex
@sp 1
@end iftex
@emph{Example}
@end macro

47 48 49 50 51 52 53
@macro exampleshead
@iftex
@sp 1
@end iftex
@emph{Examples}
@end macro

54 55 56 57 58 59 60
@macro remarkhead
@iftex
@sp 1
@end iftex
@noindent @emph{Remark}
@end macro

61 62 63 64 65 66 67
@macro outputhead
@iftex
@sp 1
@end iftex
@emph{Output}
@end macro

68 69 70 71 72 73 74
@macro algorithmhead
@iftex
@sp 1
@end iftex
@emph{Algorithm}
@end macro

75 76 77 78 79 80 81
@macro algorithmshead
@iftex
@sp 1
@end iftex
@emph{Algorithms}
@end macro

82 83 84 85 86 87 88
@macro customhead{title}
@iftex
@sp 1
@end iftex
@emph{\title\}
@end macro

89 90 91 92
@macro dates
@code{dates }
@end macro

93 94 95 96
@macro dseries
@code{dseries }
@end macro

97 98 99
@c %**end of header

@copying
Houtan Bastani's avatar
Houtan Bastani committed
100
Copyright @copyright{} 1996-2018, Dynare Team.
101 102 103 104 105 106 107 108 109 110 111 112 113 114

@quotation
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.

A copy of the license can be found at @uref{http://www.gnu.org/licenses/fdl.txt}.
@end quotation
@end copying

@titlepage
@title Dynare
@subtitle Reference Manual, version @value{VERSION}
115
@author Stéphane Adjemian
116 117
@author Houtan Bastani
@author Michel Juillard
Stéphane Adjemian's avatar
Stéphane Adjemian committed
118
@author Frédéric Karamé
119 120 121
@author Junior Maih
@author Ferhat Mihoubi
@author George Perendia
122
@author Johannes Pfeifer
123
@author Marco Ratto
124
@author Sébastien Villemot
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage

@contents

@ifnottex
@node Top
@top Dynare
This is Dynare Reference Manual, version @value{VERSION}.

@insertcopying
@end ifnottex

@menu
141 142 143 144 145 146 147 148
* Introduction::
* Installation and configuration::
* Running Dynare::
* The Model file::
* The Configuration File::
* Time Series::
* Reporting::
* Examples::
149
* Dynare misc commands::
150 151 152
* Bibliography::
* Command and Function Index::
* Variable Index::
153 154 155 156 157 158

@detailmenu
 --- The Detailed Node Listing ---

Introduction

159 160 161
* What is Dynare ?::
* Documentation sources::
* Citing Dynare in your research::
162 163 164

Installation and configuration

165 166
* Software requirements::
* Installation of Dynare::
167
* Compiler installation::
168
* Configuration::
169 170 171

Installation of Dynare

172 173
* On Windows::
* On Debian GNU/Linux and Ubuntu::
Houtan Bastani's avatar
Houtan Bastani committed
174
* On macOS::
175
* For other systems::
176

177 178 179 180
Compiler installation

* Prerequisites on Windows::
* Prerequisites on Debian GNU/Linux and Ubuntu::
Houtan Bastani's avatar
Houtan Bastani committed
181
* Prerequisites on macOS::
182

183 184
Configuration

185 186 187
* For MATLAB::
* For GNU Octave::
* Some words of warning::
188

189 190
Running Dynare

191 192 193
* Dynare invocation::
* Dynare hooks::
* Understanding Preprocessor Error Messages::
194
* Invoking the Dynare Preprocessor from the GNU/Linux or macOS Command Line::
195

196 197
The Model file

198 199 200 201 202 203 204 205 206 207 208 209 210 211
* Conventions::
* Variable declarations::
* Expressions::
* Parameter initialization::
* Model declaration::
* Auxiliary variables::
* Initial and terminal conditions::
* Shocks on exogenous variables::
* Other general declarations::
* Steady state::
* Getting information about the model::
* Deterministic simulation::
* Stochastic solution and simulation::
* Estimation::
212 213 214
* Model Comparison::
* Shock Decomposition::
* Calibrated Smoother::
215 216 217 218 219 220
* Forecasting::
* Optimal policy::
* Sensitivity and identification analysis::
* Markov-switching SBVAR::
* Displaying and saving results::
* Macro-processing language::
221
* Verbatim inclusion::
222
* Misc commands::
223

224 225 226 227
Variable declarations

* On-the-fly Model Variable Declaration::

228 229
Expressions

230 231 232 233
* Parameters and variables::
* Operators::
* Functions::
* A few words of warning in stochastic context::
234 235 236

Parameters and variables

237 238
* Inside the model::
* Outside the model::
239 240 241

Functions

242 243
* Built-in Functions::
* External Functions::
244 245 246

Steady state

247 248 249
* Finding the steady state with Dynare nonlinear solver::
* Using a steady state file::
* Replace some equations during steady state computations::
250 251 252

Stochastic solution and simulation

253 254 255 256 257
* Computing the stochastic solution::
* Typology and ordering of variables::
* First order approximation::
* Second order approximation::
* Third order approximation::
258

259 260
Sensitivity and identification analysis

261
* Performing sensitivity analysis::
262
* IRF/Moment calibration::
263
* Performing identification analysis::
264 265 266
* Types of analysis and output files::

Types of analysis and output files
267

268 269
* Sampling::
* Stability Mapping::
270
* IRF/Moment restrictions::
271 272 273 274
* Reduced Form Mapping::
* RMSE::
* Screening Analysis::
* Identification Analysis::
275

276 277
Macro-processing language

278 279 280 281
* Macro expressions::
* Macro directives::
* Typical usages::
* MATLAB/Octave loops versus macro-processor loops::
282 283 284

Typical usages

285 286 287 288
* Modularization::
* Indexed sums or products::
* Multi-country models::
* Endogeneizing parameters::
289

290 291
The Configuration File

292 293
* Dynare Configuration::
* Parallel Configuration::
294
* Windows Step-by-Step Guide::
295 296 297 298 299 300 301 302 303 304

Time Series

* Dates::
* dseries class::

Dates

* dates in a mod file::
* dates class::
305 306 307 308 309 310 311 312

@end detailmenu
@end menu

@node Introduction
@chapter Introduction

@menu
313 314 315
* What is Dynare ?::
* Documentation sources::
* Citing Dynare in your research::
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
@end menu

@node What is Dynare ?
@section What is Dynare ?

Dynare is a software platform for handling a wide class of economic
models, in particular dynamic stochastic general equilibrium (DSGE)
and overlapping generations (OLG) models. The models solved by Dynare
include those relying on the @i{rational expectations} hypothesis, wherein
agents form their expectations about the future in a way consistent
with the model. But Dynare is also able to handle models where
expectations are formed differently: on one extreme, models where
agents perfectly anticipate the future; on the other extreme, models
where agents have limited rationality or imperfect knowledge of the
state of the economy and, hence, form their expectations through a
learning process. In terms of types of agents, models solved by Dynare
can incorporate consumers, productive firms, governments, monetary
authorities, investors and financial intermediaries. Some degree of
heterogeneity can be achieved by including several distinct classes of
agents in each of the aforementioned agent categories.

Dynare offers a user-friendly and intuitive way of describing these
models. It is able to perform simulations of the model given a
calibration of the model parameters and is also able to estimate these
parameters given a dataset. In practice, the user will write a text
file containing the list of model variables, the dynamic equations
linking these variables together, the computing tasks to be performed
and the desired graphical or numerical outputs.

A large panel of applied mathematics and computer science techniques
are internally employed by Dynare: multivariate nonlinear solving and
optimization, matrix factorizations, local functional approximation,
Kalman filters and smoothers, MCMC techniques for Bayesian estimation,
graph algorithms, optimal control, @dots{}

Various public bodies (central banks, ministries of economy and
finance, international organisations) and some private financial
institutions use Dynare for performing policy analysis exercises and
as a support tool for forecasting exercises. In the academic world,
Dynare is used for research and teaching purposes in postgraduate
macroeconomics courses.

Houtan Bastani's avatar
Houtan Bastani committed
358 359 360 361 362 363
Dynare is a free software, which means that it can be downloaded free of
charge, that its source code is freely available, and that it can be used for
both non-profit and for-profit purposes. Most of the source files are covered
by the GNU General Public Licence (GPL) version 3 or later (there are some
exceptions to this, see the file @file{license.txt} in Dynare distribution). It
is available for the Windows, macOS, and Linux platforms and is fully
364
documented in this reference manual. Part of Dynare is
Houtan Bastani's avatar
Houtan Bastani committed
365 366 367 368 369 370 371 372
programmed in C++, while the rest is written using the
@uref{http://www.mathworks.com/products/matlab/, MATLAB} programming language.
The latter implies that commercially-available MATLAB software is required in
order to run Dynare. However, as an alternative to MATLAB, Dynare is also able
to run on top of @uref{http://www.octave.org, GNU Octave} (basically a free
clone of MATLAB): this possibility is particularly interesting for students or
institutions who cannot afford, or do not want to pay for, MATLAB and are
willing to bear the concomitant performance loss.
373 374

The development of Dynare is mainly done at
375
@uref{http://www.cepremap.fr, Cepremap} by a core team of
376 377 378 379
researchers who devote part of their time to software development.
Currently the development team of Dynare is composed of Stéphane
Adjemian (Université du Maine, Gains and Cepremap), Houtan Bastani
(Cepremap), Michel Juillard (Banque de France), Frédéric Karamé
380
(Université du Maine, Gains and Cepremap), Junior Maih (Norges Bank),
Sébastien Villemot's avatar
Sébastien Villemot committed
381
Ferhat Mihoubi (Université Paris-Est Créteil, Epee and Cepremap), George
382
Perendia, Johannes Pfeifer (University of Cologne), Marco Ratto (European Commission, Joint Research Centre - JRC)
Sébastien Villemot's avatar
Sébastien Villemot committed
383
and Sébastien Villemot (Cepremap).
384 385 386 387 388 389 390 391
Increasingly, the developer base is expanding, as tools developed by
researchers outside of Cepremap are integrated into Dynare. Financial
support is provided by Cepremap, Banque de France and DSGE-net (an
international research network for DSGE modeling). The Dynare project
also received funding through the Seventh Framework Programme for
Research (FP7) of the European Commission's Socio-economic Sciences
and Humanities (SSH) Program from October 2008 to September 2011 under
grant agreement SSH-CT-2009-225149.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408

Interaction between developers and users of Dynare is central to the
project. A @uref{http://www.dynare.org/phpBB3, web forum} is available
for users who have questions about the usage of Dynare or who want to
report bugs. Training sessions are given through the Dynare Summer
School, which is organized every year and is attended by about 40
people. Finally, priorities in terms of future developments and
features to be added are decided in cooperation with the institutions
providing financial support.

@node Documentation sources
@section Documentation sources

The present document is the reference manual for Dynare. It documents
all commands and features in a systematic fashion.

Other useful sources of information include the
409
@uref{http://www.dynare.org/DynareWiki,old Dynare wiki}, the
410
@uref{https://git.dynare.org/Dynare/dynare/wikis/home,new Dynare wiki}, the documentation
411 412
section of the @uref{http://www.dynare.org/documentation-and-support,Dynare
website} and the @uref{https://forum.dynare.org/,Dynare forum}.
413

414 415 416
@node Citing Dynare in your research
@section Citing Dynare in your research

417 418
You should cite Dynare if you use it in your research. The recommended way to
do this is to cite the present manual as:
419 420

@quotation
421 422 423 424
Stéphane Adjemian, Houtan Bastani, Michel Juillard, Frédéric Karamé, Junior
Maih, Ferhat Mihoubi, George Perendia, Johannes Pfeifer, Marco Ratto and
Sébastien Villemot (2011), ``Dynare: Reference Manual, Version 4,'' @i{Dynare
Working Papers}, 1, CEPREMAP
425 426
@end quotation

427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
@noindent For convenience, you can copy and paste the following into your BibTeX file:

@verbatim
@TechReport{Adjemianetal2011,
  author      = {Adjemian, St\'ephane and Bastani, Houtan and Juillard, Michel and
                 Karam\'e, Fr\'ederic and Maih, Junior and Mihoubi, Ferhat and
                 Perendia, George and Pfeifer, Johannes and Ratto, Marco and
                 Villemot, S\'ebastien},
  title       = {Dynare: Reference Manual Version 4},
  year        = {2011},
  institution = {CEPREMAP},
  type        = {Dynare Working Papers},
  number      = {1},
}
@end verbatim

443
@noindent If you want to give a URL, use the address of the Dynare website:
444 445
@uref{http://www.dynare.org}.

446 447 448 449
@node Installation and configuration
@chapter Installation and configuration

@menu
450 451
* Software requirements::
* Installation of Dynare::
452
* Compiler installation::
453
* Configuration::
454 455 456 457 458
@end menu

@node Software requirements
@section Software requirements

459
Packaged versions of Dynare are available for Windows XP/Vista/7/8/10,
460
@uref{http://www.debian.org,Debian GNU/Linux},
Houtan Bastani's avatar
Houtan Bastani committed
461
@uref{http://www.ubuntu.com/,Ubuntu} and macOS 10.8 or later.  Dynare should
462
work on other systems, but some compilation steps are necessary in that case.
463

464
In order to run Dynare, you need one of the following:
465

466
@itemize
467 468

@item
Houtan Bastani's avatar
Houtan Bastani committed
469
MATLAB version 7.5 (R2007b) or above (MATLAB R2009b 64-bit for macOS);
470 471

@item
472
GNU Octave version 4.2.1 or above.
473 474
@end itemize

Sébastien Villemot's avatar
Sébastien Villemot committed
475 476
Packages of GNU Octave can be downloaded on the
@uref{http://www.dynare.org/download/octave,Dynare website}.
477

478 479 480 481 482 483
The following optional extensions are also useful to benefit from extra
features, but are in no way required:

@itemize

@item
484 485
If under MATLAB: the optimization toolbox, the statistics toolbox, the
control system toolbox;
486 487 488 489

@item
If under GNU Octave, the following
@uref{http://octave.sourceforge.net/,Octave-Forge} packages: optim,
490
io, statistics, control.
491 492 493

@end itemize

494

495 496 497 498 499 500 501 502 503 504 505

@node Installation of Dynare
@section Installation of Dynare

After installation, Dynare can be used in any directory on your
computer. It is best practice to keep your model files in directories
different from the one containing the Dynare toolbox. That way you can
upgrade Dynare and discard the previous version without having to worry
about your own files.

@menu
506 507
* On Windows::
* On Debian GNU/Linux and Ubuntu::
Houtan Bastani's avatar
Houtan Bastani committed
508
* On macOS::
509
* For other systems::
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
@end menu

@node On Windows
@subsection On Windows

Execute the automated installer called @file{dynare-4.@var{x}.@var{y}-win.exe}
(where 4.@var{x}.@var{y} is the version number), and follow the instructions. The
default installation directory is @file{c:\dynare\4.@var{x}.@var{y}}.

After installation, this directory will contain several sub-directories,
among which are @file{matlab}, @file{mex} and @file{doc}.

The installer will also add an entry in your Start Menu with a shortcut
to the documentation files and uninstaller.

Note that you can have several versions of Dynare coexisting (for
example in @file{c:\dynare}), as long as you correctly adjust your path
settings (@pxref{Some words of warning}).

@node On Debian GNU/Linux and Ubuntu
@subsection On Debian GNU/Linux and Ubuntu

Please refer to the
@uref{http://www.dynare.org/DynareWiki/InstallOnDebianOrUbuntu,Dynare
Wiki} for detailed instructions.

536 537
Dynare will be installed under @file{/usr/lib/dynare}. Documentation will be
under @file{/usr/share/doc/dynare-doc}.
538

Houtan Bastani's avatar
Houtan Bastani committed
539 540
@node On macOS
@subsection On macOS
541

Houtan Bastani's avatar
Houtan Bastani committed
542 543 544 545
To install Dynare for use with Matlab, execute the automated installer called
@file{dynare-4.@var{x}.@var{y}.pkg} (where 4.@var{x}.@var{y} is the version
number), and follow the instructions. The default installation directory is
@file{/Applications/Dynare/4.@var{x}.@var{y}} (please refer to the
546
@uref{http://www.dynare.org/DynareWiki/InstallOnMacOSX,Dynare Wiki} for
Houtan Bastani's avatar
Houtan Bastani committed
547
detailed instructions).
548 549 550 551

After installation, this directory will contain several sub-directories,
among which are @file{matlab}, @file{mex} and @file{doc}.

Houtan Bastani's avatar
Houtan Bastani committed
552 553 554 555 556 557 558 559 560 561
Note that several versions of Dynare can coexist (by default in
@file{/Applications/Dynare}), as long as you correctly adjust your path
settings (@pxref{Some words of warning}).

To install Dynare for Octave, first install Homebrew following the instructions
on their site: @uref{https://brew.sh/}. Then install Octave, issuing the
command @code{brew install octave} at the Terminal prompt. You can then install
the latest stable version of Dynare by typing @code{brew install dynare} at the
Terminal prompt. You can also pass options to the installation command. These
options can be viewed by typing @code{brew info dynare} at the Terminal prompt.
562 563 564 565 566 567 568 569 570

@node For other systems
@subsection For other systems

You need to download Dynare source code from the
@uref{http://www.dynare.org,Dynare website} and unpack it somewhere.

Then you will need to recompile the pre-processor and the dynamic
loadable libraries. Please refer to
571
@uref{https://git.dynare.org/Dynare/dynare/blob/master/README.md,README.md}.
572

573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
@node Compiler installation
@section Compiler installation

If you plan to use the @code{use_dll} option of the @code{model}
command, you will need to install the necessary requirements for
compiling MEX files on your machine. 

If you are using MATLAB, please check
@uref{http://www.mathworks.com/support/compilers} for supported compilers for
your MATLAB version on your operating system. After installing your compiler,
select it using @code{mex -setup} in Matlab and clicking on the required compiler.

Octave comes with built-in functionality for compiling mex-files.

@menu
588 589
* Prerequisites on Windows::
* Prerequisites on Debian GNU/Linux and Ubuntu::
Houtan Bastani's avatar
Houtan Bastani committed
590
* Prerequisites on macOS::
591 592
@end menu

593 594
@node Prerequisites on Windows
@subsection Prerequisites on Windows
595

596 597
There is no prerequisite on Windows. Dynare now ships a compilation environment
that can be used with the @code{use_dll} option.
598

599 600
@node Prerequisites on Debian GNU/Linux and Ubuntu
@subsection Prerequisites on Debian GNU/Linux and Ubuntu
601

602 603 604
Users of MATLAB under GNU/Linux need a working compilation environment
installed. If not already present, it can be installed via @code{apt install
build-essential}.
605

606
Users of Octave under GNU/Linux should install the package for MEX file compilation
607 608
(under Debian or Ubuntu, it is called @file{liboctave-dev}).

Houtan Bastani's avatar
Houtan Bastani committed
609 610
@node Prerequisites on macOS
@subsection Prerequisites on macOS
611 612 613

[TO BE UPDATED]

Houtan Bastani's avatar
Houtan Bastani committed
614
If you are using MATLAB under macOS, you should install the latest
615 616 617 618
version of XCode: see
@uref{http://www.dynare.org/DynareWiki/InstallOnMacOSX,instructions on
the Dynare wiki}.

619 620 621 622
@node Configuration
@section Configuration

@menu
623 624 625
* For MATLAB::
* For GNU Octave::
* Some words of warning::
626 627 628 629 630 631 632 633
@end menu

@node For MATLAB
@subsection For MATLAB

You need to add the @file{matlab} subdirectory of your Dynare
installation to MATLAB path. You have two options for doing that:

634
@itemize
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649

@item
Using the @code{addpath} command in the MATLAB command window:

Under Windows, assuming that you have installed Dynare in the standard
location, and replacing @code{4.@var{x}.@var{y}} with the correct
version number, type:

@example
addpath c:\dynare\4.@var{x}.@var{y}\matlab
@end example

Under Debian GNU/Linux or Ubuntu, type:

@example
650
addpath /usr/lib/dynare/matlab
651 652
@end example

Houtan Bastani's avatar
Houtan Bastani committed
653
Under macOS, assuming that you have installed Dynare in the standard
654 655 656 657
location, and replacing @code{4.@var{x}.@var{y}} with the correct version
number, type:

@example
Houtan Bastani's avatar
Houtan Bastani committed
658
addpath /Applications/Dynare/4.@var{x}.@var{y}/matlab
659 660 661 662 663 664 665 666 667
@end example

MATLAB will not remember this setting next time you run it, and you
will have to do it again.

@item
Via the menu entries:

Select the ``Set Path'' entry in the ``File'' menu, then click on
Houtan Bastani's avatar
Houtan Bastani committed
668
``Add Folder@dots{}'', and select the @file{matlab} subdirectory of `your
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
Dynare installation. Note that you @emph{should not} use ``Add with
Subfolders@dots{}''. Apply the settings by clicking on ``Save''. Note that
MATLAB will remember this setting next time you run it.
@end itemize

@node For GNU Octave
@subsection For GNU Octave

You need to add the @file{matlab} subdirectory of your Dynare
installation to Octave path, using the @code{addpath} at the Octave
command prompt.

Under Windows, assuming that you have installed Dynare in the standard
location, and replacing ``4.@var{x}.@var{y}'' with the correct version
number, type:

@example
addpath c:\dynare\4.@var{x}.@var{y}\matlab
@end example

Under Debian GNU/Linux or Ubuntu, there is no need to use the
@code{addpath} command; the packaging does it for you.

Houtan Bastani's avatar
Houtan Bastani committed
692
Under macOS, assuming that you have installed Dynare and Octave via Homebrew, type:
693 694

@example
Houtan Bastani's avatar
Houtan Bastani committed
695
addpath /usr/local/opt/dynare/lib/dynare/matlab
696 697 698 699
@end example

If you don't want to type this command every time you run Octave, you
can put it in a file called @file{.octaverc} in your home directory
Houtan Bastani's avatar
Houtan Bastani committed
700
(under Windows this will generally be @file{c:\Documents and
Houtan Bastani's avatar
Houtan Bastani committed
701
Settings\USERNAME\} while under macOS it is @file{/Users/USERNAME/}).
702
This file is run by Octave at every startup.
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718

@node Some words of warning
@subsection Some words of warning

You should be very careful about the content of your MATLAB or Octave
path. You can display its content by simply typing @code{path} in the
command window.

The path should normally contain system directories of MATLAB or Octave,
and some subdirectories of your Dynare installation. You have to
manually add the @file{matlab} subdirectory, and Dynare will
automatically add a few other subdirectories at runtime (depending on
your configuration). You must verify that there is no directory coming
from another version of Dynare than the one you are planning to use.

You have to be aware that adding other directories to your path can
Houtan Bastani's avatar
Houtan Bastani committed
719 720
potentially create problems if any of your M-files have the same name
as a Dynare file. Your file would then override the Dynare file, making
721 722
Dynare unusable.

723 724
@node Running Dynare
@chapter Running Dynare
725 726 727 728

In order to give instructions to Dynare, the user has to write a
@emph{model file} whose filename extension must be @file{.mod}. This
file contains the description of the model and the computing tasks
729
required by the user. Its contents are described in @ref{The Model file}.
730

731
@menu
732 733 734
* Dynare invocation::
* Dynare hooks::
* Understanding Preprocessor Error Messages::
735
* Invoking the Dynare Preprocessor from the GNU/Linux or macOS Command Line::
736 737 738 739 740
@end menu

@node Dynare invocation
@section Dynare invocation

741 742 743 744 745 746 747 748
Once the model file is written, Dynare is invoked using the
@code{dynare} command at the MATLAB or Octave prompt (with the filename
of the @file{.mod} given as argument).

In practice, the handling of the model file is done in two steps: in the
first one, the model and the processing instructions written by the user
in a @emph{model file} are interpreted and the proper MATLAB or GNU
Octave instructions are generated; in the second step, the program
749
actually runs the computations. Both steps are triggered automatically
750 751 752 753 754 755 756
by the @code{dynare} command.

@deffn {MATLAB/Octave command} dynare @var{FILENAME}[.mod] [@var{OPTIONS}@dots{}]

@descriptionhead

This command launches Dynare and executes the instructions included in
757 758 759 760
@file{@var{FILENAME}.mod}.  This user-supplied file contains the model and the
processing instructions, as described in @ref{The Model file}. The options,
listed below, can be passed on the command line, following the name of the
@file{.mod} file or in the first line of the @file{.mod} file itself (see below).
761 762 763 764 765 766 767

@code{dynare} begins by launching the preprocessor on the @file{.mod}
file.  By default (unless @code{use_dll} option has been given to
@code{model}), the preprocessor creates three intermediary files:

@table @file

768
@item +@var{FILENAME}/driver.m
769 770
Contains variable declarations, and computing tasks

771
@item +@var{FILENAME}/dynamic.m
Johannes Pfeifer's avatar
Johannes Pfeifer committed
772
@vindex M_.lead_lag_incidence
Houtan Bastani's avatar
Houtan Bastani committed
773
Contains the dynamic model equations. Note that Dynare might introduce auxiliary equations and variables (@pxref{Auxiliary variables}). Outputs are the residuals of the dynamic model equations in the order the equations were declared and the Jacobian of the dynamic model equations. For higher order approximations also the Hessian and the third-order derivatives are provided. When computing the Jacobian of the dynamic model, the order of the endogenous variables in the columns is stored in @code{M_.lead_lag_incidence}. The rows of this matrix represent time periods: the first row denotes a lagged (time t-1) variable, the second row a contemporaneous (time t) variable, and the third row a leaded (time t+1) variable. The columns of the matrix represent the endogenous variables in their order of declaration. A zero in the matrix means that this endogenous does not appear in the model in this time period. The value in the @code{M_.lead_lag_incidence} matrix corresponds to the column of that variable in the Jacobian of the dynamic model. Example: Let the second declared variable be @code{c} and the @code{(3,2)} entry of @code{M_.lead_lag_incidence} be @code{15}. Then the @code{15}th column of the Jacobian is the derivative with respect to @code{c(+1)}.
774

775
@item +@var{FILENAME}/static.m
776
Contains the long run static model equations. Note that Dynare might introduce auxiliary equations and variables (@pxref{Auxiliary variables}). Outputs are the residuals of the static model equations in the order the equations were declared and the Jacobian of the static equations. Entry @code{(i,j)} of the Jacobian represents the derivative of the @code{i}th static model equation with respect to the @code{j}th model variable in declaration order.
777 778 779 780 781
@end table

@noindent
These files may be looked at to understand errors reported at the simulation stage.

782
@code{dynare} will then run the computing tasks by executing @file{+@var{FILENAME}/driver.m}.
783

784 785 786 787 788 789
@optionshead

@table @code

@item noclearall
By default, @code{dynare} will issue a @code{clear all} command to
790 791 792 793 794 795 796
MATLAB (<R2015b) or Octave, thereby deleting all workspace variables and
functions; this option instructs @code{dynare} not to clear the
workspace. Note that starting with Matlab 2015b @code{dynare} only
deletes the global variables and the functions using persistent
variables, in order to benefit from the JIT (Just In Time)
compilation. In this case the option instructs @code{dynare} not to
clear the globals and functions.
797

798 799
@item onlyclearglobals
By default, @code{dynare} will issue a @code{clear all} command to
800
MATLAB versions before 2015b and to Octave, thereby deleting all workspace variables; this
801 802 803 804 805
option instructs @code{dynare} to clear only the global variables
(@i{i.e.} @code{M_}, @code{options_}, @code{oo_},
@code{estim_params_}, @code{bayestopt_}, and @code{dataset_}), leaving
the other variables in the workspace.

806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
@item debug
Instructs the preprocessor to write some debugging information about the
scanning and parsing of the @file{.mod} file

@item notmpterms
Instructs the preprocessor to omit temporary terms in the static and
dynamic files; this generally decreases performance, but is used for
debugging purposes since it makes the static and dynamic files more
readable

@item savemacro[=@var{FILENAME}]
Instructs @code{dynare} to save the intermediary file which is obtained
after macro-processing (@pxref{Macro-processing language}); the saved
output will go in the file specified, or if no file is specified in
@file{@var{FILENAME}-macroexp.mod}

@item onlymacro
Instructs the preprocessor to only perform the macro-processing step,
and stop just after. Mainly useful for debugging purposes or for using
the macro-processor independently of the rest of Dynare toolbox.

@item nolinemacro
Instructs the macro-preprocessor to omit line numbering information in
829
the intermediary @file{.mod} file created after the macro-processing
830 831 832 833
step. Useful in conjunction with @code{savemacro} when one wants that to
reuse the intermediary @file{.mod} file, without having it cluttered by
line numbering directives.

834 835 836 837
@item noemptylinemacro
Passing this option removes all empty from the macro expanded mod file created
when the @code{savemacro} option is used.

838 839 840 841 842 843 844
@item onlymodel
Instructs the preprocessor to print only information about the model in the
driver file; no Dynare commands (other than the shocks statement and parameter
initializations) are printed and hence no computational tasks performed. NB:
the same ancillary files are created as would otherwise be created (dynamic,
static files, etc.).

845 846 847 848
@item nolog
Instructs Dynare to no create a logfile of this run in
@file{@var{FILENAME}.log}. The default is to create the logfile.

849 850 851 852 853 854
@item params_derivs_order=0|1|2
When @ref{identification}, @ref{dynare_sensitivity} (with identification), or
@ref{estimation_cmd} are present, this option is used to limit the order of the
derivatives with respect to the parameters that are calculated by the
preprocessor. @code{0} means no derivatives, @code{1} means first derivatives,
and @code{2} means second derivatives. Default: @code{2}
855

856 857 858
@item nowarn
Suppresses all warnings.

859 860 861
@anchor{json}
@item json=parse|transform|compute
Causes the preprocessor to output a version of the @file{.mod} file in JSON
862
format. If @code{parse} is passed, the output will be written after the parsing
863
of the @file{.mod} file to a file called @file{@var{FILENAME}/model/json/modfile.json}. If
864 865
@code{transform} is passed, the JSON output of the transformed model (maximum
lead of 1, minimum lag of -1, expectation operators substituted, etc.) will be
866 867
written to a file called @file{@var{FILENAME}/model/json/modfile.json} and the original,
untransformed model will be written in @file{@var{FILENAME}/model/json/modfile-original.json}. And
868
if @code{compute} is passed, the output is written after the computing pass. In
869 870 871 872
this case, the transformed model is written to @file{@var{FILENAME}/model/json/modfile.json}, the
original model is written to @file{@var{FILENAME}/model/json/model-original.json}, and the
dynamic and static files are written to @file{@var{FILENAME}/model/json/dynamic.json} and
@file{@var{FILENAME}/model/json/static.json}.
873 874 875 876 877 878 879 880

@item jsonstdout
Instead of writing output requested by @ref{json} to files, write to standard
out.

@item onlyjson
Quit processing once the output requested by @ref{json} has been written.

881
@item jsonderivsimple
882
Print a simplified version (excluding variable name(s) and lag information) of the
883 884
static and dynamic files in @file{@var{FILENAME}/model/json/static.json} and
@file{@var{FILENAME}/model/json/dynamic.json}.
885

886 887 888 889 890 891 892 893 894
@item warn_uninit
Display a warning for each variable or parameter which is not
initialized. @xref{Parameter initialization}, or
@ref{load_params_and_steady_state} for initialization of parameters.
@xref{Initial and terminal conditions}, or
@ref{load_params_and_steady_state} for initialization of endogenous
and exogenous variables.

@item console
895 896 897
Activate console mode. In addition to the behavior of
@code{nodisplay}, Dynare will not use graphical waitbars for long
computations.
898

899
@item nograph
900
Activate the @code{nograph} option (@pxref{nograph}), so that Dynare will not produce any
901 902
graph

903
@item nointeractive
Johannes Pfeifer 's avatar
Johannes Pfeifer committed
904 905
@anchor{nointeractive}
Instructs Dynare to not request user input.
906

907 908 909 910 911 912 913 914 915
@item nopathchange
By default Dynare will change Matlab/Octave's path if
@file{dynare/matlab} directory is not on top and if Dynare's routines
are overriden by routines provided in other toolboxes. If one wishes to
override Dynare's routines, the @code{nopathchange} options can be
used. Alternatively, the path can be temporarly modified by the user at
the top of the @file{*.mod} file (using Matlab/Octave's @code{addpath}
command).

916 917 918 919
@item nopreprocessoroutput
Prevent Dynare from printing the output of the steps leading up to the
preprocessor as well as the preprocessor output itself.

920 921 922 923 924 925 926 927 928
@item mexext=mex|mexw32|mexw64|mexmaci64|mexa64
The mex extension associated with your platform to be used when compiling
output associated with @code{use_dll}. NB: Dynare is able to set this
automatically, so you should not need to set it yourself.

@item matlabroot=@var{<<path>>}
The path to the Matlab installation for use with @code{use_dll}. NB: Dynare is
able to set this automatically, so you should not need to set it yourself.

929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949
@item parallel[=@var{CLUSTER_NAME}]
Tells Dynare to perform computations in parallel. If @var{CLUSTER_NAME}
is passed, Dynare will use the specified cluster to perform parallel
computations. Otherwise, Dynare will use the first cluster specified in
the configuration file. @xref{The Configuration File}, for more
information about the configuration file.

@item conffile=@var{FILENAME}
Specifies the location of the configuration file if it differs from the
default. @xref{The Configuration File}, for more information about the
configuration file and its default location.

@item parallel_slave_open_mode
Instructs Dynare to leave the connection to the slave node open after
computation is complete, closing this connection only when Dynare
finishes processing.

@item parallel_test
Tests the parallel setup specified in the configuration file without
executing the @file{.mod} file. @xref{The Configuration File}, for more
information about the configuration file.
950 951 952 953

@item -D@var{MACRO_VARIABLE}=@var{MACRO_EXPRESSION}
Defines a macro-variable from the command line (the same effect as using
the Macro directive @code{@@#define} in a model file, @pxref{Macro-processing language}).
954

955
@anchor{-I}
956 957 958 959 960
@item -I@var{<<path>>}
Defines a path to search for files to be included by the
macroprocessor (using the @ref{@@#include} command). Multiple
@code{-I} flags can be passed on the command line. The paths will be
searched in the order that the @code{-I} flags are passed and the
961 962
first matching file will be used. The flags passed here take priority
over those passed to @ref{@@#includepath}.
963

964
@item nostrict
965 966 967
Allows Dynare to issue a warning and continue processing when
@enumerate
@item there are more endogenous variables than equations
968
@item an undeclared symbol is assigned in @code{initval} or @code{endval}
969
@item an undeclared symbol is found in the @code{model} block; in this case, it is automatically declared exogenous
970
@item exogenous variables were declared but not used in the @code{model} block
971
@end enumerate
972 973 974 975

@item fast
Only useful with model option @code{use_dll}. Don't recompile the MEX
files when running again the same model file and the lists of variables
976 977 978 979
and the equations haven't changed. We use a 32 bit checksum, stored in
@code{<model filename>/checksum}. There is a very small probability that
the preprocessor misses a change in the model. In case of doubt, re-run
without the @code{fast} option.
980 981 982 983 984 985

@item minimal_workspace
Instructs Dynare not to write parameter assignments to parameter names
in the @file{.m} file produced by the preprocessor. This is
potentially useful when running @code{dynare} on a large @file{.mod}
file that runs into workspace size limitations imposed by MATLAB.
986 987 988 989

@item compute_xrefs
Tells Dynare to compute the equation cross references, writing them to the
output @file{.m} file.
990 991 992 993

@item stochastic
Tells Dynare that the model to be solved is stochastic. If no Dynare commands related to stochastic models (@code{stoch_simul}, @code{estimation}@dots{}) are present in the @code{.mod} file, Dynare understands by default that the model to be solved is deterministic.

994 995
@end table

996 997 998 999 1000
These options can be passed to the preprocessor by listing them after the name
of the @code{.mod} file. They can alternatively be defined in the first line of
the @file{.mod} file, this avoids typing them on the command line each time a
@file{.mod} file is to be run. This line must be a Dynare comment (@emph{ie}
must begin with @code{//}) and the options must be comma separated between
1001 1002 1003 1004
@code{--+ options:} and @code{+--}. Note that any text after the @code{+--}
will be discarded. As with the command line, if an option admits a value the
equal symbol must not be surrounded by spaces. For instance @code{json =
compute} is not correct, and should be written @code{json=compute}.
1005

1006 1007 1008
@outputhead

Depending on the computing tasks requested in the @file{.mod} file,
1009 1010 1011
executing the @code{dynare} command will leave variables containing
results in the workspace available for further processing. More
details are given under the relevant computing tasks.
1012

1013 1014
The @code{M_}, @code{oo_}, and @code{options_} structures are saved in
a file called @file{@var{FILENAME}_results.mat}. If they exist,
1015
@code{estim_params_}, @code{bayestopt_}, @code{dataset_}, @code{oo_recursive_} and
1016
@code{estimation_info} are saved in the same file.
1017 1018 1019 1020 1021

@examplehead

@example
dynare ramst
1022
dynare ramst.mod savemacro
1023 1024
@end example

1025 1026 1027 1028 1029 1030 1031
Alternatively the options can be specified in the first line of @file{ramst.mod}:

@example
// --+ options: savemacro, json=compute +--
@end example


1032 1033 1034 1035 1036 1037
@end deffn

The output of Dynare is left into three main variables in the
MATLAB/Octave workspace:

@defvr {MATLAB/Octave variable} M_
1038
Structure containing various information about the model.
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049
@end defvr

@defvr {MATLAB/Octave variable} options_
Structure contains the values of the various options used by Dynare
during the computation.
@end defvr

@defvr {MATLAB/Octave variable} oo_
Structure containing the various results of the computations.
@end defvr

1050 1051 1052 1053 1054 1055 1056 1057
@defvr {MATLAB/Octave variable} oo_recursive_
@anchor{oo_recursive_}
Cell array containing the @code{oo_} structures obtained when estimating the model 
for the different samples when performing recursive estimation and forecasting. 
The @code{oo_} structure obtained for the sample ranging to the @math{i}th observation 
is saved in the @math{i}th field. The fields for non-estimated endpoints are empty.
@end defvr

1058 1059 1060 1061

@node Dynare hooks
@section Dynare hooks

1062
It is possible to call pre and post Dynare preprocessor hooks written as MATLAB scripts.
1063
The script @file{@var{MODFILENAME}/hooks/priorprocessing.m} is executed before the
1064
call to Dynare's preprocessor, and  can be used to programmatically transform the mod file
1065
that will be read by the preprocessor. The script @file{@var{MODFILENAME}/hooks/postprocessing.m}
1066
is executed just after the call to Dynare's preprocessor, and can be used to programmatically
1067
transform the files generated by Dynare's preprocessor before actual computations start. The
Houtan Bastani's avatar
Houtan Bastani committed
1068
pre and/or post dynare preprocessor hooks are executed if and only if the aforementioned scripts
1069 1070 1071
are detected in the same folder as the the model file, @file{@var{FILENAME}.mod}.


1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
@node Understanding Preprocessor Error Messages
@section Understanding Preprocessor Error Messages

If the preprocessor runs into an error while processing your
@file{.mod} file, it will issue an error. Due to the way that a parser
works, sometimes these errors can be misleading. Here, we aim to
demystify these error messages.

The preprocessor issues error messages of the form:
@enumerate
@item @code{ERROR: <<file.mod>>: line A, col B: <<error message>>}
@item @code{ERROR: <<file.mod>>: line A, cols B-C: <<error message>>}
@item @code{ERROR: <<file.mod>>: line A, col B - line C, col D: <<error message>>}
@end enumerate
@noindent The first two errors occur on a single line, with error
two spanning multiple columns. Error three spans multiple rows.

Often, the line and column numbers are precise, leading you directly
to the offending syntax. Infrequently however, because of the way the
parser works, this is not the case. The most common example of
misleading line and column numbers (and error message for that matter)
is the case of a missing semicolon, as seen in the following example:
@example
varexo a, b
parameters c, ...;
@end example
@noindent In this case, the parser doesn't know a semicolon is missing at the
end of the @code{varexo} command until it begins parsing the second
line and bumps into the @code{parameters} command. This is because we
allow commands to span multiple lines and, hence, the parser cannot
know that the second line will not have a semicolon on it until it
gets there. Once the parser begins parsing the second line, it
realizes that it has encountered a keyword, @code{parameters}, which
it did not expect. Hence, it throws an error of the form: @code{ERROR:
<<file.mod>>: line 2, cols 0-9: syntax error, unexpected
PARAMETERS}. In this case, you would simply place a semicolon at the
end of line one and the parser would continue processing.

1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
@node Invoking the Dynare Preprocessor from the GNU/Linux or macOS Command Line
@section Invoking the Dynare Preprocessor from the GNU/Linux or macOS Command Line

You can invoke the preprocessor directly from the command line. In this way,
the preprocessor can be called a @file{.mod} file as explained above or on the
text of a @file{.mod} file as explained herein.

In certain circumstances, it may be useful to invoke the preprocessor on the
text of a @file{.mod} file. To do so, simply invoke the preprocessor by passing
it the text of your @file{.mod} file as the first argument. This argument
requires special care. First, any native Matlab statements contained in the
string representing your @file{.mod} file must be followed by a newline
character (@code{\n}). Further, any single-line comments must also be followed
by a newline character. Finally, any apostrophe's must be escaped with a
backslash (@i{i.e.}, @code{\'} instead of @code{'}.

Taking into account the considerations above, the file located in
@code{examples/example1.mod} could be run by executing:
@example
./dynare_m $'/* * Example 1 from F. Collard (2001): "Stochastic simulations
with DYNARE: * A practical guide" (see "guide.pdf" in the documentation
directory). */var y, c, k, a, h, b;varexo e, u;parameters beta, rho, alpha,
delta, theta, psi, tau;alpha = 0.36;rho = 0.95;tau = 0.025;beta = 0.99;delta =
0.025;psi = 0;theta = 2.95;phi = 0.1;\nmodel;c*theta*h^(1+psi)=(1-alpha)*y;k =
beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));y
= exp(a)*(k(-1)^alpha)*(h^(1-alpha));k = exp(b)*(y-c)+(1-delta)*k(-1);a =
rho*a(-1)+tau*b(-1) + e;b = tau*a(-1)+rho*b(-1) + u;end;initval;y =
1.08068253095672;c = 0.80359242014163;h = 0.29175631001732;k =
11.08360443260358;a = 0;b = 0;e = 0;u = 0;end;shocks;var e; stderr 0.009;var u;
stderr 0.009;var e, u = phi*0.009*0.009;end;stoch_simul;'
@end example

This produces the same output as when running dynare on a @file{.mod} file with
the basename of the output files being set to @code{mod_file_passed_as_string_}.

1145 1146 1147 1148
@node The Model file
@chapter The Model file

@menu
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
* Conventions::
* Variable declarations::
* Expressions::
* Parameter initialization::
* Model declaration::
* Auxiliary variables::
* Initial and terminal conditions::
* Shocks on exogenous variables::
* Other general declarations::
* Steady state::
* Getting information about the model::
* Deterministic simulation::
* Stochastic solution and simulation::
* Estimation::
1163 1164 1165
* Model Comparison::
* Shock Decomposition::
* Calibrated Smoother::
1166 1167 1168 1169 1170 1171
* Forecasting::
* Optimal policy::
* Sensitivity and identification analysis::
* Markov-switching SBVAR::
* Displaying and saving results::
* Macro-processing language::
1172
* Verbatim inclusion::
1173
* Misc commands::
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189
@end menu

@node Conventions
@section Conventions

A model file contains a list of commands and of blocks.  Each command
and each element of a block is terminated by a semicolon
(@code{;}). Blocks are terminated by @code{end;}.

Most Dynare commands have arguments and several accept options,
indicated in parentheses after the command keyword. Several options
are separated by commas.

In the description of Dynare commands, the following conventions are
observed:

1190
@itemize
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204

@item
optional arguments or options are indicated between square brackets:
@samp{[]};

@item
repreated arguments are indicated by ellipses: ``@dots{}'';

@item
mutually exclusive arguments are separated by vertical bars: @samp{|};

@item
@var{INTEGER} indicates an integer number;

1205
@item
1206 1207
@var{INTEGER_VECTOR} indicates a vector of integer numbers separated by spaces,
enclosed by square brackets;
1208

1209 1210
@item
@var{DOUBLE} indicates a double precision number. The following syntaxes
1211 1212
are valid: @code{1.1e3}, @code{1.1E3}, @code{1.1d3}, @code{1.1D3}. In
some places, infinite values @code{Inf} and @code{-Inf} are also allowed;
1213

Houtan Bastani's avatar
Houtan Bastani committed
1214 1215 1216 1217
@item
@var{NUMERICAL_VECTOR} indicates a vector of numbers separated by spaces,
enclosed by square brackets;

1218 1219 1220 1221 1222 1223 1224 1225
@item
@var{EXPRESSION} indicates a mathematical expression valid outside the
model description (@pxref{Expressions});

@item
@var{MODEL_EXPRESSION} indicates a mathematical expression valid in the
model description (@pxref{Expressions} and @ref{Model declaration});

1226 1227 1228 1229
@item
@var{MACRO_EXPRESSION} designates an expression of the macro-processor
(@pxref{Macro expressions});

1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
@item
@var{VARIABLE_NAME} indicates a variable name starting with an
alphabetical character and can't contain: @samp{()+-*/^=!;:@@#.} or
accentuated characters;

@item
@var{PARAMETER_NAME} indicates a parameter name starting with an
alphabetical character and can't contain: @samp{()+-*/^=!;:@@#.} or
accentuated characters;

@item
1241 1242
@var{LATEX_NAME} indicates a valid @LaTeX{} expression in math mode
(not including the dollar signs);
1243 1244 1245 1246 1247 1248

@item
@var{FUNCTION_NAME} indicates a valid MATLAB function name;

@item
@var{FILENAME} indicates a filename valid in the underlying operating
1249 1250
system; it is necessary to put it between quotes when specifying the
extension or if the filename contains a non-alphanumeric character;
1251 1252 1253 1254 1255 1256

@end itemize

@node Variable declarations
@section Variable declarations

1257 1258 1259 1260 1261 1262 1263
While Dynare allows the user to choose their own variable names, there are some restrictions 
to be kept in mind. First, variables and parameters must not have the same name as Dynare commands or
built-in functions. In this respect, Dynare is not case-sensitive. For example, do not use @var{Ln}
or @var{Sigma_e} to name your variable. Not conforming to this rule might yield hard-to-debug
error messages or crashes. Second, to minimize interference with MATLAB or Octave functions that
may be called by Dynare or user-defined steady state files, it is recommended to avoid using the name
of MATLAB functions. In particular when working with steady state files, do not use correctly-spelled greek 
Johannes Pfeifer 's avatar
Johannes Pfeifer committed
1264
names like @var{alpha}, because there are Matlab functions of the same name. Rather go for @var{alppha} or @var{alph}.
1265
Lastly, please do not name a variable or parameter @var{i}. This may interfere with the imaginary 
Johannes Pfeifer 's avatar
Johannes Pfeifer committed
1266 1267
number @var{i} and the index in many loops. Rather, name investment @var{invest}. Using @var{inv} is also not recommended
as it alread denotes the inverse operator.
1268

1269 1270
Declarations of variables and parameters are made with the following commands:

1271 1272 1273
@deffn Command var @var{VARIABLE_NAME} [$@var{LATEX_NAME}$] [(long_name=@var{QUOTED_STRING}|NAME=@var{QUOTED_STRING}@dots{})]@dots{};
@deffnx Command var (deflator = @var{MODEL_EXPRESSION}) @var{VARIABLE_NAME} [$@var{LATEX_NAME}$] [(long_name=@var{QUOTED_STRING}|NAME=@var{QUOTED_STRING}@dots{})]@dots{};
@deffnx Command var (log_deflator = @var{MODEL_EXPRESSION}) @var{VARIABLE_NAME} [$@var{LATEX_NAME}$] [(long_name=@var{QUOTED_STRING}|NAME=@var{QUOTED_STRING}@dots{})]@dots{};
1274 1275 1276 1277 1278

@descriptionhead

This required command declares the endogenous variables in the
model. @xref{Conventions}, for the syntax of @var{VARIABLE_NAME} and
1279 1280 1281
@var{MODEL_EXPRESSION}. Optionally it is possible to give a @LaTeX{}
name to the variable or, if it is nonstationary, provide information
regarding its deflator.
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299

@code{var} commands can appear several times in the file and Dynare will
concatenate them.

@optionshead

If the model is nonstationary and is to be written as such in the
@code{model} block, Dynare will need the trend deflator for the
appropriate endogenous variables in order to stationarize the model. The
trend deflator must be provided alongside the variables that follow this
trend.

@table @code

@item deflator = @var{MODEL_EXPRESSION}
The expression used to detrend an endogenous variable. All trend
variables, endogenous variables and parameters referenced in
@var{MODEL_EXPRESSION} must already have been declared by the
1300 1301 1302 1303 1304 1305 1306 1307 1308
@code{trend_var}, @code{log_trend_var}, @code{var} and
@code{parameters} commands. The deflator is assumed to be
multiplicative; for an additive deflator, use @code{log_deflator}.

@item log_deflator = @var{MODEL_EXPRESSION}
Same as @code{deflator}, except that the deflator is assumed to be
additive instead of multiplicative (or, to put it otherwise, the
declared variable is equal to the log of a variable with a
multiplicative trend).
1309 1310 1311 1312

@anchor{long_name}
@item long_name = @var{QUOTED_STRING}
This is the long version of the variable name. Its value is stored in
1313 1314
@code{M_.endo_names_long}. In case multiple @code{long_name} options are
provided, the last one will be used. Default: @var{VARIABLE_NAME}
1315

1316 1317 1318
@anchor{partitioning}
@item NAME = @var{QUOTED_STRING}
This is used to create a partitioning of variables. It results in the direct
1319 1320
output in the @file{.m} file analogous to:
@code{M_.endo_partitions.}@var{NAME}@code{ = }@var{QUOTED_STRING}@code{;}.
1321 1322 1323 1324 1325
@end table

@examplehead

@example
1326 1327
var c gnp cva (country=`US', state=`VA')
          cca (country=`US', state=`CA', long_name=`Consumption CA');
1328
var(deflator=A) i b;
Houtan Bastani's avatar
Houtan Bastani committed
1329
var c $C$ (long_name=`Consumption');
1330 1331 1332 1333
@end example

@end deffn

1334
@deffn Command varexo @var{VARIABLE_NAME} [$@var{LATEX_NAME}$] [(long_name=@var{QUOTED_STRING}|NAME=@var{QUOTED_STRING}@dots{})]@dots{};
1335 1336 1337 1338 1339

@descriptionhead

This optional command declares the exogenous variables in the model.
@xref{Conventions}, for the syntax of @var{VARIABLE_NAME}. Optionally it
1340
is possible to give a @LaTeX{} name to the variable.
1341 1342 1343 1344 1345 1346 1347

Exogenous variables are required if the user wants to be able to apply
shocks to her model.

@code{varexo} commands can appear several times in the file and Dynare
will concatenate them.

1348 1349 1350 1351
@optionshead
@table @code
@item long_name = @var{QUOTED_STRING}
Like @ref{long_name} but value stored in @code{M_.exo_names_long}.
1352

1353
@item NAME = @var{QUOTED_STRING}
1354 1355
Like @ref{partitioning} but @var{QUOTED_STRING} stored in
@code{M_.exo_partitions.}@var{NAME}.
1356 1357
@end table

1358 1359 1360 1361 1362 1363 1364 1365
@examplehead

@example
varexo m gov;
@end example

@end deffn

1366
@deffn Command varexo_det @var{VARIABLE_NAME} [$@var{LATEX_NAME}$] [(long_name=@var{QUOTED_STRING}|NAME=@var{QUOTED_STRING}@dots{})]@dots{};