Re: Loop over parameters
Posted: Fri Jan 17, 2014 1:11 pm
Suppose that we want to estimate the parameters using GMM. In particular, we would like to match the theoretical moments implied by the linearized model to the sample moments based on the data. Also assume that we have a separate toolbox for GMM estimation in which we just need to code the moment conditions in a separate m file. In this case, we need to pass the information obtained from first run of the Dynare to parse the code to the moment function in GMM and the objective function. Can we do this as follows:
1. In a Matlab script file define the parameters and all other necessary stuff along with
global var_list_ oo_ M_ ex0_ options_ estimation_info info
save parameters gamma1 alpha1 delta1 rho1 beta1 sigma1
dynare stochgrowth_dyna noclearall
2. In the mod file define
parameters gamma alpha delta rho beta sigma;
load parameters;
set_param_value('gamma',gamma1) % utility parameter
set_param_value('alpha',alpha1) % production elasticity
set_param_value('delta',delta1) % depreciation rate
set_param_value('rho',rho1) % production shock autocorrelation
set_param_value('beta',beta1 ) % discount factor
set_param_value('sigma',sigma1) % production shock volatility
at the beginning, the rest of the mode file is standard.
3. In the GMM moment function matlab m file:
function mom = GMMmoments(theta,X,avg)
global var_list_ oo_ M_ ex0_ options_ estimation_info info
gamma1 = theta(1);
alpha1 = theta(2);
delta1 = theta(3);
rho1 = theta(4);
beta1 = theta(5);
sigma1 = theta(6);
yobs = X(:,1);
cobs = X(:,2);
kobs = X(:,3);
iobs = X(:,4);
set_param_value('gamma',gamma1)
set_param_value('alpha',alpha1)
set_param_value('delta',delta1)
set_param_value('rho',rho1)
set_param_value('beta',beta1 )
set_param_value('sigma',sigma1)
info = stoch_simul(var_list_);
if info
disp('Stochastic Simulation failed');
end
xmean = oo_.mean;
xvar = diag(oo_.var);
Basically, what I did here is to define Dynare solution variables as GLOBAL variables in the main file and the moment file. I am not a big fan of using global variables but I could not use local variables. Is this procedure OK? Is there any other ways?
(By the way I did not post the full codes but they seem to work OK)
1. In a Matlab script file define the parameters and all other necessary stuff along with
global var_list_ oo_ M_ ex0_ options_ estimation_info info
save parameters gamma1 alpha1 delta1 rho1 beta1 sigma1
dynare stochgrowth_dyna noclearall
2. In the mod file define
parameters gamma alpha delta rho beta sigma;
load parameters;
set_param_value('gamma',gamma1) % utility parameter
set_param_value('alpha',alpha1) % production elasticity
set_param_value('delta',delta1) % depreciation rate
set_param_value('rho',rho1) % production shock autocorrelation
set_param_value('beta',beta1 ) % discount factor
set_param_value('sigma',sigma1) % production shock volatility
at the beginning, the rest of the mode file is standard.
3. In the GMM moment function matlab m file:
function mom = GMMmoments(theta,X,avg)
global var_list_ oo_ M_ ex0_ options_ estimation_info info
gamma1 = theta(1);
alpha1 = theta(2);
delta1 = theta(3);
rho1 = theta(4);
beta1 = theta(5);
sigma1 = theta(6);
yobs = X(:,1);
cobs = X(:,2);
kobs = X(:,3);
iobs = X(:,4);
set_param_value('gamma',gamma1)
set_param_value('alpha',alpha1)
set_param_value('delta',delta1)
set_param_value('rho',rho1)
set_param_value('beta',beta1 )
set_param_value('sigma',sigma1)
info = stoch_simul(var_list_);
if info
disp('Stochastic Simulation failed');
end
xmean = oo_.mean;
xvar = diag(oo_.var);
Basically, what I did here is to define Dynare solution variables as GLOBAL variables in the main file and the moment file. I am not a big fan of using global variables but I could not use local variables. Is this procedure OK? Is there any other ways?
(By the way I did not post the full codes but they seem to work OK)