Merge branch 'master' into ecb-master

Fixed conflicts:
	matlab/backward/backward_model_forecast.m
	preprocessor/DynareBison.yy
	preprocessor/ParsingDriver.hh
	tests/practicing/datasaver.m
time-shift
Stéphane Adjemian (Scylla) 2017-08-30 11:51:56 +02:00
commit eb3f33df00
68 changed files with 397 additions and 1824 deletions

5
.gitignore vendored
View File

@ -197,6 +197,9 @@ mex/build/matlab/run_m2html.m
# MacOS stuff
.DS_Store
# Emacs stuff
scripts/dynare.elc
# MS-Sbvar
/contrib/ms-sbvar/*.prn
/contrib/ms-sbvar/*.dat
@ -215,4 +218,4 @@ tests/julia/rbc/rbc*.jl
octave-workspace
# VERSION generated file
VERSION
VERSION

View File

@ -907,6 +907,10 @@ 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).
@item nopreprocessoroutput
Prevent Dynare from printing the output of the steps leading up to the
preprocessor as well as the preprocessor output itself.
@item mingw
Tells Dynare that your MATLAB is configured for compiling MEX files with the
MinGW-compiler from TDM-GCC (@pxref{Compiler installation}). This option is
@ -1542,6 +1546,24 @@ a variable with a multiplicative trend).
@end deffn
@anchor{model_local_variable}
@deffn Command model_local_variable @var{VARIABLE_NAME} [$@var{LATEX_NAME}$] @dots{};
@descriptionhead
This optional command declares a model local variable. @xref{Conventions}, for
the syntax of @var{VARIABLE_NAME}. As you can create model local variables on
the fly in the model block (@pxref{model_local_variables_in_model_block}), the
interest of this command is primarily to assign a @var{LATEX_NAME} to the model
local variable.
@examplehead
@example
model_local_variable GDP_US $GDPUS$;
@end example
@end deffn
@node Expressions
@section Expressions
@ -1966,16 +1988,19 @@ equation. A homogenous equation looks like:
@var{MODEL_EXPRESSION};
@end example
@anchor{model_local_variables_in_model_block}
Inside the model block, Dynare allows the creation of @emph{model-local
variables}, which constitute a simple way to share a common expression
between several equations. The syntax consists of a pound sign
(@code{#}) followed by the name of the new model local variable (which
must @strong{not} be declared as in @ref{Variable declarations}), an equal
sign, and the expression for which this new variable will stand. Later
on, every time this variable appears in the model, Dynare will
substitute it by the expression assigned to the variable. Note that the
scope of this variable is restricted to the model block; it cannot be
used outside. A model local variable declaration looks like:
variables}, which constitute a simple way to share a common expression between
several equations. The syntax consists of a pound sign (@code{#}) followed by
the name of the new model local variable (which must @strong{not} be declared
as in @ref{Variable declarations}, but may have been declared by
@ref{model_local_variable}), an equal sign, and the expression for which this
new variable will stand. Later on, every time this variable appears in the
model, Dynare will substitute it by the expression assigned to the
variable. Note that the scope of this variable is restricted to the model
block; it cannot be used outside. To assign a @LaTeX{} name to the model local
variable, use the declaration syntax outlined by @ref{model_local_variable}. A
model local variable declaration looks like:
@example
# @var{VARIABLE_NAME} = @var{MODEL_EXPRESSION};
@end example
@ -2164,6 +2189,7 @@ equations using the @code{write_latex_static_model} command.
@anchor{write_latex_original_model}
@deffn Command write_latex_original_model ;
@deffnx Command write_latex_original_model (@var{OPTIONS}) ;
@descriptionhead
@ -2187,6 +2213,17 @@ appended to the variable names, as @LaTeX{} subscripts.
Compiling the @TeX{} file requires the following @LaTeX{} packages:
@code{geometry}, @code{fullpage}, @code{breqn}.
@optionshead
@table @code
@anchor{write_equation_tags}
@item write_equation_tags
Write the equation tags in the @LaTeX{} output. NB: the equation tags will be
interpreted with @LaTeX{} markups.
@end table
@end deffn
@anchor{write_latex_dynamic_model}
@ -2244,14 +2281,14 @@ For the required @LaTeX{} packages, @pxref{write_latex_original_model}.
@table @code
@item write_equation_tags
Write the equation tags in the @LaTeX{} output. NB: the equation tags will be
interpreted with @LaTeX{} markups.
@xref{write_equation_tags}
@end table
@end deffn
@deffn Command write_latex_static_model ;
@deffnx Command write_latex_static_model (@var{OPTIONS}) ;
@descriptionhead
@ -2279,6 +2316,15 @@ lags) of the dynamic model declared in the @code{model} block.
For the required @LaTeX{} packages, @pxref{write_latex_original_model}.
@optionshead
@table @code
@item write_equation_tags
@xref{write_equation_tags}
@end table
@end deffn
@node Auxiliary variables
@ -7646,6 +7692,9 @@ more details.
@item prefilter = @var{INTEGER}
@xref{prefilter}.
@item parameter_set = @code{calibration} | @code{prior_mode} | @code{prior_mean} | @code{posterior_mode} | @code{posterior_mean} | @code{posterior_median} | @code{mle_mode}
@xref{parameter_set}.
@item loglinear
@xref{loglinear}.
@ -7834,7 +7883,7 @@ Fields are of the form:
@end defvr
@deffn Command conditional_forecast (@var{OPTIONS}@dots{}) [@var{VARIABLE_NAME}@dots{}];
@deffn Command conditional_forecast (@var{OPTIONS}@dots{});
@anchor{conditional_forecast}
@descriptionhead
@ -7889,7 +7938,7 @@ constrained endogenous, and their constrained future path.
Option @code{controlled_varexo} is used to specify the structural shocks
which will be matched to generate the constrained path.
Use @code{plot_conditional_forecast} to graph the results.
Use @ref{plot_conditional_forecast} to graph the results.
@optionshead
@ -7985,7 +8034,8 @@ periods 1:5;
values 3;
end;
conditional_forecast(parameter_set = calibration, controlled_varexo = (e, u), replic = 3000);
conditional_forecast(parameter_set = calibration, controlled_varexo = (e, u),
replic = 3000);
plot_conditional_forecast(periods = 10) a y;
@end example
@ -8014,7 +8064,7 @@ it is necessary to specify the logarithm of the controlled variables.
@deffn Command plot_conditional_forecast [@var{VARIABLE_NAME}@dots{}];
@deffnx Command plot_conditional_forecast (periods = @var{INTEGER}) [@var{VARIABLE_NAME}@dots{}];
@anchor{plot_conditional_forecast}
@descriptionhead
Plots the conditional (plain lines) and unconditional (dashed lines) forecasts.

View File

@ -104,6 +104,10 @@ oo_.dr.restrict_columns = bayestopt_.smoother_restrict_columns;
[T,R,SteadyState,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_);
if info~=0
print_info(info,options_.noprint, options_);
return
end
oo_.dr.restrict_var_list = oldoo.restrict_var_list;
oo_.dr.restrict_columns = oldoo.restrict_columns;

View File

@ -235,7 +235,9 @@ else
% which files have to be copied to run remotely
NamFileInput(1,:) = {'',[M_.fname '_static.m']};
NamFileInput(2,:) = {'',[M_.fname '_dynamic.m']};
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
if M_.set_auxiliary_variables
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
end
if options_.steadystate_flag
if options_.steadystate_flag == 1
NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']};

View File

@ -91,7 +91,7 @@ end
initialconditions = transpose(initialcondition{endo_names{:}}.data);
% Compute forecast without shock
innovations = zeros(periods+max(M_.maximum_exo_lag, 1), M_.exo_nbr);
innovations = zeros(periods+M_.maximum_exo_lag, M_.exo_nbr);
if M_.maximum_exo_lag
if isempty(M_.exo_histval)
error('You need to set the past values for the exogenous variables!')
@ -105,9 +105,9 @@ forecasts.pointforecast = dseries(transpose(oo__0.endo_simul(idy,:)), initialcon
if withuncertainty
% Preallocate an array gathering the simulations.
ArrayOfForecasts = zeros(n, periods+1, B);
ArrayOfForecasts = zeros(n, periods+size(initialconditions, 2), B);
for i=1:B
innovations(max(M_.maximum_exo_lag, 1)+1:end,:) = transpose(sigma*randn(M_.exo_nbr, periods));
innovations(M_.maximum_exo_lag+1:end,:) = transpose(sigma*randn(M_.exo_nbr, periods));
oo__ = simul_backward_model(initialconditions, periods, options_, M_, oo_, innovations);
ArrayOfForecasts(:,:,i) = oo__.endo_simul(idy,:);
end

View File

@ -106,7 +106,7 @@ elseif isempty(varlist) && isempty(options_.endo_vars_for_moment_computations_in
end
if ~isempty(cas)
string = [ cas , ' will be computed for the ' num2str(M_.endo_nbr) ' endogenous variables'];
string = [ string ' of your model, this can be very long....'];
string = [ string ' of your model, this can take a long time ....'];
format_text(string, 10)
if options_.nointeractive
% Default behaviour is to consider all the endogenous variables.

View File

@ -52,7 +52,7 @@ else
% Dynare is on top of matlab's path! Nothing to do here...
return
else
str0 = sprintf('Dynare is not on top of matlab''s path!');
str0 = sprintf('Dynare is not on top of the Matlab/Octave path!');
% Check that this will not create a problem
MATLAB_PATH_ = path2cell(MATLAB_PATH);
DYNARE_ROUTINES = getallroutinenames(DYNARE_PATH, getalldirectories(DYNARE_PATH));
@ -66,19 +66,19 @@ else
warning off backtrace
skipline()
if length(COMMON_ROUTINES)==1
warning(sprintf('%s This can cause problems because the Dynare version of %s will be overriden.', str0, COMMON_ROUTINES{1}));
warning(sprintf('%s This can cause problems because the Dynare implementation of %s will be overriden.', str0, COMMON_ROUTINES{1}));
else
str1 = repmat('%s, ', 1, length(COMMON_ROUTINES)-1);
str2 = 'and %s ';
str3 = sprintf(['%s This can cause problems because the Dynare versions of ' str1, str2, 'will be overriden.'], str0, COMMON_ROUTINES{:});
str3 = sprintf(['%s This can cause problems because the Dynare implementations of ' str1, str2, 'will be overriden.'], str0, COMMON_ROUTINES{:});
warning(str3);
end
if change_path_flag
skipline()
msg = sprintf('I put %s on top of your matlab''s path. Note that this is a', DYNARE_PATH);
msg = sprintf(' %s a temporary change (ie will not affect future matlab''s session).', msg);
msg = sprintf(' %s If the ordering was intentional, ie if you really want to override the routines distributed with Dynare,', msg);
msg = sprintf(' %s you can change this behaviour using option nopathchange (see the reference manual).', msg);
msg = sprintf(['I put %s on top of your Matlab/Ocatve path.' ...
'\nNote that this is a temporary change (i.e. it will not affect future Matlab/Octave sessions).\n' ...
'\nIf the ordering was intentional, i.e. if you really want to override the routines distributed with Dynare,' ...
' you can change this behavior using the ''nopathchange'' option (see the reference manual).'], DYNARE_PATH);
warning(msg);
skipline()
rmpath(DYNARE_PATH)
@ -96,9 +96,9 @@ else
MATLAB_PATH = path2cell(MATLAB_PATH);
for i=1:length(mexpath)
if exist([mexpath{i} filesep 'mjdgges.' mexext],'file') && ismember([DYNARE_PATH filesep 'qz'],MATLAB_PATH)
msg = sprintf(['You put all the dynare/matlab subfolders in matlab''s path! Only ' ...
'the dynare/matlab folder (without subfolders)\nshould be in the ' ...
'path, Dynare will automatically add any required subfolders in the ' ...
msg = sprintf(['You put all the subfolders of the Dynare matlab folder in the Matlab/Octave path! Only ' ...
'the dynare ' filesep 'matlab folder (without subfolders)\nshould be in the ' ...
'path. Dynare automatically adds any required subfolders to the ' ...
'path.']);
error(msg)
end

View File

@ -136,11 +136,15 @@ xx(1:M.orig_endo_nbr) = x(1:M.orig_endo_nbr); %set values of original endogenous
% setting steady state of auxiliary variables that depends on original endogenous variables
if any([M.aux_vars.type] ~= 6) %auxiliary variables other than multipliers
needs_set_auxiliary_variables = 1;
fh = str2func([M.fname '_set_auxiliary_variables']);
s_a_v_func = @(z) fh(z,...
[oo.exo_steady_state,...
oo.exo_det_steady_state],...
params);
if M.set_auxiliary_variables
fh = str2func([M.fname '_set_auxiliary_variables']);
s_a_v_func = @(z) fh(z,...
[oo.exo_steady_state,...
oo.exo_det_steady_state],...
params);
else
s_a_v_func = z;
end
xx = s_a_v_func(xx);
else
needs_set_auxiliary_variables = 0;

View File

@ -49,11 +49,17 @@ end
change_path_flag = true;
% Filter out some options.
preprocessoroutput = true;
if nargin>1
id = strfind(varargin,'nopathchange');
if ~isempty(id)
if ~all(cellfun(@isempty, id))
change_path_flag = false;
varargin(id{1}) = [];
varargin(cellfun(@isempty, id) == 0) = [];
end
id = strfind(varargin, 'nopreprocessoroutput');
if ~all(cellfun(@isempty, id))
preprocessoroutput = false;
varargin(cellfun(@isempty, id) == 0) = [];
end
end
@ -61,7 +67,7 @@ end
check_matlab_path(change_path_flag);
% Detect if MEX files are present; if not, use alternative M-files
dynareroot = dynare_config;
dynareroot = dynare_config('', preprocessoroutput);
warning_config()
@ -177,10 +183,14 @@ end
if isempty(strfind(arch, '64'))
arch_ext = '32';
disp('Using 32-bit preprocessor');
if preprocessoroutput
disp('Using 32-bit preprocessor');
end
else
arch_ext = '64';
disp('Using 64-bit preprocessor');
if preprocessoroutput
disp('Using 64-bit preprocessor');
end
end
% Read options from the first line in mod/dyn file.
@ -208,18 +218,26 @@ for i=1:length(varargin)
command = [command ' ' varargin{i}];
end
fprintf('Calling Dynare with arguments: ');
disp(varargin);
if preprocessoroutput
fprintf('Calling Dynare with arguments: ');
disp(varargin);
end
[status, result] = system(command);
disp(result)
if status ~= 0 || preprocessoroutput
disp(result)
end
if ismember('onlymacro', varargin)
disp('Preprocesser stopped after macroprocessing step because of ''onlymacro'' option.');
if preprocessoroutput
disp('Preprocesser stopped after macroprocessing step because of ''onlymacro'' option.');
end
return
end
if ismember('onlyjson', varargin)
disp('Preprocesser stopped after preprocessing step because of ''onlyjson'' option.');
if preprocessoroutput
disp('Preprocesser stopped after preprocessing step because of ''onlyjson'' option.');
end
return;
end

View File

@ -609,10 +609,10 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
if nvn
number_of_plots_to_draw = 0;
index = [];
for i=1:n_varobs
if max(abs(measurement_error)) > 0.000000001
for obs_iter=1:n_varobs
if max(abs(measurement_error(obs_iter,:))) > options_.ME_plot_tol;
number_of_plots_to_draw = number_of_plots_to_draw + 1;
index = cat(1,index,i);
index = cat(1,index,obs_iter);
end
end
if ~options_.nograph
@ -627,7 +627,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
fh = dyn_figure(options_.nodisplay,'Name','Smoothed observation errors');
NAMES = [];
if options_.TeX, TeXNAMES = []; end
nstar0=min(nstar,number_of_plots_to_draw-(nbplt-1)*nstar);
nstar0=min(nstar,number_of_plots_to_draw-(plt-1)*nstar);
if gend==1
marker_string{1,1}='-ro';
marker_string{2,1}='-ko';

View File

@ -2,7 +2,7 @@ function [oo_,M_,options_,bayestopt_,Smoothed_variables_declaration_order_deviat
% Evaluate the smoother at parameters.
%
% INPUTS
% o parameters a string ('posterior mode','posterior mean','posterior median','prior mode','prior mean','mle_mode') or a vector of values for
% o parameters a string ('posterior mode','posterior mean','posterior median','prior mode','prior mean','mle_mode','calibration') or a vector of values for
% the (estimated) parameters of the model.
% o var_list subset of endogenous variables
% o M_ [structure] Definition of the model

View File

@ -46,9 +46,9 @@ steadystate_flag = options.steadystate_flag;
params = M.params;
exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state];
if length(M.aux_vars) > 0
if length(M.aux_vars) > 0 && ~steadystate_flag
h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']);
if ~steadystate_flag
if M.set_auxiliary_variables
ys_init = h_set_auxiliary_variables(ys_init,exo_ss,M.params);
end
end
@ -290,7 +290,9 @@ if check
info(1)= 20;
%make sure ys contains auxiliary variables in case of problem with dynare_solve
if length(M.aux_vars) > 0 && ~steadystate_flag
ys = h_set_auxiliary_variables(ys,exo_ss,M.params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,M.params);
end
end
resid = evaluate_static_model(ys,exo_ss,params,M,options);
info(2) = resid'*resid ;

View File

@ -74,14 +74,18 @@ h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']);
if isnan(updated_params_flag) || (updated_params_flag && any(isnan(params(~isnan(params))-params1(~isnan(params))))) %checks if new NaNs were added
info(1) = 24;
info(2) = NaN;
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
return
end
if updated_params_flag && ~isreal(params1)
info(1) = 23;
info(2) = sum(imag(params).^2);
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
return
end
@ -94,16 +98,22 @@ if length(M.aux_vars) > 0 && ~options.ramsey_policy
if debug
ys0 = ys;
end
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
if debug
ys1 = ys;
end
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
if debug
ys2 = ys;
end
if debug
ys = h_set_auxiliary_variables(ys,exo_ss,params);
if M.set_auxiliary_variables
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
ys3 = ys;
idx = find(abs(ys0-ys1)>0);
if ~isempty(idx)

View File

@ -467,6 +467,7 @@ options_.prior_trunc = 1e-10;
options_.smoother = 0;
options_.posterior_max_subsample_draws = 1200;
options_.sub_draws = [];
options_.ME_plot_tol=1e-6;
% options_.use_mh_covariance_matrix = 0;
options_.gradient_method = 2; %used by csminwel and newrat
options_.gradient_epsilon = 1e-6; %used by csminwel and newrat

View File

@ -51,6 +51,19 @@ if options_.periods == 0
error('PERFECT_FORESIGHT_SETUP: number of periods for the simulation isn''t specified')
end
if ~isempty(M_.det_shocks) && options_.periods<max([M_.det_shocks.periods])
% Some expected shocks happen after the terminal period.
mess = sprintf('Problem with the declaration of the expected shocks:\n');
for i=1:length(M_.det_shocks)
if any(M_.det_shocks(i).periods>options_.periods);
mess = sprintf('%s\n At least one expected value for %s has been declared after the terminal period.', mess, deblank(M_.exo_names(M_.det_shocks(i).exo_id,:)));
end
end
disp(mess)
skipline()
error('PERFECT_FORESIGHT_SETUP: Please check the declaration of the shocks or increase the value of the periods option.')
end
if ~options_.initval_file
if isempty(options_.datafile)
oo_=make_ex_(M_,options_,oo_);

View File

@ -108,10 +108,12 @@ if verbose
end
dynamicmodel = str2func([M.fname,'_dynamic']);
z = steadystate_y([ip; ic; in]);
x = repmat(transpose(steadystate_x), 1+M.maximum_exo_lag+M.maximum_exo_lead, 1);
% Evaluate the Jacobian of the dynamic model at the deterministic steady state.
[d1,jacobian] = dynamicmodel(z, transpose(steadystate_x), params, steadystate_y, 1);
[d1, jacobian] = dynamicmodel(z, x, params, steadystate_y, M.maximum_exo_lag+1);
% Check that the dynamic model was evaluated at the steady state.
if max(abs(d1))>1e-12

View File

@ -127,7 +127,9 @@ else
% which files have to be copied to run remotely
NamFileInput(1,:) = {'',[ModelName '_static.m']};
NamFileInput(2,:) = {'',[ModelName '_dynamic.m']};
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
if M.set_auxiliary_variables
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
end
if options_.steadystate_flag
if options_.steadystate_flag == 1
NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']};

View File

@ -294,7 +294,9 @@ else
% which files have to be copied to run remotely
NamFileInput(1,:) = {'',[M_.fname '_static.m']};
NamFileInput(2,:) = {'',[M_.fname '_dynamic.m']};
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
if M.set_auxiliary_variables
NamFileInput(3,:) = {'',[M_.fname '_set_auxiliary_variables.m']};
end
if options_.steadystate_flag
if options_.steadystate_flag == 1
NamFileInput(length(NamFileInput)+1,:)={'',[M_.fname '_steadystate.m']};

View File

@ -626,9 +626,7 @@ ForecastStatement::writeJsonOutput(ostream &output) const
output << "}";
}
RamseyModelStatement::RamseyModelStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg) :
symbol_list(symbol_list_arg),
RamseyModelStatement::RamseyModelStatement(const OptionsList &options_list_arg) :
options_list(options_list_arg)
{
}
@ -2606,15 +2604,16 @@ WriteLatexDynamicModelStatement::writeJsonOutput(ostream &output) const
output << "{\"statementName\": \"write_latex_dynamic_model\"}";
}
WriteLatexStaticModelStatement::WriteLatexStaticModelStatement(const StaticModel &static_model_arg) :
static_model(static_model_arg)
WriteLatexStaticModelStatement::WriteLatexStaticModelStatement(const StaticModel &static_model_arg, bool write_equation_tags_arg) :
static_model(static_model_arg),
write_equation_tags(write_equation_tags_arg)
{
}
void
WriteLatexStaticModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
static_model.writeLatexFile(basename);
static_model.writeLatexFile(basename, write_equation_tags);
}
void
@ -2623,15 +2622,16 @@ WriteLatexStaticModelStatement::writeJsonOutput(ostream &output) const
output << "{\"statementName\": \"write_latex_static_model\"}";
}
WriteLatexOriginalModelStatement::WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg) :
original_model(original_model_arg)
WriteLatexOriginalModelStatement::WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg, bool write_equation_tags_arg) :
original_model(original_model_arg),
write_equation_tags(write_equation_tags_arg)
{
}
void
WriteLatexOriginalModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
original_model.writeLatexOriginalFile(basename);
original_model.writeLatexOriginalFile(basename, write_equation_tags);
}
void
@ -4608,10 +4608,13 @@ void
CalibSmootherStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{
options_list.writeOutput(output);
OptionsList::string_options_t::const_iterator it = options_list.string_options.find("parameter_set");
if (it == options_list.string_options.end())
output << "options_.parameter_set = 'calibration';" << endl;
symbol_list.writeOutput("var_list_", output);
output << "options_.smoother = 1;" << endl;
output << "options_.order = 1;" << endl;
output << "[oo_,M_,options_,bayestopt_]=evaluate_smoother('calibration',var_list_,M_,oo_,options_,bayestopt_,estim_params_);" << endl;
output << "options_.smoother = 1;" << endl
<< "options_.order = 1;" << endl
<< "[oo_, M_, options_, bayestopt_] = evaluate_smoother(options_.parameter_set, var_list_, M_, oo_, options_, bayestopt_, estim_params_);" << endl;
}
void

View File

@ -186,11 +186,9 @@ public:
class RamseyModelStatement : public Statement
{
private:
const SymbolList symbol_list;
const OptionsList options_list;
public:
RamseyModelStatement(const SymbolList &symbol_list_arg,
const OptionsList &options_list_arg);
RamseyModelStatement(const OptionsList &options_list_arg);
virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings);
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
virtual void writeJsonOutput(ostream &output) const;
@ -662,8 +660,9 @@ class WriteLatexStaticModelStatement : public Statement
{
private:
const StaticModel &static_model;
const bool write_equation_tags;
public:
WriteLatexStaticModelStatement(const StaticModel &static_model_arg);
WriteLatexStaticModelStatement(const StaticModel &static_model_arg, bool write_equation_tags_arg);
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
virtual void writeJsonOutput(ostream &output) const;
};
@ -672,8 +671,9 @@ class WriteLatexOriginalModelStatement : public Statement
{
private:
const DynamicModel &original_model;
const bool write_equation_tags;
public:
WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg);
WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg, bool write_equation_tags_arg);
virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const;
virtual void writeJsonOutput(ostream &output) const;
};

View File

@ -537,6 +537,7 @@ DataTree::AddLocalVariable(int symb_id, expr_t value) throw (LocalVariableExcept
throw LocalVariableException(symbol_table.getName(symb_id));
local_variables_table[symb_id] = value;
local_variables_vector.push_back(symb_id);
}
expr_t

View File

@ -90,6 +90,8 @@ protected:
//! Stores local variables value (maps symbol ID to corresponding node)
map<int, expr_t> local_variables_table;
//! Stores the order of appearance of local variables in the model block. Needed following change in #563
vector<int> local_variables_vector;
//! Internal implementation of AddVariable(), without the check on the lag
VariableNode *AddVariableInternal(int symb_id, int lag);

View File

@ -2695,23 +2695,24 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
(julia ? "false" : "0"))
<< ";" << endl;
vector<int> state_var;
for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++)
// Loop on periods
for (int lag = -max_endo_lag; lag < 0; lag++)
try
{
getDerivID(symbol_table.getID(eEndogenous, variable_reordered[endoID]), lag);
if (lag < 0 && find(state_var.begin(), state_var.end(), variable_reordered[endoID]+1) == state_var.end())
state_var.push_back(variable_reordered[endoID]+1);
}
catch (UnknownDerivIDException &e)
{
}
//In case of sparse model, writes the block_decomposition structure of the model
if (block_decomposition)
{
vector<int> state_var, state_equ;
for (int endoID = 0; endoID < symbol_table.endo_nbr(); endoID++)
// Loop on periods
for (int lag = -max_endo_lag; lag < 0; lag++)
try
{
getDerivID(symbol_table.getID(eEndogenous, variable_reordered[endoID]), lag);
if (lag < 0 && find(state_var.begin(), state_var.end(), variable_reordered[endoID]+1) == state_var.end())
state_var.push_back(variable_reordered[endoID]+1);
}
catch (UnknownDerivIDException &e)
{
}
vector<int> state_equ;
int count_lead_lag_incidence = 0;
int max_lead, max_lag, max_lag_endo, max_lead_endo, max_lag_exo, max_lead_exo, max_lag_exo_det, max_lead_exo_det;
unsigned int nb_blocks = getNbBlocks();
@ -3129,13 +3130,13 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
KF_index_file.write(reinterpret_cast<char *>(&(*it)), sizeof(index_KF));
KF_index_file.close();
}
output << modstruct << "state_var = [";
for (vector<int>::const_iterator it = state_var.begin(); it != state_var.end(); it++)
output << *it << " ";
output << "];" << endl;
}
output << modstruct << "state_var = [";
for (vector<int>::const_iterator it=state_var.begin(); it != state_var.end(); it++)
output << *it << " ";
output << "];" << endl;
// Writing initialization for some other variables
if (!julia)
output << modstruct << "exo_names_orig_ord = [1:" << symbol_table.exo_nbr() << "];" << endl;
@ -3818,9 +3819,9 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const
assert(&symbol_table == &dynamic_model.symbol_table);
// Convert model local variables (need to be done first)
for (map<int, expr_t>::const_iterator it = local_variables_table.begin();
it != local_variables_table.end(); it++)
dynamic_model.AddLocalVariable(it->first, it->second->cloneDynamic(dynamic_model));
for (vector<int>::const_iterator it = local_variables_vector.begin();
it != local_variables_vector.end(); it++)
dynamic_model.AddLocalVariable(*it, local_variables_table.find(*it)->second->cloneDynamic(dynamic_model));
// Convert equations
for (size_t i = 0; i < equations.size(); i++)
@ -3841,7 +3842,8 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const
// Convert static_only equations
for (size_t i = 0; i < static_only_equations.size(); i++)
dynamic_model.addStaticOnlyEquation(static_only_equations[i]->cloneDynamic(dynamic_model),
static_only_equations_lineno[i]);
static_only_equations_lineno[i],
static_only_equations_equation_tags[i]);
dynamic_model.setLeadsLagsOrig();
}
@ -3942,9 +3944,9 @@ DynamicModel::toStatic(StaticModel &static_model) const
assert(&symbol_table == &static_model.symbol_table);
// Convert model local variables (need to be done first)
for (map<int, expr_t>::const_iterator it = local_variables_table.begin();
it != local_variables_table.end(); it++)
static_model.AddLocalVariable(it->first, it->second->toStatic(static_model));
for (vector<int>::const_iterator it = local_variables_vector.begin();
it != local_variables_vector.end(); it++)
static_model.AddLocalVariable(*it, local_variables_table.find(*it)->second->toStatic(static_model));
// Convert equations
int static_only_index = 0;
@ -3952,12 +3954,14 @@ DynamicModel::toStatic(StaticModel &static_model) const
{
// Detect if equation is marked [dynamic]
bool is_dynamic_only = false;
vector<pair<string, string> > eq_tags;
for (vector<pair<int, pair<string, string> > >::const_iterator it = equation_tags.begin();
it != equation_tags.end(); ++it)
if (it->first == i && it->second.first == "dynamic")
if (it->first == i)
{
is_dynamic_only = true;
break;
eq_tags.push_back(it->second);
if (it->second.first == "dynamic")
is_dynamic_only = true;
}
try
@ -3965,11 +3969,11 @@ DynamicModel::toStatic(StaticModel &static_model) const
// If yes, replace it by an equation marked [static]
if (is_dynamic_only)
{
static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index]);
static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index], static_only_equations_equation_tags[static_only_index]);
static_only_index++;
}
else
static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i]);
static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i], eq_tags);
}
catch (DataTree::DivisionByZeroException)
{
@ -4548,9 +4552,9 @@ DynamicModel::writeLatexFile(const string &basename, const bool write_equation_t
}
void
DynamicModel::writeLatexOriginalFile(const string &basename) const
DynamicModel::writeLatexOriginalFile(const string &basename, const bool write_equation_tags) const
{
writeLatexModelFile(basename + "_original", oLatexDynamicModel);
writeLatexModelFile(basename + "_original", oLatexDynamicModel, write_equation_tags);
}
void
@ -4870,13 +4874,18 @@ DynamicModel::isModelLocalVariableUsed() const
}
void
DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno)
DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags)
{
BinaryOpNode *beq = dynamic_cast<BinaryOpNode *>(eq);
assert(beq != NULL && beq->get_op_code() == oEqual);
vector<pair<string, string> > soe_eq_tags;
for (size_t i = 0; i < eq_tags.size(); i++)
soe_eq_tags.push_back(eq_tags[i]);
static_only_equations.push_back(beq);
static_only_equations_lineno.push_back(lineno);
static_only_equations_equation_tags.push_back(soe_eq_tags);
}
size_t

View File

@ -39,6 +39,9 @@ private:
//! Stores line numbers of equations declared as [static]
vector<int> static_only_equations_lineno;
//! Stores the equation tags of equations declared as [static]
vector<vector<pair<string, string> > > static_only_equations_equation_tags;
typedef map<pair<int, int>, int> deriv_id_table_t;
//! Maps a pair (symbol_id, lag) to a deriv ID
deriv_id_table_t deriv_id_table;
@ -308,7 +311,7 @@ public:
void replaceMyEquations(DynamicModel &dynamic_model) const;
//! Adds an equation marked as [static]
void addStaticOnlyEquation(expr_t eq, int lineno);
void addStaticOnlyEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags);
//! Returns number of static only equations
size_t staticOnlyEquationsNbr() const;
@ -320,7 +323,7 @@ public:
void writeLatexFile(const string &basename, const bool write_equation_tags) const;
//! Writes LaTeX file with the equations of the dynamic model (for the original model)
void writeLatexOriginalFile(const string &basename) const;
void writeLatexOriginalFile(const string &basename, const bool write_equation_tags) const;
virtual int getDerivID(int symb_id, int lag) const throw (UnknownDerivIDException);
virtual int getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException);

View File

@ -129,7 +129,7 @@ class ParsingDriver;
%token TEX RAMSEY_MODEL RAMSEY_POLICY RAMSEY_CONSTRAINTS PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL
%token <string_val> TEX_NAME
%token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED
%token VALUES VAR VAREXO VAREXO_DET VAROBS VAREXOBS PREDETERMINED_VARIABLES VAR_EXPECTATION PLOT_SHOCK_DECOMPOSITION
%token VALUES VAR VAREXO VAREXO_DET VAROBS VAREXOBS PREDETERMINED_VARIABLES VAR_EXPECTATION PLOT_SHOCK_DECOMPOSITION MODEL_LOCAL_VARIABLE
%token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL CROSSEQUATIONS COVARIANCE
%token XLS_SHEET XLS_RANGE LMMCP OCCBIN BANDPASS_FILTER COLORMAP VAR_MODEL QOQ YOY AOA
%left COMMA
@ -203,6 +203,7 @@ statement : parameters
| varexo
| varexo_det
| predetermined_variables
| model_local_variable
| change_type
| periods
| model
@ -494,6 +495,8 @@ predetermined_variables : PREDETERMINED_VARIABLES predetermined_variables_list '
parameters : PARAMETERS parameter_list ';';
model_local_variable : MODEL_LOCAL_VARIABLE model_local_variable_list ';';
named_var_elem : symbol EQUAL QUOTED_STRING
{
pair<string *, string *> *pr = new pair<string *, string *>($1, $3);
@ -638,6 +641,20 @@ predetermined_variables_list : predetermined_variables_list symbol
{ driver.add_predetermined_variable($1); }
;
model_local_variable_list : model_local_variable_list symbol
{ driver.declare_model_local_variable($2); }
| model_local_variable_list COMMA symbol
{ driver.declare_model_local_variable($3); }
| symbol
{ driver.declare_model_local_variable($1); }
| model_local_variable_list symbol TEX_NAME
{ driver.declare_model_local_variable($2, $3); }
| model_local_variable_list COMMA symbol TEX_NAME
{ driver.declare_model_local_variable($3, $4); }
| symbol TEX_NAME
{ driver.declare_model_local_variable($1, $2); }
;
change_type : CHANGE_TYPE '(' change_type_arg ')' change_type_var_list ';'
{ driver.change_type($3, $5); }
;
@ -2169,10 +2186,6 @@ ramsey_model : RAMSEY_MODEL ';'
{ driver.ramsey_model(); }
| RAMSEY_MODEL '(' ramsey_model_options_list ')' ';'
{ driver.ramsey_model(); }
| RAMSEY_MODEL symbol_list ';'
{ driver.ramsey_model(); }
| RAMSEY_MODEL '(' ramsey_model_options_list ')' symbol_list ';'
{ driver.ramsey_model(); }
;
ramsey_policy : RAMSEY_POLICY ';'
@ -2253,11 +2266,15 @@ write_latex_dynamic_model : WRITE_LATEX_DYNAMIC_MODEL ';'
;
write_latex_static_model : WRITE_LATEX_STATIC_MODEL ';'
{ driver.write_latex_static_model(); }
{ driver.write_latex_static_model(false); }
| WRITE_LATEX_STATIC_MODEL '(' WRITE_EQUATION_TAGS ')' ';'
{ driver.write_latex_static_model(true); }
;
write_latex_original_model : WRITE_LATEX_ORIGINAL_MODEL ';'
{ driver.write_latex_original_model(); }
{ driver.write_latex_original_model(false); }
| WRITE_LATEX_ORIGINAL_MODEL '(' WRITE_EQUATION_TAGS ')' ';'
{ driver.write_latex_original_model(true); }
;
shock_decomposition : SHOCK_DECOMPOSITION ';'
@ -2818,6 +2835,7 @@ calib_smoother_option : o_filtered_vars
| o_diffuse_kalman_tol
| o_diffuse_filter
| o_smoothed_state_uncertainty
| o_parameter_set
;
extended_path : EXTENDED_PATH ';'

View File

@ -111,6 +111,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2
<INITIAL>log_trend_var {BEGIN DYNARE_STATEMENT; return token::LOG_TREND_VAR;}
<INITIAL>predetermined_variables {BEGIN DYNARE_STATEMENT; return token::PREDETERMINED_VARIABLES;}
<INITIAL>parameters {BEGIN DYNARE_STATEMENT; return token::PARAMETERS;}
<INITIAL>model_local_variable {BEGIN DYNARE_STATEMENT; return token::MODEL_LOCAL_VARIABLE;}
<INITIAL>periods {BEGIN DYNARE_STATEMENT; return token::PERIODS;}
<INITIAL>model_info {BEGIN DYNARE_STATEMENT; return token::MODEL_INFO;}
<INITIAL>estimation {BEGIN DYNARE_STATEMENT; return token::ESTIMATION;}

View File

@ -62,7 +62,7 @@ usage()
#if defined(_WIN32) || defined(__CYGWIN32__) || defined(__MINGW32__)
<< " [cygwin] [msvc] [mingw]"
#endif
<< "[json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple]"
<< " [json=parse|check|transform|compute] [jsonstdout] [onlyjson] [jsonderivsimple] [nopathchange] [nopreprocessoroutput]"
<< endl;
exit(EXIT_FAILURE);
}

View File

@ -829,7 +829,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
mOutputFile << "M_.orig_eq_nbr = " << mod_file_struct.orig_eq_nbr << ";" << endl
<< "M_.eq_nbr = " << dynamic_model.equation_number() << ";" << endl
<< "M_.ramsey_eq_nbr = " << mod_file_struct.ramsey_eq_nbr << ";" << endl;
<< "M_.ramsey_eq_nbr = " << mod_file_struct.ramsey_eq_nbr << ";" << endl
<< "M_.set_auxiliary_variables = exist(['./' M_.fname '_set_auxiliary_variables.m'], 'file') == 2;" << endl;
if (dynamic_model.equation_number() > 0)
{

View File

@ -1418,24 +1418,25 @@ ModelTree::writeModelLocalVariables(ostream &output, ExprNodeOutputType output_t
for (size_t i = 0; i < equations.size(); i++)
equations[i]->collectVariables(eModelLocalVariable, used_local_vars);
for (set<int>::const_iterator it = used_local_vars.begin();
it != used_local_vars.end(); ++it)
{
int id = *it;
expr_t value = local_variables_table.find(id)->second;
value->writeExternalFunctionOutput(output, output_type, tt, tef_terms);
for (vector<int>::const_iterator it = local_variables_vector.begin();
it != local_variables_vector.end(); it++)
if (used_local_vars.find(*it) != used_local_vars.end())
{
int id = *it;
expr_t value = local_variables_table.find(id)->second;
value->writeExternalFunctionOutput(output, output_type, tt, tef_terms);
if (IS_C(output_type))
output << "double ";
else if (IS_JULIA(output_type))
output << " @inbounds ";
if (IS_C(output_type))
output << "double ";
else if (IS_JULIA(output_type))
output << " @inbounds ";
/* We append underscores to avoid name clashes with "g1" or "oo_" (see
also VariableNode::writeOutput) */
output << symbol_table.getName(id) << "__ = ";
value->writeOutput(output, output_type, tt, tef_terms);
output << ";" << endl;
}
/* We append underscores to avoid name clashes with "g1" or "oo_" (see
also VariableNode::writeOutput) */
output << symbol_table.getName(id) << "__ = ";
value->writeOutput(output, output_type, tt, tef_terms);
output << ";" << endl;
}
}
void
@ -1468,21 +1469,26 @@ ModelTree::writeJsonModelLocalVariables(ostream &output, deriv_node_temp_terms_t
}
output << "]"
<< ", \"model_local_variables\": [";
for (set<int>::const_iterator it = used_local_vars.begin();
it != used_local_vars.end(); ++it)
{
if (it != used_local_vars.begin())
output << ", ";
int id = *it;
expr_t value = local_variables_table.find(id)->second;
bool printed = false;
for (vector<int>::const_iterator it = local_variables_vector.begin();
it != local_variables_vector.end(); it++)
if (used_local_vars.find(*it) != used_local_vars.end())
{
int id = *it;
expr_t value = local_variables_table.find(id)->second;
/* We append underscores to avoid name clashes with "g1" or "oo_" (see
also VariableNode::writeOutput) */
output << "{\"variable\": \"" << symbol_table.getName(id) << "__\""
<< ", \"value\": \"";
value->writeJsonOutput(output, tt, tef_terms);
output << "\"}" << endl;
}
if (printed)
output << ", ";
else
printed = true;
/* We append underscores to avoid name clashes with "g1" or "oo_" (see
also VariableNode::writeOutput) */
output << "{\"variable\": \"" << symbol_table.getName(id) << "__\""
<< ", \"value\": \"";
value->writeJsonOutput(output, tt, tef_terms);
output << "\"}" << endl;
}
output << "]";
}
@ -1660,11 +1666,11 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
<< "\\footnotesize" << endl;
// Write model local variables
for (map<int, expr_t>::const_iterator it = local_variables_table.begin();
it != local_variables_table.end(); it++)
for (vector<int>::const_iterator it = local_variables_vector.begin();
it != local_variables_vector.end(); it++)
{
int id = it->first;
expr_t value = it->second;
int id = *it;
expr_t value = local_variables_table.find(id)->second;
content_output << "\\begin{dmath*}" << endl
<< symbol_table.getTeXName(id) << " = ";
@ -1690,7 +1696,7 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
content_output << iteqt->second.first;
if (iteqt->second.second.empty())
if (!(iteqt->second.second.empty()))
content_output << "= `" << iteqt->second.second << "'";
wrote_eq_tag = true;
@ -1723,7 +1729,7 @@ ModelTree::addEquation(expr_t eq, int lineno)
}
void
ModelTree::addEquation(expr_t eq, int lineno, vector<pair<string, string> > &eq_tags)
ModelTree::addEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags)
{
int n = equations.size();
for (size_t i = 0; i < eq_tags.size(); i++)

View File

@ -200,7 +200,7 @@ protected:
void compileModelEquations(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic) const;
//! Writes LaTeX model file
void writeLatexModelFile(const string &basename, ExprNodeOutputType output_type, const bool write_equation_tags = false) const;
void writeLatexModelFile(const string &basename, ExprNodeOutputType output_type, const bool write_equation_tags) const;
//! Sparse matrix of double to store the values of the Jacobian
/*! First index is equation number, second index is endogenous type specific ID */
@ -318,7 +318,7 @@ public:
//! Declare a node as an equation of the model; also give its line number
void addEquation(expr_t eq, int lineno);
//! Declare a node as an equation of the model, also giving its tags
void addEquation(expr_t eq, int lineno, vector<pair<string, string> > &eq_tags);
void addEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags);
//! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations
void addAuxEquation(expr_t eq);
//! Returns the number of equations in the model

