Dynare: Introduction. Structure of a mod-file Additional insights I Dynare output Additional insights II Introduction to Dynare Alexander Kriwoluzky 1 1 Humboldt Universität zu Berlin [email protected]July 12, 2007 Alexander Kriwoluzky Introduction to Dynare
59
Embed
Introduction to Dynare - hu- · PDF fileDynare: Introduction. Structure of a mod-file Additional insights I Dynare output Additional insights II Introduction to Dynare Alexander Kriwoluzky1
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Declaration of the variables, parameters and shocksThe modelSolving and estimating the model
Outline
1 Dynare: Introduction.
2 Structure of a mod-fileDeclaration of the variables, parameters and shocksThe modelSolving and estimating the model
3 Additional insights ISteady state computationThe dataset
4 Dynare outputCharacteristics of the modelFigures and how to produce them
5 Additional insights II
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Declaration of the variables, parameters and shocksThe modelSolving and estimating the model
The command stoch_simul
The command ’stoch_simul’ starts the solution routine. - Itis the ’Do it’ function in Dynare.
It computes a Taylor approximation around the steadystate of order one or two.
It simulates data from the model.
Furthermore moments, autocorrelations and impulseresponses are computed.
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Declaration of the variables, parameters and shocksThe modelSolving and estimating the model
Options
Options set outside the command ’stoch_simul’:
’check’ - computes and displays the eigenvalues of themodel. Example: check;
’datatomfile’ - saves the simulated data in a m file.Example: datatomfile(’simuldata’,[])
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Declaration of the variables, parameters and shocksThe modelSolving and estimating the model
Options for ’stoch_simul’
Additional options can be set in brackets after ’stoch_ simul’:
’periods’ - specifies the number of simulation periodsperiods=1000;
’irf’ sets the number of periods for which to computeimpulse responses.
’nomoments’, ’nocorr’, ’nofunctions’: moments, correlationsor the approximated solution are not printed.
’order=1’ sets the order of the Taylor approximation (defaultis two).
Example: stoch_simul(irf=20, order=1,nomoments);
Have a look at the Dynare manual for complete description.
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Declaration of the variables, parameters and shocksThe modelSolving and estimating the model
Prior distribution of the parameters
For each parameter to be estimated a conjugate priordistribution has to be defined.There are four common prior distributions used in theliterature:
Beta distribution for parameters between 0 and 1.Gamma distribution for parameters restricted to be positive.InverseGamma distribution for the standard deviation of theshocks.Normal distribution.
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Declaration of the variables, parameters and shocksThe modelSolving and estimating the model
2 Structure of a mod-fileDeclaration of the variables, parameters and shocksThe modelSolving and estimating the model
3 Additional insights ISteady state computationThe dataset
4 Dynare outputCharacteristics of the modelFigures and how to produce them
5 Additional insights II
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Steady state computationThe dataset
The dataset
Observed variables are declared after varobs. You can includethe dataset in the following ways:
As matlab savefile (*.mat). Names of variables have tocorrespond to the ones declared under varobs.
As m-file. Again names of variables have to correspond tothe ones declared under varobs.
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Steady state computationThe dataset
Matching data to the model
The variables of the model are often log deviations from thesteady state with zero mean and no growth trend. To fit themodel and the data:
Detrend the data before by HP filter or a linear detrending.Compute first differences of the dataset and fit the modelby:
Declaring additional endogenous variables, for example:var y_obs .Augmenting the model block with observation equations,e.g.:
y_obs = y − y(−1)
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Outline
1 Dynare: Introduction.
2 Structure of a mod-fileDeclaration of the variables, parameters and shocksThe modelSolving and estimating the model
3 Additional insights ISteady state computationThe dataset
4 Dynare outputCharacteristics of the modelFigures and how to produce them
5 Additional insights II
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Summary of variables
Number of variables: 8Number of stochastic shocks: 3Number of state variables: 4Number of jumpers: 4Number of static variables: 2
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Further output
Matrix of Covariance of exogenous shocks
Recursive law of motion
Moments, Correlation and Autocorrelation of simulatedvariables
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Stored output
All results are stored in filename_results.mat:
dr_ contains e.g.:Recursive law of motion (ghx, ghu).EigenvaluesSteady state (ys)
oo_ contains e.g.:Posterior mode and stdMarginal densitySmoothed shocks
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Outline
1 Dynare: Introduction.
2 Structure of a mod-fileDeclaration of the variables, parameters and shocksThe modelSolving and estimating the model
3 Additional insights ISteady state computationThe dataset
4 Dynare outputCharacteristics of the modelFigures and how to produce them
5 Additional insights II
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Prior vs. Posterior
0.02 0.04 0.06 0.08 0.10
200
400
SE_eps_a
0 0.05 0.10
20
40
60
80
SE_eps_b
0 0.05 0.10
50
100
SE_eps_x
1.5 2 2.50
5
10
A
0.2 0.4 0.60
20
40
60
80
theta
0.985 0.99 0.9950
100
200
300
400
beta
0.02 0.03 0.040
50
100
150
delta
0.4 0.6 0.80
2
4
6
8
rho_a
0.2 0.4 0.6 0.8 1 1.20
1
2
3
rho_b
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Mode check
Add the option mode_check.
0.015 0.02 0.025 0.03−900
−890
−880
−870SE_eps_a
0.02 0.03 0.04−900
−895
−890
−885
−880SE_eps_b
6 8 10 12
x 10−3
−896.5
−896
−895.5SE_eps_x
1.5 2 2.5 3−1000
−500
0A
0.2 0.3 0.4 0.5−5
0
5x 10
4 theta
0.98 0.99 1 1.01−1000
−500
0beta
0.02 0.03 0.04−1000
−800
−600
−400delta
0.4 0.6 0.8−898
−896
−894
−892rho_a
0.4 0.6 0.8−898
−896
−894
−892rho_b
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Convergence of the Markov chain
Using simulation methods it is important to insure convergenceof the proposal distribution to the target distribution:
Dynare runs different, independent chains. Default=2. Setthe number of chains by: mh_blocks.
Longer chains are more likely to have converged. Set thenumber of draws by: mh_replic
The first draws should be discarded. Set the percentage ofdiscarded draws by: mh_drop.
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Multivariate diagnostics
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
3
4
5
6
7Interval
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
2
3
4
5
6m2
0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
5
10
15
20
25m3
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Univariate diagnostics
0.5 1 1.5 2
x 104
0.06
0.08
0.1
0.12A (Interval)
0.5 1 1.5 2
x 104
0.8
1
1.2
1.4
1.6x 10
−3 A (m2)
0.5 1 1.5 2
x 104
4
6
8
10x 10
−5 A (m3)
0.5 1 1.5 2
x 104
0.005
0.01
0.015
0.02theta (Interval)
0.5 1 1.5 2
x 104
0
1
2
3
4x 10
−5 theta (m2)
0.5 1 1.5 2
x 104
0
1
2
3
4x 10
−7 theta (m3)
0.5 1 1.5 2
x 104
2.2
2.4
2.6
2.8
3x 10
−3 beta (Interval)
0.5 1 1.5 2
x 104
6
8
10
12x 10
−7 beta (m2)
0.5 1 1.5 2
x 104
1
1.5
2x 10
−9 beta (m3)
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Bayesian impulse response function
Add bayesian_irf.
5 10 15 20 25 30 35 400
0.02
0.04
0.06y
5 10 15 20 25 30 35 40−0.02
0
0.02
0.04
0.06n
5 10 15 20 25 30 35 400
2
4
6x 10
−3 c
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
More Bayesian impulse response function
Add bayesian_irf.
5 10 15 20 25 30 35 400
0.005
0.01
0.015y
5 10 15 20 25 30 35 40−0.01
0
0.01
0.02
0.03n
5 10 15 20 25 30 35 40−10
−5
0
5x 10
−3 c
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Filtered and smoothed variables
filtered_vars triggers the computation of filtered variables,i.e. forecast on past information:
xt|t−1 = E [xt |It−1]
smoother computes posterior distribution of smoothedendogenous variables and shocks, i.e. infers about theunobserved state variables using all available informationup to T :
xt|T = E [xt |IT ]
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Filtered variables
100 200 300−0.2
−0.1
0
0.1
0.2n
100 200 300−1
−0.5
0
0.5x
100 200 300−0.1
−0.05
0
0.05
0.1eta_a
100 200 300−0.2
−0.1
0
0.1
0.2k
100 200 300−0.05
0
0.05eta_b
100 200 300−0.05
0
0.05eta_x
100 200 300−0.1
−0.05
0
0.05
0.1c
100 200 300−0.2
−0.1
0
0.1
0.2y
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Smoothed variables
100 200 3000
0.2
0.4
0.6
0.8n
100 200 300−2
−1
0
1x
100 200 300−0.1
−0.05
0
0.05
0.1eta_a
100 200 300−0.2
−0.1
0
0.1
0.2k
100 200 300−0.1
−0.05
0
0.05
0.1eta_b
100 200 300−0.1
−0.05
0
0.05
0.1eta_x
100 200 3000.9
1
1.1
1.2
1.3c
100 200 3001
1.2
1.4
1.6
1.8y
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Smoothed shocks
50 100 150 200 250 300−0.1
−0.05
0
0.05
0.1eps_a
50 100 150 200 250 300−0.1
−0.05
0
0.05
0.1eps_b
50 100 150 200 250 300−0.01
−0.005
0
0.005
0.01eps_x
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Characteristics of the modelFigures and how to produce them
Out of sample forecast
Add forecast=10 to forecast 10 periods.
11
1.5
2y
10
0.5
1n
10.9
1
1.1
1.2
1.3c
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Save some time
mode_file=filename_mode uses former mode. This modefile is automatically generated by Dynare. Don’t forget: Setmode_compute=0.
Continue an old markov chain: load_mh_file.
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Markov chain mechanism
Given θi−1, draw the parameter vector θ from a joint normaldistribution (proposal distribution):
θi ∼ N (θi , c2Σ)
where Σ denotes the inverse Hessian evaluated at theposterior mode and c a scaling factor.Denote the logobjective function as l(θ). The draw is thenaccepted with probability:
min(1, exp(l(θi) − l(θi−1)))
Repeat this until the distribution has converged to thetarget distribution.→ The average acceptance rate and therefore the speedof convergence depend on the scaling parameter c.
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Scaling the chain
Recommended is an accepted rate of about 0.23. Theoptimal scale factor has to be found by try and error.
mh_jscale sets the scaling parameter.
mh_init_scale allows for a wider distribution for the firstdraw.
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
From mod to m file
Dynare produces three m-files. It is possible to set all optionsdirectly in the m-files. The m-file named as the mod-filecontains all options. For example:
options_.mode_compute=0;
options_.mode_file=’filename_mode’;
options_.load_mh_file=1;
options_.mh_jscale=0.43;
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Dynare and nohup
Dynare cannot be started by a nohup command. Instead:
1 Run the Dynare command on your desktop.2 Open the now created m-file.3 Set the folder containing Dynare on the server. For
example: path(path,’../dynare_v3/matlab’)
4 Upload the m-files and your dataset.5 Run the m-file by the nohup command
Additionally, the matrices lgx_TeX_, lgy_TeX_,options_.varobs_TeX and estim_params_.tex have to bedefined.
lgx_TeX_ and lgy_TeX_ have to be defined globally:global lgx_TeX_ lgy_TeX_ ;
Run Dynare and stop it shortly afterwards.
Type lgy_.
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Create tex-tables II
Add the list to your mod-file in the following way:lgy_TeX_ = ’c’;lgy_TeX_ = strvcat(lgy_TeX_,’eta_a’);lgy_TeX_ = strvcat(lgy_TeX_,’eta_b’);lgy_TeX_ = strvcat(lgy_TeX_,’eta_x’);lgy_TeX_ = strvcat(lgy_TeX_,’k’);lgy_TeX_ = strvcat(lgy_TeX_,’n’);lgy_TeX_ = strvcat(lgy_TeX_,’x’);lgy_TeX_ = strvcat(lgy_TeX_,’y’);
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Create tex-tables III
Repeat this for:
lgx_ → lgx_TeX_
estim_params_.param_names → estim_params_.tex
options_.varobs → options_.varobs_TeX
Alexander Kriwoluzky Introduction to Dynare
Dynare: Introduction.Structure of a mod-file
Additional insights IDynare output
Additional insights II
Tex output
Prior distribution Prior mean Prior s.d. Post. mean HPD inf HPD sup