Commit a03af050 authored by sebastien's avatar sebastien
Browse files

undoing r2110 and r2111 changesets


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2112 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 464e2970
// example 1 from Collard's guide to Dynare
var y, c, k, a, h, b;
varexo e,u;
{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf420
{\fonttbl\f0\fswiss\fcharset77 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\paperw11900\paperh16840\margl1440\margr1440\vieww9000\viewh8400\viewkind0
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\ql\qnatural\pardirnatural
parameters beta, rho, beta, 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;
model;
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 = 5;
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(periods=2100);
\f0\fs24 \cf0 // example 1 from Collard's guide to Dynare \
var y, c, k, a, h, b; \
varexo e,u; \
\
parameters beta, rho, beta, 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; \
\
model; \
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 = 5; \
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(periods=2100); \
}
\ No newline at end of file
......
var y c k i l y_l w r z;
varexo e;
parameters beta psi delta alpha rho epsilon;
model;
(1/c) = beta*(1/c(+1))*(1+r(+1)-delta);
psi*c/(1-l) = w;
c+i = y;
y = (k(-1)^alpha)*(exp(z)*l)^(1-alpha);
w = y*((epsilon-1)/epsilon)*(1-alpha)/l;
r = y*((epsilon-1)/epsilon)*alpha/k(-1);
i = k-(1-delta)*k(-1);
y_l = y/l;
z = rho*z(-1)+e;
end;
varobs y;
initval;
k = 9;
c = 0.76;
l = 0.3;
w = 2.07;
r = 0.03;
z = 0;
e = 0;
end;
estimated_params;
alpha, beta_pdf, 0.35, 0.02;
beta, beta_pdf, 0.99, 0.002;
delta, beta_pdf, 0.025, 0.003;
psi, gamma_pdf, 1.75, 0.02;
rho, beta_pdf, 0.95, 0.05;
epsilon, gamma_pdf, 10, 0.003;
stderr e, inv_gamma_pdf, 0.01, inf;
var y c k i l y_l w r z;
varexo e;
parameters beta psi delta alpha rho epsilon;
model;
(1/c) = beta*(1/c(+1))*(1+r(+1)-delta);
psi*c/(1-l) = w;
c+i = y;
y = (k(-1)^alpha)*(exp(z)*l)^(1-alpha);
w = y*((epsilon-1)/epsilon)*(1-alpha)/l;
r = y*((epsilon-1)/epsilon)*alpha/k(-1);
i = k-(1-delta)*k(-1);
y_l = y/l;
z = rho*z(-1)+e;
end;
estimation(datafile=simuldataRBC,nobs=200,first_obs=500,mh_replic=2000,mh_nblocks=2,mh_drop=0.45,mh_jscale=0.8);
varobs y;
initval;
k = 9;
c = 0.76;
l = 0.3;
w = 2.07;
r = 0.03;
z = 0;
e = 0;
end;
estimated_params;
alpha, beta_pdf, 0.35, 0.02;
beta, beta_pdf, 0.99, 0.002;
delta, beta_pdf, 0.025, 0.003;
psi, gamma_pdf, 1.75, 0.02;
rho, beta_pdf, 0.95, 0.05;
epsilon, gamma_pdf, 10, 0.003;
stderr e, inv_gamma_pdf, 0.01, inf;
end;
estimation(datafile=simuldataRBC,nobs=200,first_obs=500,mh_replic=2000,mh_nblocks=2,mh_drop=0.45,mh_jscale=0.8);
// Adapted from Jesus Fernandez-Villaverde, Basic RBC Model with Monopolistic Competion Philadelphia, March 3, 2005
var y c k i l y_l w r z;
varexo e;
parameters beta psi delta alpha rho gamma sigma epsilon;
alpha = 0.33;
beta = 0.99;
delta = 0.023;
psi = 1.75;
rho = 0.95;
sigma = (0.007/(1-alpha));
epsilon = 10;
model;
(1/c) = beta*(1/c(+1))*(1+r(+1)-delta);
psi*c/(1-l) = w;
c+i = y;
y = (k(-1)^alpha)*(exp(z)*l)^(1-alpha);
w = y*((epsilon-1)/epsilon)*(1-alpha)/l;
r = y*((epsilon-1)/epsilon)*alpha/k(-1);
i = k-(1-delta)*k(-1);
y_l = y/l;
z = rho*z(-1)+e;
end;
initval;
k = 9;
c = 0.76;
l = 0.3;
w = 2.07;
r = 0.03;
z = 0;
e = 0;
end;
// Adapted from Jesus Fernandez-Villaverde, Basic RBC Model with Monopolistic Competion Philadelphia, March 3, 2005
var y c k i l y_l w r z;
varexo e;
parameters beta psi delta alpha rho gamma sigma epsilon;
alpha = 0.33;
beta = 0.99;
delta = 0.023;
psi = 1.75;
rho = 0.95;
sigma = (0.007/(1-alpha));
epsilon = 10;
model;
(1/c) = beta*(1/c(+1))*(1+r(+1)-delta);
psi*c/(1-l) = w;
c+i = y;
y = (k(-1)^alpha)*(exp(z)*l)^(1-alpha);
w = y*((epsilon-1)/epsilon)*(1-alpha)/l;
r = y*((epsilon-1)/epsilon)*alpha/k(-1);
i = k-(1-delta)*k(-1);
y_l = y/l;
z = rho*z(-1)+e;
end;
initval;
k = 9;
c = 0.76;
l = 0.3;
w = 2.07;
r = 0.03;
z = 0;
e = 0;
end;
steady;
check;
shocks;
var e = sigma^2;
end;
stoch_simul(periods=2100);
check;
shocks;
var e = sigma^2;
end;
steady;
stoch_simul(periods=2100);
......@@ -31,8 +31,6 @@ function CutSample(M_, options_, estim_params_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global M_ options_ estim_params_
npar = estim_params_.np+estim_params_.nvn+estim_params_.ncx+estim_params_.ncn+estim_params_.nvx;
DirectoryName = CheckPath('metropolis');
......
function moments=compute_model_moments(dr,SelectVariables,M_,options_)
%function moments=compute_model_moments(dr,M_,options_)
function moments=compute_model_moments(dr,M_,options,_)
%
% INPUTS
% dr: structure describing model solution
% SelectVariables: indices of selected variables
% M_: structure of Dynare options
% options_
%
......@@ -30,4 +28,4 @@ function moments=compute_model_moments(dr,SelectVariables,M_,options_)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
moments = th_autocovariances(dr,SelectVariables,M_,options_);
moments = th_autocovariances(dr,options_.varlist,M_,options_);
No preview for this file type
......@@ -99,19 +99,6 @@ if ~(exist('stab_map_','file')==6 | exist('stab_map_','file')==2),
end
end
if ~(exist('gsa_sdp','file')==6 | exist('gsa_sdp','file')==2),
dynare_root = strrep(which('dynare.m'),'dynare.m','');
ss_anova_path = [dynare_root 'gsa/ss_anova_recurs'];
if exist(ss_anova_path)
addpath(ss_anova_path,path)
else
disp('Download Dynare sensitivity routines at:')
disp('http://eemc.jrc.ec.europa.eu/softwareDYNARE-Dowload.htm')
disp(' ' )
error('Mapping routines missing!')
end
end
if options_gsa.morris,
options_gsa.redform=1;
......
function PosteriorOddsTable = model_comparison(ModelNames,ModelPriors,oo,options_,fname)
% Bayesian model comparison. This function computes Odds ratios and
% estimate a posterior density over a colletion of models.
%
% INPUTS
% ModelNames [string] m*1 cell array of string.
% ModelPriors [double] m*1 vector of prior probabilities
%
% OUTPUTS
% none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2007-2008 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
NumberOfModels = size(ModelNames,2);
disp(' ')
disp(' ')
if isempty(ModelPriors)
prior_flag = 0;% empty_prior=0
ModelPriors = ones(NumberOfModels,1)/NumberOfModels;
else % The prior density has to sum up to one.
prior_flag = 1;
improper = abs(sum(ModelPriors)-1)>1e-6;
if improper
disp('model_comparison:: The user supplied prior distribution over models is improper...')
disp('model_comparison:: The distribution is automatically rescaled!')
ModelPriors=ModelPriors/sum(ModelPriors);
end
end
% The marginal densities are based on Laplace approxiations (default) or
% modified harmonic mean estimators.
if isfield(options_,'model_comparison_approximation')
type = options_.model_comparison_approximation;
if strcmp(type,'Laplace')
type = 'LaplaceApproximation';
end
else
type = 'LaplaceApproximation';
end
% Get the estimated logged marginal densities.
MarginalLogDensity = zeros(NumberOfModels,1);
ShortModelNames = get_short_names(ModelNames);
iname = strmatch(fname,ShortModelNames,'exact');
for i=1:NumberOfModels
if i==iname
mstruct.oo_ = oo;
else
if strcmpi(ModelNames{i}(end-3:end),'.mod') | strcmpi(ModelNames{i}(end-3:end),'.dyn')
mstruct = load([ModelNames{i}(1:end-4) '_results.mat' ],'oo_');
else
mstruct = load([ModelNames{i} '_results.mat' ],'oo_');
end
end
try
eval(['MarginalLogDensity(i) = mstruct.oo_.MarginalDensity.' type ';'])
catch
if strcmpi(type,'LaplaceApproximation')
disp(['MODEL_COMPARISON: I cant''t find the Laplace approximation associated to model ' ModelNames{i}])
return
elseif strcmpi(type,'ModifiedHarmonicMean')
disp(['MODEL_COMPARISON: I cant''t find the modified harmonic mean estimate associated to model ' ModelNames{i}])
return
end
end
end
% In order to avoid overflow, we divide the numerator and the denominator
% of the Posterior Odds Ratio by the largest Marginal Posterior Density
lmpd = log(ModelPriors)+MarginalLogDensity;
[maxval,k] = max(lmpd);
elmpd = exp(lmpd-maxval);
% Now I display the posterior probabilities.
title = 'Model Comparison';
headers = strvcat('Model',ShortModelNames{:});
if prior_flag
labels = strvcat('Priors','Log Marginal Density','Bayes Ratio', ...
'Posterior Model Probability');
values = [ModelPriors';MarginalLogDensity';exp(lmpd-lmpd(1))'; ...
elmpd'/sum(elmpd)];
else
labels = strvcat('Priors','Log Marginal Density','Bayes Ratio','Posterior Odds Ratio', ...
'Posterior Model Probability');
values = [ModelPriors';MarginalLogDensity'; exp(MarginalLogDensity-MarginalLogDensity(1))'; ...
exp(lmpd-lmpd(1))'; elmpd'/sum(elmpd)];
end
table(title,headers,labels,values, 0, 15, 6);
function name = get_model_name_without_path(modelname)
idx = strfind(modelname,'\');
if isempty(idx)
idx = strfind(modelname,'/');
end
if isempty(idx)
name = modelname;
return
end
name = modelname(idx(end)+1:end);
function name = get_model_name_without_extension(modelname)
idx = strfind(modelname,'.mod');
if isempty(idx)
idx = strfind(modelname,'.dyn')
end
if isempty(idx)
name = modelname;
return
end
name = modelname(1:end-4);
function modellist = get_short_names(modelnames)
n = length(modelnames);
modellist = {};
for i=1:n
name = get_model_name_without_extension(modelnames{i});
name = get_model_name_without_path(name);
modellist = {modellist{:} name};
end
......@@ -46,10 +46,10 @@ for k=1:size(s1,1)
y = [y; oo_.endo_simul(strmatch(s1(k,:),M_.endo_names,'exact'),:)] ;
end
if options_.dsample == 0
if options_.smpl == 0
i = [M_.maximum_lag:size(oo_.endo_simul,2)]' ;
else
i = [options_.dsample(1)+M_.maximum_lag:options_.dsample(2)+M_.maximum_lag]' ;
i = [options_.smpl(1)+M_.maximum_lag:options_.smpl(2)+M_.maximum_lag]' ;
end
t = ['Plot of '] ;
......@@ -86,6 +86,9 @@ elseif rplottype == 2
end
end
% 02/28/01 MJ replaced bseastr by MATLAB's strmatch
% 06/19/01 MJ added 'exact' to strmatch calls
% 06/25/03 MJ correction when options_.smpl ~= 0
......
......@@ -49,19 +49,7 @@ function steady()
homotopy3(options_.homotopy_values, options_.homotopy_steps);
end
if options_.homotopy_mode == 1
homotopy1(options_.homotopy_param,options_.homotopy_exo, ...
options_.homotopy_exodet,options_.homotopy_steps);
elseif options_.homotopy_mode == 2
homotopy2(options_.homotopy_param,options_.homotopy_exo, ...
options_.homotopy_exodet,options_.homotopy_steps);
elseif options_.homotopy_mode == 3
homotopy3(options_.homotopy_param,options_.homotopy_exo, ...
options_.homotopy_exodet,options_.homotopy_steps);
else
steady_;
end
steady_;
disp(' ')
disp('STEADY-STATE RESULTS:')
......
......@@ -827,16 +827,16 @@ ModelComparisonStatement::writeOutput(ostream &output, const string &basename) c
{
options_list.writeOutput(output);
output << "ModelNames_ = {};" << endl;
output << "ModelPriors_ = [];" << endl;
output << "ModelNames_ = {};\n";
output << "ModelPriors_ = {};\n";
for(filename_list_type::const_iterator it = filename_list.begin();
it != filename_list.end(); it++)
{
output << "ModelNames_ = { ModelNames_{:} '" << it->first << "'};" << endl;
output << "ModelPriors_ = [ ModelPriors_ ; " << it->second << "];" << endl;
output << "ModelNames_ = { ModelNames_{:} '" << it->first << "};\n";
output << "ModelPriors_ = { ModelPriors_{:} '" << it->second << "};\n";
}
output << "model_comparison(ModelNames_,ModelPriors_,oo_,options_,M_.fname);" << endl;
output << "model_comparison(ModelNames_,ModelPriors_);\n";
}
PlannerObjectiveStatement::PlannerObjectiveStatement(ModelTree *model_tree_arg) :
......
......@@ -87,8 +87,7 @@ class ParsingDriver;
%token CALIB CALIB_VAR CHECK CONF_SIG CONSTANT CORR COVAR CUTOFF
%token DATAFILE DR_ALGO DROP DSAMPLE DYNASAVE DYNATYPE
%token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT
%token <string_val> FILENAME
%token FILENAME_KEYWORD FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS
%token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS
%token <string_val> FLOAT_NUMBER
%token FORECAST
%token GAMMA_PDF GAUSSIAN_ELIMINATION GCC_COMPILER GMRES GRAPH
......@@ -97,11 +96,10 @@ class ParsingDriver;
%token <string_val> INT_NUMBER
%token INV_GAMMA1_PDF INV_GAMMA2_PDF IRF
%token KALMAN_ALGO KALMAN_TOL