View File

@ -2126,8 +2126,7 @@ ParsingDriver::ramsey_model()
{
if (!mod_file->symbol_table.exists("optimal_policy_discount_factor"))
declare_optimal_policy_discount_factor_parameter(data_tree->One);
mod_file->addStatement(new RamseyModelStatement(symbol_list, options_list));
symbol_list.clear();
mod_file->addStatement(new RamseyModelStatement(options_list));
options_list.clear();
}
@ -2165,15 +2164,15 @@ ParsingDriver::write_latex_dynamic_model(bool write_equation_tags)
}
void
ParsingDriver::write_latex_static_model()
ParsingDriver::write_latex_static_model(bool write_equation_tags)
{
mod_file->addStatement(new WriteLatexStaticModelStatement(mod_file->static_model));
mod_file->addStatement(new WriteLatexStaticModelStatement(mod_file->static_model, write_equation_tags));
}
void
ParsingDriver::write_latex_original_model()
ParsingDriver::write_latex_original_model(bool write_equation_tags)
{
mod_file->addStatement(new WriteLatexOriginalModelStatement(mod_file->original_model));
mod_file->addStatement(new WriteLatexOriginalModelStatement(mod_file->original_model, write_equation_tags));
}
void
@ -2409,7 +2408,7 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2)
if (!id->isInStaticForm())
error("An equation tagged [static] cannot contain leads, lags, expectations or STEADY_STATE operators");
dynamic_model->addStaticOnlyEquation(id, location.begin.line);
dynamic_model->addStaticOnlyEquation(id, location.begin.line, eq_tags);
}
else
model_tree->addEquation(id, location.begin.line, eq_tags);
@ -2424,6 +2423,15 @@ ParsingDriver::add_model_equal_with_zero_rhs(expr_t arg)
return add_model_equal(arg, model_tree->Zero);
}
void
ParsingDriver::declare_model_local_variable(string *name, string *tex_name)
{
declare_symbol(name, eModelLocalVariable, tex_name, NULL);
delete name;
if (tex_name != NULL)
delete tex_name;
}
void
ParsingDriver::declare_and_init_model_local_variable(string *name, expr_t rhs)
{

View File

@ -325,6 +325,8 @@ public:
void declare_parameter(string *name, string *tex_name = NULL, vector<pair<string *, string *> *> *partition_value = NULL);
//! Declares a VAR variable and adds to symbol_list
void declare_var_endogenous(string *name);
//! Declares a model local variable
void declare_model_local_variable(string *name, string *tex_name = NULL);
//! Declares a statement local variable
void declare_statement_local_variable(string *name);
//! Completes a subsample statement
@ -387,7 +389,7 @@ public:
void end_shocks(bool overwrite);
//! Writes a mshocks statement
void end_mshocks(bool overwrite);
//! Adds a deterministic chock or a path element inside a conditional_forecast_paths block
//! Adds a deterministic shock or a path element inside a conditional_forecast_paths block
void add_det_shock(string *var, bool conditional_forecast);
//! Adds a std error chock
void add_stderr_shock(string *var, expr_t value);
@ -591,9 +593,9 @@ public:
//! Adds a write_latex_dynamic_model statement
void write_latex_dynamic_model(bool write_equation_tags);
//! Adds a write_latex_static_model statement
void write_latex_static_model();
void write_latex_static_model(bool write_equation_tags);
//! Adds a write_latex_original_model statement
void write_latex_original_model();
void write_latex_original_model(bool write_equation_tags);
//! BVAR marginal density
void bvar_density(string *maxnlags);
//! BVAR forecast

View File

@ -2112,9 +2112,9 @@ StaticModel::writeChainRuleDerivative(ostream &output, int eqr, int varr, int la
}
void
StaticModel::writeLatexFile(const string &basename) const
StaticModel::writeLatexFile(const string &basename, bool write_equation_tags) const
{
writeLatexModelFile(basename + "_static", oLatexStaticModel);
writeLatexModelFile(basename + "_static", oLatexStaticModel, write_equation_tags);
}
void
@ -2130,6 +2130,11 @@ StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type)
void
StaticModel::writeSetAuxiliaryVariables(const string &basename, const bool julia) const
{
ostringstream output_func_body;
writeAuxVarRecursiveDefinitions(output_func_body, oMatlabStaticModel);
if (output_func_body.str().empty())
return;
string func_name = basename + "_set_auxiliary_variables";
string filename = julia ? func_name + ".jl" : func_name + ".m";
@ -2148,10 +2153,8 @@ StaticModel::writeSetAuxiliaryVariables(const string &basename, const bool julia
<< comment << " Status : Computes static model for Dynare" << endl
<< comment << endl
<< comment << " Warning : this file is generated automatically by Dynare" << endl
<< comment << " from model file (.mod)" << endl
<< endl;
writeAuxVarRecursiveDefinitions(output, oMatlabStaticModel);
<< comment << " from model file (.mod)" << endl << endl
<< output_func_body.str();
}
void

View File

@ -183,7 +183,7 @@ public:
void writeParamsDerivativesFile(const string &basename, bool julia) const;
//! Writes LaTeX file with the equations of the static model
void writeLatexFile(const string &basename) const;
void writeLatexFile(const string &basename, const bool write_equation_tags) const;
//! Writes initializations in oo_.steady_state or steady state file for the auxiliary variables
void writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const;

View File

@ -180,6 +180,7 @@ MODFILES = \
simul/simul_ZLB_purely_forward.mod \
simul/simul_ZLB_purely_forward_no_solution.mod \
simul/Irreversible_investment.mod \
simul/linear_state_space_arma.mod \
conditional_forecasts/2/fs2000_est.mod \
conditional_forecasts/3/fs2000_conditional_forecast_initval.mod \
conditional_forecasts/4/fs2000_conditional_forecast_histval.mod \

View File

@ -38,6 +38,6 @@ perfect_foresight_solver;
rplot c;
rplot k;
if ~exist('ramst.json') || exist('ramst.log')
error('dynare command did not honour the options provided in the mod file!')
end
if ~exist('./ramst.json', 'file') || exist('./ramst.log', 'file')
error('The dynare command did not honor the options provided in the mod file!')
end

View File

@ -73,3 +73,4 @@ varobs gp_obs gy_obs;
options_.solve_tolf = 1e-12;
estimation(order=1,datafile=fsdat_simul,nobs=192,loglinear,mh_replic=2000,mh_nblocks=2,mh_jscale=0.8,moments_varendo,consider_only_observed);
calib_smoother(parameter_set=posterior_mean) y;

View File

@ -1,47 +0,0 @@
periods 500;
var dc, dd, v_c, v_d, x;
varexo e_c, e_x, e_d;
parameters DELTA THETA PSI MU_C MU_D RHO_X LAMBDA_DX;
DELTA=.99;
PSI=1.5;
THETA=(1-7.5)/(1-1/PSI);
MU_C=0.0015;
MU_D=0.0015;
RHO_X=.979;
LAMBDA_DX=3;
model;
v_c = DELTA^THETA * exp((-THETA/PSI)*dc(+1) + (THETA-1)*log((1+v_c(+1))*exp(dc(+1))/v_c) ) * (1+v_c(+1))*exp(dc(+1));
v_d = DELTA^THETA * exp((-THETA/PSI)*dc(+1) + (THETA-1)*log((1+v_c(+1))*exp(dc(+1))/v_c) ) * (1+v_d(+1))*exp(dd(+1));
dc = MU_C + x(-1) + e_c;
dd = MU_D + LAMBDA_DX*x(-1) + e_d;
x = RHO_X * x(-1) + e_x;
end;
initval;
v_c=15;
v_d=15;
dc=MU_C;
dd=MU_D;
x=0;
e_c=0;
e_x=0;
e_d=0;
end;
shocks;
var e_c;
stderr .0078;
var e_x;
stderr .0078*.044;
var e_d;
stderr .0078*4.5;
end;
steady(solve_algo=0);
check;
stoch_simul(dr_algo=1, order=1, periods=1000, irf=30);
datasaver('simudata',[]);

View File

@ -1,58 +0,0 @@
var dc, dd, v_c, v_d, x;
varexo e_c, e_x, e_d;
parameters DELTA THETA PSI MU_C MU_D RHO_X LAMBDA_DX;
DELTA=.99;
PSI=1.5;
THETA=(1-7.5)/(1-1/PSI);
MU_C=0.0015;
MU_D=0.0015;
RHO_X=.979;
LAMBDA_DX=3;
model;
v_c = DELTA^THETA * exp((-THETA/PSI)*dc(+1) + (THETA-1)*log((1+v_c(+1))*exp(dc(+1))/v_c) ) * (1+v_c(+1))*exp(dc(+1));
v_d = DELTA^THETA * exp((-THETA/PSI)*dc(+1) + (THETA-1)*log((1+v_c(+1))*exp(dc(+1))/v_c) ) * (1+v_d(+1))*exp(dd(+1));
dc = MU_C + x(-1) + e_c;
dd = MU_D + LAMBDA_DX*x(-1) + e_d;
x = RHO_X * x(-1) + e_x;
end;
initval;
v_c=15;
v_d=15;
dc=MU_C;
dd=MU_D;
x=0;
e_c=0;
e_x=0;
e_d=0;
end;
shocks;
var e_d; stderr .001;
var e_c; stderr .001;
var e_x; stderr .001;
end;
steady;
estimated_params;
DELTA, beta_pdf, 0.98,.005;
THETA,normal_pdf,-19.5, 0.0025;
PSI,normal_pdf,1.6, 0.1;
MU_C,normal_pdf,0.001, 0.001;
MU_D,normal_pdf,0.001, 0.001;
RHO_X,normal_pdf,.98, 0.005;
LAMBDA_DX,normal_pdf,3, 0.05;
stderr e_d,inv_gamma_pdf,.0025, 30;
stderr e_x,inv_gamma_pdf,.0003, 30;
stderr e_c,inv_gamma_pdf,.01, 30;
end;
varobs v_d dd dc;
estimation(datafile=simudata,mh_replic=1000,mh_jscale=.4,nodiagnostic);

View File

@ -1,42 +0,0 @@
var x y;
varexo e_x e_u;
parameters rho sig_x sig_u mu_y;
rho = .98;
mu_y=.015;
sig_x=0.00025;
sig_u=.0078;
model(linear);
x=rho*x(-1) + sig_x*e_x;
y=mu_y + x(-1) + sig_u*e_u;
end;
initval;
x=0;
y=mu_y;
end;
steady;
shocks;
var e_x;
stderr 1;
var e_u;
stderr 1;
end;
estimated_params;
rho, beta_pdf, .98, .01;
mu_y, uniform_pdf, .005, .0025;
sig_u, inv_gamma_pdf, .003, inf;
sig_x, inv_gamma_pdf, .003, inf;
// The syntax for to input the priors is the following:
// variable name, prior distribution, parameters of distribution.
end;
varobs y;
estimation(datafile=data_consRicardoypg,first_obs=1,nobs=227,mh_replic=5000,mh_nblocks=1,mh_jscale=1);

View File

@ -1,44 +0,0 @@
var x y;
varexo e_x e_u;
parameters rho sig_x sig_u mu_y;
rho = .98;
mu_y=.015;
sig_x=0.00025;
sig_u=.0078;
model(linear);
x=rho*x(-1) + sig_x*e_x;
y=mu_y + x(-1) + sig_u*e_u;
end;
initval;
x=0;
y=mu_y;
end;
steady;
shocks;
var e_x;
stderr 1;
var e_u;
stderr 1;
end;
estimated_params;
// ML estimation setup
// parameter name, initial value, boundaries_low, ..._up;
rho, 0, -0.99, 0.999; // use this for unconstrained max likelihood
// rho, .98, .975, .999 ; // use this for long run risk model
// sig_x, .0004,.0001,.05 ; // use this for the long run risk model
sig_x, .0005, .00000000001, .01; // use this for unconstrained max likelihood
sig_u, .007,.001, .1;
mu_y, .014, .0001, .04;
end;
varobs y;
estimation(datafile=data_consRicardoypg,first_obs=1,nobs=227,mh_replic=0,mode_compute=4,mode_check);

View File

@ -1,79 +0,0 @@
// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent
var c k;
varexo taui tauc tauk g;
parameters bet gam del alpha A;
bet=.95;
gam=2;
del=.2;
alpha=.33;
A=1;
model;
k=A*k(-1)^alpha+(1-del)*k(-1)-c-g;
c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+
((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1));
end;
initval;
k=1.5;
c=0.6;
g = 0.2;
tauc = 0;
taui = 0;
tauk = 0;
end;
steady;
endval;
k=1.5;
c=0.4;
g =.4;
tauc =0;
taui =0;
tauk =0;
end;
steady;
shocks;
var g;
periods 1:9;
values 0.2;
end;
simul(periods=100);
co=ys0_(var_index('c'));
ko = ys0_(var_index('k'));
go = ex_(1,1);
rbig0=1/bet;
rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam));
rq0=alpha*A*ko^(alpha-1);
rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1);
wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1);
wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1);
sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del);
sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del);
figure
subplot(2,3,1)
plot([ko*ones(100,1) y_(var_index('k'),1:100)' ])
title('k')
subplot(2,3,2)
plot([co*ones(100,1) y_(var_index('c'),2:101)' ])
title('c')
subplot(2,3,3)
plot([rbig0*ones(100,1) rbig' ])
title('R')
subplot(2,3,4)
plot([wq0*ones(100,1) wq' ])
title('w/q')
subplot(2,3,5)
plot([sq0*ones(100,1) sq' ])
title('s/q')
subplot(2,3,6)
plot([rq0*ones(100,1) rq' ])
title('r/q')
print -depsc fig1131.ps

View File

@ -1,130 +0,0 @@
// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent
// This is a commented version of the program given in the handout.
// Note: y_ records the simulated endogenous variables in alphabetical order
// ys0_ records the initial steady state
// ys_ records the terminal steady state
// We check that these line up at the end points
// Note: y_ has ys0_ in first column, ys_ in last column, explaining why it is 102 long;
// The sample of size 100 is in between.
// Warning: we align c, k, and the taxes to exploit the dynare syntax. See comments below.
// So k in the program corresponds to k_{t+1} and the same timing holds for the taxes.
//Declares the endogenous variables;
var c k;
//declares the exogenous variables // investment tax credit, consumption tax, capital tax, government spending
varexo taui tauc tauk g;
parameters bet gam del alpha A;
bet=.95; // discount factor
gam=2; // CRRA parameter
del=.2; // depreciation rate
alpha=.33; // capital's share
A=1; // productivity
// Alignment convention:
// g tauc taui tauk are now columns of ex_. Because of a bad design decision
// the date of ex_(1,:) doesn't necessarily match the date in y_. Whether they match depends
// on the number of lag periods in endogenous versus exogenous variables.
// In this example they match because tauc(-1) and taui(-1) enter the model.
// These decisions and the timing conventions mean that
// y_(:,1) records the initial steady state, while y_(:,102) records the terminal steady state values.
// For j > 2, y_(:,j) records [c(j-1) .. k(j-1) .. G(j-1)] where k(j-1) means
// end of period capital in period j-1, which equals k(j) in chapter 11 notation.
// Note that the jump in G occurs in y_(;,11), which confirms this timing.
// the jump occurs now in ex_(11,1)
model;
// equation 11.3.8.a
k=A*k(-1)^alpha+(1-del)*k(-1)-c-g;
// equation 11.3.8e + 11.3.8.g
c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+
((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1));
end;
initval;
k=1.5;
c=0.6;
g = 0.2;
tauc = 0;
taui = 0;
tauk = 0;
end;
steady; // put this in if you want to start from the initial steady state, comment it out to start from the indicated values
endval; // The following values determine the new steady state after the shocks.
k=1.5;
c=0.4;
g =.4;
tauc =0;
taui =0;
tauk =0;
end;
steady; // We use steady again and the enval provided are initial guesses for dynare to compute the ss.
// The following lines produce a g sequence with a once and for all jump in g
shocks;
// we use shocks to undo that for the first 9 periods and leave g at
// it's initial value of 0
var g;
periods 1:9;
values 0.2;
end;
// now solve the model
simul(periods=100);
// Note: y_ records the simulated endogenous variables in alphabetical order
// ys0_ records the initial steady state
// ys_ records the terminal steady state
// check that these line up at the end points
y_(:,1) -ys0_(:)
y_(:,102) - ys_(:)
// Compute the initial steady state for consumption to later do the plots.
co=ys0_(var_index('c'));
ko = ys0_(var_index('k'));
// g is in ex_(:,1) since it is stored in alphabetical order
go = ex_(1,1)
// The following equation compute the other endogenous variables use in the plots below
// Since they are function of capital and consumption, so we can compute them from the solved
// model above.
// These equations were taken from page 333 of RMT2
rbig0=1/bet;
rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam));
rq0=alpha*A*ko^(alpha-1);
rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1);
wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1);
wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1);
sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del);
sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del);
//Now we plot the responses of the endogenous variables to the shock.
figure
subplot(2,3,1)
plot([ko*ones(100,1) y_(var_index('k'),1:100)' ]) // note the timing: we lag capital to correct for syntax
title('k')
subplot(2,3,2)
plot([co*ones(100,1) y_(var_index('c'),2:101)' ])
title('c')
subplot(2,3,3)
plot([rbig0*ones(100,1) rbig' ])
title('R')
subplot(2,3,4)
plot([wq0*ones(100,1) wq' ])
title('w/q')
subplot(2,3,5)
plot([sq0*ones(100,1) sq' ])
title('s/q')
subplot(2,3,6)
plot([rq0*ones(100,1) rq' ])
title('r/q')

View File

@ -1,79 +0,0 @@
// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent
var c k;
varexo taui tauc tauk g;
parameters bet gam del alpha A;
bet=.95;
gam=2;
del=.2;
alpha=.33;
A=1;
model;
k=A*k(-1)^alpha+(1-del)*k(-1)-c-g;
c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+
((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1));
end;
initval;
k=1.5;
c=0.6;
g = 0.2;
tauc = 0;
taui = 0;
tauk = 0;
end;
steady;
endval;
k=1.5;
c=0.6;
g = 0.2;
tauc =0.2;
taui =0;
tauk =0;
end;
steady;
shocks;
var tauc;
periods 1:9;
values 0;
end;
simul(periods=100);
co=ys0_(var_index('c'));
ko = ys0_(var_index('k'));
go = ex_(1,1);
rbig0=1/bet;
rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam));
rq0=alpha*A*ko^(alpha-1);
rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1);
wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1);
wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1);
sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del);
sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del);
figure
subplot(2,3,1)
plot([ko*ones(100,1) y_(var_index('k'),1:100)' ])
title('k')
subplot(2,3,2)
plot([co*ones(100,1) y_(var_index('c'),2:101)' ])
title('c')
subplot(2,3,3)
plot([rbig0*ones(100,1) rbig' ])
title('R')
subplot(2,3,4)
plot([wq0*ones(100,1) wq' ])
title('w/q')
subplot(2,3,5)
plot([sq0*ones(100,1) sq' ])
title('s/q')
subplot(2,3,6)
plot([rq0*ones(100,1) rq' ])
title('r/q')
print -depsc fig1132.ps

View File

@ -1,80 +0,0 @@
// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent
var c k;
varexo taui tauc tauk g;
parameters bet gam del alpha A;
bet=.95;
gam=2;
del=.2;
alpha=.33;
A=1;
model;
k=A*k(-1)^alpha+(1-del)*k(-1)-c-g;
c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+
((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1));
end;
initval;
k=1.5;
c=0.6;
g = 0.2;
tauc = 0;
taui = 0;
tauk = 0;
end;
steady;
endval;
k=1.5;
c=0.6;
g =0.2;
tauc =0;
taui =0.20;
tauk =0;
end;
steady;
shocks;
var taui;
periods 1:9;
values 0;
end;
simul(periods=100);
co=ys0_(var_index('c'));
ko = ys0_(var_index('k'));
go = ex_(1,1);
rbig0=1/bet;
rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam));
rq0=alpha*A*ko^(alpha-1);
rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1);
wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1);
wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1);
sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del);
sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del);
figure
subplot(2,3,1)
plot([ko*ones(100,1) y_(var_index('k'),1:100)' ])
title('k')
subplot(2,3,2)
plot([co*ones(100,1) y_(var_index('c'),2:101)' ])
title('c')
subplot(2,3,3)
plot([rbig0*ones(100,1) rbig' ])
title('R')
subplot(2,3,4)
plot([wq0*ones(100,1) wq' ])
title('w/q')
subplot(2,3,5)
plot([sq0*ones(100,1) sq' ])
title('s/q')
subplot(2,3,6)
plot([rq0*ones(100,1) rq' ])
title('r/q')
print -depsc fig1151.ps

View File

@ -1,80 +0,0 @@
// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent
var c k;
varexo taui tauc tauk g;
parameters bet gam del alpha A;
bet=.95;
gam=2;
del=.2;
alpha=.33;
A=1;
model;
k=A*k(-1)^alpha+(1-del)*k(-1)-c-g;
c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+
((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1));
end;
initval;
k=1.5;
c=0.6;
g = 0.2;
tauc = 0;
taui = 0;
tauk = 0;
end;
steady;
endval;
k=1.5;
c=0.6;
g =0.2;
tauc =0;
taui =0;
tauk = 0.2;
end;
steady;
shocks;
var tauk;
periods 1:9;
values 0;
end;
simul(periods=100);
co=ys0_(var_index('c'));
ko = ys0_(var_index('k'));
go = ex_(1,1);
rbig0=1/bet;
rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam));
rq0=alpha*A*ko^(alpha-1);
rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1);
wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1);
wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1);
sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del);
sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del);
figure
subplot(2,3,1)
plot([ko*ones(100,1) y_(var_index('k'),1:100)' ])
title('k')
subplot(2,3,2)
plot([co*ones(100,1) y_(var_index('c'),2:101)' ])
title('c')
subplot(2,3,3)
plot([rbig0*ones(100,1) rbig' ])
title('R')
subplot(2,3,4)
plot([wq0*ones(100,1) wq' ])
title('w/q')
subplot(2,3,5)
plot([sq0*ones(100,1) sq' ])
title('s/q')
subplot(2,3,6)
plot([rq0*ones(100,1) rq' ])
title('r/q')
print -depsc fig1152.ps

View File

@ -1,80 +0,0 @@
// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent
var c k;
varexo taui tauc tauk g;
parameters bet gam del alpha A;
bet=.95;
gam=2;
del=.2;
alpha=.33;
A=1;
model;
k=A*k(-1)^alpha+(1-del)*k(-1)-c-g;
c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+
((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1));
end;
initval;
k=1.5;
c=0.6;
g = 0.2;
tauc = 0;
taui = 0;
tauk = 0;
end;
steady;
endval;
k=1.5;
c=0.6;
g = 0.2;
tauc =0;
taui =0;
tauk =0;
end;
steady;
shocks;
var g;
periods 10;
values 0.4;
end;
simul(periods=100);
co=ys0_(var_index('c'));
ko = ys0_(var_index('k'));
go = ex_(1,1);
rbig0=1/bet;
rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam));
rq0=alpha*A*ko^(alpha-1);
rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1);
wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1);
wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1);
sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del);
sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del);
figure
subplot(2,3,1)
plot([ko*ones(100,1) y_(var_index('k'),1:100)' ])
title('k')
subplot(2,3,2)
plot([co*ones(100,1) y_(var_index('c'),2:101)' ])
title('c')
subplot(2,3,3)
plot([rbig0*ones(100,1) rbig' ])
title('R')
subplot(2,3,4)
plot([wq0*ones(100,1) wq' ])
title('w/q')
subplot(2,3,5)
plot([sq0*ones(100,1) sq' ])
title('s/q')
subplot(2,3,6)
plot([rq0*ones(100,1) rq' ])
title('r/q')
print -depsc fig1171.ps

View File

@ -1,80 +0,0 @@
// This program replicates figure 11.3.1 from chapter 11 of RMT2 by Ljungqvist and Sargent
var c k;
varexo taui tauc tauk g;
parameters bet gam del alpha A;
bet=.95;
gam=2;
del=.2;
alpha=.33;
A=1;
model;
k=A*k(-1)^alpha+(1-del)*k(-1)-c-g;
c^(-gam)= bet*(c(+1)^(-gam))*((1+tauc(-1))/(1+tauc))*((1-taui)*(1-del)/(1-taui(-1))+
((1-tauk)/(1-taui(-1)))*alpha*A*k(-1)^(alpha-1));
end;
initval;
k=1.5;
c=0.6;
g = 0.2;
tauc = 0;
taui = 0;
tauk = 0;
end;
steady;
endval;
k=1.5;
c=0.6;
g =0.2;
tauc =0;
taui =0;
tauk =0;
end;
steady;
shocks;
var taui;
periods 10;
values 0.2;
end;
simul(periods=100);
co=ys0_(var_index('c'));
ko = ys0_(var_index('k'));
go = ex_(1,1);
rbig0=1/bet;
rbig=y_(var_index('c'),2:101).^(-gam)./(bet*y_(var_index('c'),3:102).^(-gam));
rq0=alpha*A*ko^(alpha-1);
rq=alpha*A*y_(var_index('k'),1:100).^(alpha-1);
wq0=A*ko^alpha-ko*alpha*A*ko^(alpha-1);
wq=A*y_(var_index('k'),1:100).^alpha-y_(var_index('k'),1:100).*alpha*A.*y_(var_index('k'),1:100).^(alpha-1);
sq0=(1-ex_(1,4))*A*alpha*ko^(alpha-1)+(1-del);
sq=(1-ex_(1:100,4)')*A*alpha.*y_(var_index('k'),1:100).^(alpha-1)+(1-del);
figure
subplot(2,3,1)
plot([ko*ones(100,1) y_(var_index('k'),1:100)' ])
title('k')
subplot(2,3,2)
plot([co*ones(100,1) y_(var_index('c'),2:101)' ])
title('c')
subplot(2,3,3)
plot([rbig0*ones(100,1) rbig' ])
title('R')
subplot(2,3,4)
plot([wq0*ones(100,1) wq' ])
title('w/q')
subplot(2,3,5)
plot([sq0*ones(100,1) sq' ])
title('s/q')
subplot(2,3,6)
plot([rq0*ones(100,1) rq' ])
title('r/q')
print -depsc fig1172.ps

View File

@ -1,41 +0,0 @@
periods 1000;
var c k lab z;
varexo e;
parameters bet the del alp tau rho s;
bet = 0.987;
the = 0.357;
del = 0.012;
alp = 0.4;
tau = 2;
rho = 0.95;
s = 0.007;
model;
(c^the*(1-lab)^(1-the))^(1-tau)/c=bet*((c(+1)^the*(1-lab(+1))^(1-the))^(1-tau)/c(+1))*(1+alp*exp(z(+1))*k^(alp-1)*lab(+1)^(1-alp)-del);
c=the/(1-the)*(1-alp)*exp(z)*k(-1)^alp*lab^(-alp)*(1-lab);
k=exp(z)*k(-1)^alp*lab^(1-alp)-c+(1-del)*k(-1);
z=rho*z(-1)+s*e;
end;
initval;
k = 1;
c = 1;
lab = 0.3;
z = 0;
e = 0;
end;
shocks;
var e;
stderr 1;
end;
steady;
stoch_simul(dr_algo=0,periods=1000,irf=40);
datasaver('simudata',[]);

View File

@ -1,44 +0,0 @@
var c k lab z;
varexo e;
parameters bet del alp rho the tau s;
bet = 0.987;
the = 0.357;
del = 0.012;
alp = 0.4;
tau = 2;
rho = 0.95;
s = 0.007;
model;
(c^the*(1-lab)^(1-the))^(1-tau)/c=bet*((c(+1)^the*(1-lab(+1))^(1-the))^(1-tau)/c(+1))*(1+alp*exp(z(+1))*k^(alp-1)*lab(+1)^(1-alp)-del);
c=the/(1-the)*(1-alp)*exp(z)*k(-1)^alp*lab^(-alp)*(1-lab);
k=exp(z)*k(-1)^alp*lab^(1-alp)-c+(1-del)*k(-1);
z=rho*z(-1)+s*e;
end;
initval;
k = 1;
c = 1;
lab = 0.3;
z = 0;
e = 0;
end;
shocks;
var e;
stderr 1;
end;
estimated_params;
stderr e, inv_gamma_pdf, 0.95,30;
rho, beta_pdf,0.93,0.02;
the, normal_pdf,0.3,0.05;
tau, normal_pdf,2.1,0.3;
end;
varobs c;
estimation(datafile=simudata,mh_replic=1000,mh_jscale=0.9,nodiagnostic);

View File

@ -1,62 +0,0 @@
// Estimates the Hansen Sargent and Tallarini model by maximum likelihood.
var s c h k i d dhat dbar mus muc muh gamma R;
varexo e_dhat e_dbar;
parameters lambda deltah deltak mud b bet phi1 phi2 cdbar alpha1 alpha2 cdhat;
bet=0.9971;
deltah=0.682;
lambda=2.443;
alpha1=0.813;
alpha2=0.189;
phi1=0.998;
phi2=0.704;
mud=13.710;
cdhat=0.155;
cdbar=0.108;
b=32;
deltak=0.975;
model(linear);
R=deltak+gamma;
R*bet=1;
s=(1+lambda)*c-lambda*h(-1);
h=deltah*h(-1)+(1-deltah)*c;
k=deltak*k(-1)+i;
c+i=gamma*k(-1)+d;
mus=b-s;
muc=(1+lambda)*mus+(1-deltah)*muh;
muh=bet*(deltah*muh(+1)-lambda*mus(+1));
muc=bet*R*muc(+1);
d=mud+dbar+dhat;
dbar=(phi1+phi2)*dbar(-1) - phi1*phi2*dbar(-2) + cdbar*e_dbar;
dhat=(alpha1+alpha2)*dhat(-1) - alpha1*alpha2*dhat(-2) + cdhat*e_dhat;
end;
shocks;
var e_dhat;
stderr 1;
var e_dbar;
stderr 1;
end;
stoch_simul(irf=0, periods=500);
// save dataHST c i;
estimated_params;
bet,uniform_pdf, .9499999999, 0.0288675134306;
deltah,uniform_pdf, 0.45, 0.202072594216;
lambda,uniform_pdf, 25.05, 14.4048892163;
alpha1,uniform_pdf, 0.8, 0.115470053809;
alpha2,uniform_pdf, 0.25, 0.144337567297;
phi1,uniform_pdf, 0.8, 0.115470053809;
phi2,uniform_pdf, 0.5, 0.288675134595;
mud,uniform_pdf, 24.5, 14.1450815951;
cdhat,uniform_pdf, 0.175, 0.0721687836487;
cdbar,uniform_pdf, 0.175, 0.0721687836487;
end;
varobs c i;
// estimation(datafile=dataHST,first_obs=1,nobs=500,mode_compute=4,MH_jscale=2);
estimation(datafile=dataHST,first_obs=1,nobs=500,mode_compute=4,mode_check,mh_replic=5000,mh_nblocks=1,mh_jscale=0.3);

View File

@ -1,62 +0,0 @@
// Estimates the Hansen Sargent and Tallarini model by maximum likelihood.
var s c h k i d dhat dbar mus muc muh gamma R;
varexo e_dhat e_dbar;
parameters lambda deltah deltak mud b bet phi1 phi2 cdbar alpha1 alpha2 cdhat;
bet=0.9971;
deltah=0.682;
lambda=2.443;
alpha1=0.813;
alpha2=0.189;
phi1=0.998;
phi2=0.704;
mud=13.710;
cdhat=0.155;
cdbar=0.108;
b=32;
deltak=0.975;
model(linear);
R=deltak+gamma;
R*bet=1;
s=(1+lambda)*c-lambda*h(-1);
h=deltah*h(-1)+(1-deltah)*c;
k=deltak*k(-1)+i;
c+i=gamma*k(-1)+d;
mus=b-s;
muc=(1+lambda)*mus+(1-deltah)*muh;
muh=bet*(deltah*muh(+1)-lambda*mus(+1));
muc=bet*R*muc(+1);
d=mud+dbar+dhat;
dbar=(phi1+phi2)*dbar(-1) - phi1*phi2*dbar(-2) + cdbar*e_dbar;
dhat=(alpha1+alpha2)*dhat(-1) - alpha1*alpha2*dhat(-2) + cdhat*e_dhat;
end;
shocks;
var e_dhat;
stderr 1;
var e_dbar;
stderr 1;
end;
// stoch_simul(irf=0, periods=500);
// save dataHST c i;
estimated_params;
bet, .91, .9, .99999;
deltah, 0.4, 0.1, 0.8;
lambda, 2, 0.1, 50;
alpha1, 0.8, 0.6, 0.99999;
alpha2, 0.2, 0.01, 0.5;
phi1, 0.8, 0.6, 0.99999;
phi2, 0.5, 0.3, 0.9;
mud, 10, 1, 50;
cdhat, 0.1, 0.05, 0.2;
cdbar, 0.1, 0.05, 0.2;
end;
varobs c i;
estimation(datafile=dataHST,first_obs=1,nobs=500,mode_compute=4,mode_check);

View File

@ -1,45 +0,0 @@
periods 200;
var c1 c2 k1 k2 a1 a2 y1 y2;
varexo e1 e2;
parameters gamma delta alpha beta rho;
gamma=2;
delta=.05;
alpha=.4;
beta=.98;
rho=.85;
model;
c1=c2;
exp(c1)^(-gamma) = beta*exp(c1(+1))^(-gamma)*(alpha*exp(a1(+1))*exp(k1)^(alpha-1)+1-delta);
exp(c2)^(-gamma) = beta*exp(c2(+1))^(-gamma)*(alpha*exp(a2(+1))*exp(k2)^(alpha-1)+1-delta);
exp(c1)+exp(c2)+exp(k1)-exp(k1(-1))*(1-delta)+exp(k2)-exp(k2(-1))*(1-delta) = exp(a1)*exp(k1(-1))^alpha+exp(a2)*exp(k2(-1))^alpha;
a1=rho*a1(-1)+e1;
a2=rho*a2(-1)+e2;
exp(y1)=exp(a1)*exp(k1(-1))^alpha;
exp(y2)=exp(a2)*exp(k2(-1))^alpha;
end;
initval;
y1=1.1;
y2=1.1;
k1=2.8;
k2=2.8;
c1=.8;
c2=.8;
a1=0;
a2=0;
e1=0;
e2=0;
end;
shocks;
var e1; stderr .08;
var e2; stderr .08;
end;
steady;
stoch_simul(dr_algo=0,periods=200);
datatomfile('simu2',[]);

View File

@ -1,51 +0,0 @@
periods 200;
var c1 c2 k1 k2 a1 a2 y1 y2;
varexo e1 e2;
parameters gamma delta alpha beta rho;
gamma=2;
delta=.05;
alpha=.4;
beta=.98;
rho=.85;
model;
c1=c2;
exp(c1)^(-gamma) = beta*exp(c1(+1))^(-gamma)*(alpha*exp(a1(+1))*exp(k1)^(alpha-1)+1-delta);
exp(c2)^(-gamma) = beta*exp(c2(+1))^(-gamma)*(alpha*exp(a2(+1))*exp(k2)^(alpha-1)+1-delta);
exp(c1)+exp(c2)+exp(k1)-exp(k1(-1))*(1-delta)+exp(k2)-exp(k2(-1))*(1-delta) = exp(a1)*exp(k1(-1))^alpha+exp(a2)*exp(k2(-1))^alpha;
a1=rho*a1(-1)+e1;
a2=rho*a2(-1)+e2;
exp(y1)=exp(a1)*exp(k1(-1))^alpha;
exp(y2)=exp(a2)*exp(k2(-1))^alpha;
end;
initval;
y1=1.1;
y2=1.1;
k1=2.8;
k2=2.8;
c1=.8;
c2=.8;
a1=0;
a2=0;
e1=0;
e2=0;
end;
shocks;
var e1; stderr .08;
var e2; stderr .08;
end;
steady;
estimated_params;
alpha, normal_pdf, .35, .05;
rho, normal_pdf, .8, .05;
stderr e1, inv_gamma_pdf, .09, 10;
stderr e2, inv_gamma_pdf, .09, 10;
end;
varobs y1 y2;
estimation(datafile=simu2,mh_replic=1200,mh_jscale=.7,nodiagnostic);

Binary file not shown.

Binary file not shown.

View File

@ -1,58 +0,0 @@
function datasaver (s,var_list)
% datasaver saves variables simulated by Dynare
% INPUT
% s: a string containing the name of the destination *.m file
% var_list: a character matrix containting the name of the variables
% to be saved (optional, default: all endogenous variables)
% OUTPUT
% none
% This is part of the examples included in F. Barillas, R. Colacito,
% S. Kitao, C. Matthes, T. Sargent and Y. Shin (2007) "Practicing
% Dynare".
% Modified by M. Juillard to make it also compatible with Dynare
% version 4 (12/4/07)
global lgy_ lgx_ y_ endo_nbr M_ oo_
% test and adapt for Dynare version 4
if isempty(lgy_)
lgy_ = M_.endo_names;
lgx_ + M_.exo_names;
y_ = oo_.endo_simul;
endo_nbr = M_.endo_nbr;
end
sm=[s,'.m'];
fid=fopen(sm,'w') ;
n = size(var_list,1);
if n == 0
n = endo_nbr;
ivar = [1:n]';
var_list = lgy_;
else
ivar=zeros(n,1);
for i=1:n
i_tmp = strmatch(var_list(i,:),lgy_,'exact');
if isempty(i_tmp)
error (['One of the specified variables does not exist']) ;
else
ivar(i) = i_tmp;
end
end
end
for i = 1:n
fprintf(fid,[lgy_(ivar(i),:), '=['],'\n') ;
fprintf(fid,'\n') ;
fprintf(fid,'%15.8g\n',y_(ivar(i),:)') ;
fprintf(fid,'\n') ;
fprintf(fid,'];\n') ;
fprintf(fid,'\n') ;
end
fclose(fid) ;
return ;

View File

@ -1,46 +0,0 @@
periods 5000;
var c k mu_c b d in;
varexo e_d e_b;
parameters R rho rho_b mu_b mu_d;
R=1.05;
//rho=0.9;
rho = 0;
mu_b=30;
mu_d=5;
rho_b = 0;
model(linear);
c+k = R*k(-1) + d;
mu_c = b - c;
mu_c=mu_c(+1);
d= rho*d(-1)+ mu_d*(1-rho) + e_d;
b=(1-rho_b)*mu_b+rho_b*b(-1)+e_b;
in = k - k(-1);
end;
//With a unit root, there exists no steady state. Use the following trick.
//Supply ONE solution corresponding to the initial k that you named.
initval;
d=mu_d;
k=100;
c = (R-1)*k +d;
mu_c=mu_b-c;
b=mu_b;
end;
shocks;
var e_d;
stderr 1;
var e_b;
stderr 1;
end;
steady;
check;
stoch_simul(dr_algo=1, order=1, periods=500, irf=10);
save data_hall.mat c in;

View File

@ -1,54 +0,0 @@
// Estimates the hall model using Bayesian method.
// hall1_estimate.mod estimates by maximum likelihood
periods 5000;
var c k mu_c b d in;
varexo e_d e_b;
parameters R rho rho_b mu_b mu_d;
R=1.05;
rho=0.9;
mu_b=30;
mu_d=5;
rho_b = 0.5;
model(linear);
c+k = R*k(-1) + d;
mu_c = b - c;
mu_c=mu_c(+1);
d= rho*d(-1)+ mu_d*(1-rho) + e_d;
b=(1-rho_b)*mu_b+rho_b*b(-1)+e_b;
in = k - k(-1);
end;
// Michel says that in a stationary linear model, this junk is irrelevant.
// But with a unit root, there exists no steady state. Use the following trick.
// Supply ONE solution corresponding to the initial k that you named. (Michel is a gneius!! Or so he thinks -- let's see
// if this works.)
initval;
d=mu_d;
k=100;
c = (R-1)*k +d;
mu_c=mu_b-c;
b=mu_b;
end;
shocks;
var e_d;
stderr 0.05;
var e_b;
stderr 0.05;
end;
estimated_params;
rho, beta_pdf, .1, 0.2;
R, normal_pdf, 1.02, 0.05;
end;
varobs c in;
// declare the unit root variables for diffuse filter
unit_root_vars k;
//estimation(datafile=data_hall,first_obs=101,nobs=200,mh_replic=1000,mh_nblocks=2,mh_jscale=2,mode_compute=0,mode_file=hall1_estimate2_mode);
estimation(datafile=data_hall,first_obs=101,nobs=200,mh_replic=1000,mh_nblocks=2,mh_jscale=2);

View File

@ -1,56 +0,0 @@
// Estimates the hall model using maximum likelihood. See hall1_estimateBayes.mod for Bayesian method
periods 5000;
var c k mu_c b d in;
varexo e_d e_b;
parameters R rho rho_b mu_b mu_d;
R=1.05;
rho=0.9;
mu_b=30;
mu_d=5;
rho_b = 0.5;
model(linear);
c+k = R*k(-1) + d;
mu_c = b - c;
mu_c=mu_c(+1);
d= rho*d(-1)+ mu_d*(1-rho) + e_d;
b=(1-rho_b)*mu_b+rho_b*b(-1)+e_b;
in = k - k(-1);
end;
// Michel says that in a stationary linear model, this junk is irrelevant.
// But with a unit root, there exists no steady state. Use the following trick.
// Supply ONE solution corresponding to the initial k that you named. (Michel is a gneius!! Or so he thinks -- let's see
// if this works.)
initval;
d=mu_d;
k=100;
c = (R-1)*k +d;
mu_c=mu_b-c;
b=mu_b;
end;
shocks;
var e_d;
stderr 0.05;
var e_b;
stderr 0.05;
end;
estimated_params;
// ML estimation setup
// parameter name, initial value, boundaries_low, ..._up;
// now we use the optimum results from csminwel for starting up Marco's
rho, -0.0159, -0.9, 0.9;
R, 1.0074, 0, 1.5;
end;
varobs c in;
// declare the unit root variables for diffuse filter
unit_root_vars k;
estimation(datafile=data_hall,first_obs=101,nobs=200,mh_replic=0,mode_compute=4,mode_check);
// Note: there is a problem when you try to use method 5. Tom, Jan 13, 2006

View File

@ -1,55 +0,0 @@
// Rosen schooling model
//
// The model is the one Sherwin Rosen showed Sargent in Sargent's Chicago office.
// The equations are
//
// s_t = a0 + a1*P_t + e_st ; flow supply of new engineers
//
// N_t = (1-delta)*N_{t-1} + s_{t-k} ; time to school engineers
//
// N_t = d0 - d1*W_t +e_dt ; demand for engineers
//
// P_t = (1-delta)*bet P_(t+1) + beta^k*W_(t+k); present value of wages of an engineer
periods 500;
var s N P W;
varexo e_s e_d;
parameters a0 a1 delta d0 d1 bet k;
a0=10;
a1=1;
d0=1000;
d1=1;
bet=.99;
delta=.02;
model(linear);
s=a0+a1*P+e_s; // flow supply of new entrants
N=(1-delta)*N(-1) + s(-4); // evolution of the stock
N=d0-d1*W+e_d; // stock demand equation
P=bet*(1-delta)*P(+1) + bet^4*(1-delta)^4*W(+4); // present value of wages
end;
initval;
s=0;
N=0;
P=0;
W=0;
end;
shocks;
var e_d;
stderr 1;
var e_s;
stderr 1;
end;
steady;
check;
stoch_simul(dr_algo=1, order=1, periods=500, irf=10);
//datasaver('simudata',[]);
save data_rosen.mat s N P W;

View File

@ -1,63 +0,0 @@
// Estimates the Rosen schooling model by maximum likelihood
// Rosen schooling model
//
// The model is the one Sherwin Rosen showed Sargent in Sargent's Chicago office.
// The equations are
//
// s_t = a0 + a1*P_t + e_st ; flow supply of new engineers
//
// N_t = (1-delta)*N_{t-1} + s_{t-k} ; time to school engineers
//
// N_t = d0 - d1*W_t +e_dt ; demand for engineers
//
// P_t = (1-delta)*bet P_(t+1) + W_(t+k); present value of wages of an engineer
periods 500;
var s N P W;
varexo e_s e_d;
parameters a0 a1 delta d0 d1 bet ;
a0=10;
a1=1;
d0=1000;
d1=1;
bet=.99;
delta=.02;
model(linear);
s=a0+a1*P+e_s; // flow supply of new entrants
N=(1-delta)*N(-1) + s(-4); // evolution of the stock
N=d0-d1*W+e_d; // stock demand equation
P=bet*(1-delta)*P(+1) + bet^4*(1-delta)^4*W(+4); // present value of wages
end;
initval;
s=0;
N=0;
P=0;
W=0;
end;
shocks;
var e_d;
stderr 1;
var e_s;
stderr 1;
end;
steady;
estimated_params;
a1, gamma_pdf, .5, .5;
d1, gamma_pdf, 2, .5;
end;
varobs W N;
estimation(datafile=data_rosen,first_obs=101,nobs=200,mh_replic=5000,mh_nblocks=2,mh_jscale=2,mode_compute=0,mode_file=rosen_estimateML_mode);

View File

@ -1,65 +0,0 @@
// Estimates the Rosen schooling model by maximum likelihood
// Rosen schooling model
//
// The model is the one Sherwin Rosen showed Sargent in Sargent's Chicago office.
// The equations are
//
// s_t = a0 + a1*P_t + e_st ; flow supply of new engineers
//
// N_t = (1-delta)*N_{t-1} + s_{t-k} ; time to school engineers
//
// N_t = d0 - d1*W_t +e_dt ; demand for engineers
//
// P_t = (1-delta)*bet P_(t+1) + W_(t+k); present value of wages of an engineer
periods 500;
var s N P W;
varexo e_s e_d;
parameters a0 a1 delta d0 d1 bet ;
a0=10;
a1=1;
d0=1000;
d1=1;
bet=.99;
delta=.02;
model(linear);
s=a0+a1*P+e_s; // flow supply of new entrants
N=(1-delta)*N(-1) + s(-4); // evolution of the stock
N=d0-d1*W+e_d; // stock demand equation
P=bet*(1-delta)*P(+1) + bet^4*(1-delta)^4*W(+4); // present value of wages
end;
initval;
s=0;
N=0;
P=0;
W=0;
end;
shocks;
var e_d;
stderr 1;
var e_s;
stderr 1;
end;
steady;
estimated_params;
a1, .5, -10, 10;
d1, .5, -20, 40; // these are the ranges for the parameters
end;
varobs W N;
estimation(datafile=data_rosen,first_obs=101,nobs=200,mh_replic=0,mode_compute=4,mode_check);

View File

@ -1,41 +0,0 @@
// this program solves and simulates the model in
// "The Demand for Money during Hyperinflations under Rational Expectations: I" by T. Sargent, IER 1977
// this program mainly serves as the data generating process for the estimation of the model in sargent77ML.mod and sargent77Bayes.mod
// variables are defined as follows:
// x=p_t-p_{t-1}, p being the log of the price level
// mu=m_t-m_{t-1}, m being the log of money supply
// note that in contrast to the paper eta and epsilon have variance 1 (they are multiplied by the standard deviations)
var x mu a1 a2;
varexo epsilon eta;
parameters alpha lambda sig_eta sig_epsilon;
lambda=.5921;
alpha=-2.344;
sig_eta= .001;
sig_epsilon= .001;
// the model equations are taken from equation (27) on page 69 of the paper
model;
x=x(-1)-lambda*a1(-1)+(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta;
mu=(1-lambda)*x(-1)+lambda*mu(-1)-lambda*a2(-1)+(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta;
a1=(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta;
a2=(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta;
end;
steady;
shocks;
var eta;
stderr 1;
var epsilon;
stderr 1;
end;
stoch_simul(dr_algo=1,drop=0, order=1, periods=33, irf=0);
save data_hyperinfl.mat x mu;

View File

@ -1,48 +0,0 @@
// this program estimates the model in
// "The Demand for Money during Hyperinflations under Rational Expectations: I" by T. Sargent, IER 1977 using Bayesian techniques
// variables are defined as follows:
// x=p_t-p_{t-1}, p being the log of the price level
// mu=m_t-m_{t-1}, m being the log of money supply
// note that in contrast to the paper eta and epsilon have variance 1 (they are multiplied by the standard deviations)
var x mu a1 a2;
varexo epsilon eta;
parameters alpha lambda sig_eta sig_epsilon;
lambda=.5921;
alpha=-2.344;
sig_eta=.001;
sig_epsilon=.001;
model;
x=x(-1)-lambda*a1(-1)+(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta;
mu=(1-lambda)*x(-1)+lambda*mu(-1)-lambda*a2(-1)+(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta;
a1=(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta;
a2=(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta;
end;
steady;
shocks;
var eta;
stderr 1;
var epsilon;
stderr 1;
end;
estimated_params;
// Bayesian setup
lambda, uniform_pdf, 0.68, .5;
alpha, uniform_pdf, -5, 2;
sig_eta, uniform_pdf, .5, 0.25;
sig_epsilon, uniform_pdf, .5, 0.25;
end;
varobs mu x;
unit_root_vars x;
estimation(datafile=cagan_data,first_obs=1,nobs=34,mh_replic=25000,mh_nblocks=1,mh_jscale=1,mode_compute=4);

View File

@ -1,52 +0,0 @@
// this program estimates the model in
// "The Demand for Money during Hyperinflations under Rational Expectations: I" by T. Sargent, IER 1977 using maximum likelihood
// variables are defined as follows:
// x=p_t-p_{t-1}, p being the log of the price level
// mu=m_t-m_{t-1}, m being the log of money supply
// note that in contrast to the paper eta and epsilon have variance 1 (they are multiplied by the standard deviations)
var x mu a1 a2;
varexo epsilon eta;
parameters alpha lambda sig_eta sig_epsilon;
lambda=.5921;
alpha=-2.344;
sig_eta=.001;
sig_epsilon=.001;
model;
x=x(-1)-lambda*a1(-1)+(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta;
mu=(1-lambda)*x(-1)+lambda*mu(-1)-lambda*a2(-1)+(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta;
a1=(1/(lambda+alpha*(1-lambda)))*sig_epsilon*epsilon-(1/(lambda+alpha*(1-lambda)))*sig_eta*eta;
a2=(1+alpha*(1-lambda))/(lambda+alpha*(1-lambda))*sig_epsilon*epsilon-(1-lambda)/(lambda+alpha*(1-lambda))*sig_eta*eta;
end;
steady;
shocks;
var eta;
stderr 1;
var epsilon;
stderr 1;
end;
estimated_params;
// ML estimation setup
// parameter name, initial value, boundaries_low, ..._up;
lambda, .5, 0.25, 0.75;
alpha, -2, -8, -0.1;
sig_eta, .0001, 0.0001, 0.3;
sig_epsilon, .0001, 0.0001, 0.3;
end;
varobs mu x;
unit_root_vars x;
estimation(datafile=cagan_data,first_obs=1,nobs=34,mh_replic=0,mode_compute=4,mode_check);

View File

@ -0,0 +1,43 @@
%mod-file triggering the sim1_linear.m solver;
%The exogenous arma processes test whether the Jacobian at the
%deterministic steady state is correctly computed
var x
y
z;
varexo u
v;
parameters a1 a2 a3 a4
b1 b2 b3
c1;
a1 = .50;
a2 = .00;
a3 = .70;
a4 = .40;
b1 = .90;
b2 = .00;
b3 = .80;
c1 = .95;
model(linear);
y = a1*x(-1) + a2*x(+1) + a3*z + a4*y(-1);
z = b1*z(-1) + b2*z(+1) + b3*x + u;
x = c1*x(-1) + v +v(-1)+v(+1);
end;
initval;
y=-1;
x=-1;
z=-1;
end;
endval;
y=0;
x=0;
z=0;
end;
steady;
simul(periods=1000,stack_solve_algo=0);