problem with estimation_params

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

problem with estimation_params

Postby lilia » Wed Oct 05, 2016 10:23 am

Hi,

I'm running a simple RBC model with monopolistic competition and Stone-Geary preferences and try to estimate parameter b (subsistence consumption) using US data for consumption. Here is the code

%preliminary data

cons = xlsread ('consumption', 1, 'A1:A154');

nobs = 154;
cr = ones(nobs,1);
tr = (1:nobs)';
for i=1:nobs
tr2(i) = tr(i)^2;
end;

log_cons=log(cons)
const = FOLS(log_cons,[cr tr tr2']);
c = log_cons-const.beta(2)*tr-const.beta(3)*tr2'; % eliminate quadratic trend
save rawdata_US_1977Q1_2016q3 c;

var c, k, L, A, Y ;

varexo zz ;

parameters alpha, beta, delta, teta, phi, vi, b, niz, n ;

alpha = 0.333; %capital share to match labor share of 2/3 in US KR, 1999 is 0.333;
teta = 6; %elasticity of substitution for goods
phi = 2; %Frisch elasticity, in KR and BGM 4, in villaverde-ramirez 0.85
beta = 0.99; %in KR 0.984
delta = 0.025;
niz = 0.979;
b = 1.19;
vi = 8.15;
n = 2.015;

model;

k=(1-delta)*k(-1)+exp(A)*k(-1)^alpha*L^(1-alpha)-n*c;

% L=(((1-alpha)*exp(A)*k(-1)^alpha)/((c-b)*vi))^(phi/(1+alpha*phi)); %perf comp
L=(((1-alpha)*exp(A)*(k(-1)^alpha))*((teta-1)*c-b*teta)/((c-b)^2*vi))^(phi/(1+alpha*phi)); %mon comp

%(c-b)^(-1)=beta*(1+alpha*exp(A(+1))*k^(alpha-1)*L(+1)^(1-alpha)-delta)*((c(+1)-b)^(-1)); %perf comp
((teta-1)*c-b*teta)*(c-b)^(-2)=beta*(1+alpha*exp(A(+1))*k^(alpha-1)*L(+1)^(1-alpha)-delta)*(((teta-1)*c(+1)-b*teta)*(c(+1)-b)^(-2)); %mon comp

A=niz*A(-1)+zz;

Y=exp(A)*L^(1-alpha)*k^alpha;
end;

initval;

c = 2.1914529;
L = 0.0608807939;
k = 91.041666655;
A = 0;
Y = 0.0608;

end;

shocks;
var zz = 0.0072^2;
end;

estimated_params ;
b, normal_pdf, 1.19, 0.375;
end;

varobs c;

%estimated_params_init(use_calibration);
%end;

estimation(datafile=rawdata_US_1977Q1_2016q3, first_obs=1,nobs=70,mode_compute=5,mode_check,mh_replic=10000,mh_nblocks=2,mh_jscale=0.65,mh_init_scale=0.5,bayesian_irf,moments_varendo) c ;

%estimated_params_init(use_calibration);
%end;

The following error appears:
Error using schur
First input must be square.


I have tried other options for computing the mode. When I run the same code on an earlier version of dynare, it works!

many thanks for any help
lilia
 
Posts: 17
Joined: Mon Feb 15, 2016 1:48 pm

Re: problem with estimation_params

Postby jpfeifer » Wed Oct 05, 2016 1:43 pm

Please upload all required files in a zip-file
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: problem with estimation_params

Postby lilia » Wed Oct 05, 2016 2:03 pm

ok, here they are. thanks
Attachments
code.zip
(20.91 KiB) Downloaded 63 times
lilia
 
Posts: 17
Joined: Mon Feb 15, 2016 1:48 pm

Re: problem with estimation_params

Postby jpfeifer » Wed Oct 05, 2016 2:07 pm

I get
Undefined function or variable 'FOLS'.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: problem with estimation_params

Postby lilia » Wed Oct 05, 2016 2:12 pm

that is preliminary work on data, just skip with %, data are saved in dat files
lilia
 
Posts: 17
Joined: Mon Feb 15, 2016 1:48 pm

Re: problem with estimation_params

Postby jpfeifer » Wed Oct 05, 2016 4:27 pm

I can run the code. Please try the unstable version and please post the full error message, i.e. including line numbers and the caller stack.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: problem with estimation_params

Postby lilia » Thu Oct 06, 2016 8:47 am

Hi,

This is the message I get

ESTIMATION_CHECKS: There was an error in computing the likelihood for initial parameter values.
ESTIMATION_CHECKS: You should try using the calibrated version of the model as starting values. To do
ESTIMATION_CHECKS: this, add an empty estimated_params_init-block with use_calibration option immediately before the estimation
ESTIMATION_CHECKS: command (and after the estimated_params-block so that it does not get overwritten):


Error using schur
First input must be square.
Error in lyapunov_symm (line 120)
[U,T] = schur(a);
Error in dsge_likelihood (line 374)
Pstar = lyapunov_symm(T,R*Q*R',DynareOptions.qz_criterium,DynareOptions.lyapunov_complex_threshold);
Error in initial_estimation_checks (line 47)
[fval,junk1,junk2,a,b,c,d] = feval(objective_function,xparam1,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);
Error in dynare_estimation_1 (line 180)
oo_ = initial_estimation_checks(objective_function,xparam1,dataset_,M_,estim_params_,options_,bayestopt_,oo_);
Error in dynare_estimation (line 89)
dynare_estimation_1(var_list,dname);
Error in Stone_Geary_moments_test (line 186)
dynare_estimation(var_list_);
Error in dynare (line 180)
evalin('base',fname) ;

I've installed the latest unstable version in a new directory and could not add the new path to Matlab. should I disinstall the stable version first?
lilia
 
Posts: 17
Joined: Mon Feb 15, 2016 1:48 pm

Re: problem with estimation_params

Postby jpfeifer » Thu Oct 06, 2016 9:13 am

Yes, try that.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: problem with estimation_params

Postby lilia » Thu Oct 06, 2016 9:30 am

this is what I get now

Error using save
Unable to write file Stone_Geary_moments_test/metropolis\Stone_Geary_moments_test_mh_tmp_blck1.mat: Invalid argument.

Error in posterior_sampler_core (line 190)
save([BaseName '_mh_tmp_blck' int2str(curr_block) '.mat'],'x2','logpo2','LastSeeds');

Error in posterior_sampler (line 121)
fout = posterior_sampler_core(localVars, fblck, nblck, 0);

Error in dynare_estimation_1 (line 418)
posterior_sampler(objective_function,posterior_sampler_options.proposal_distribution,xparam1,posterior_sampler_options,bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);

Error in dynare_estimation (line 105)
dynare_estimation_1(var_list,dname);

Error in Stone_Geary_moments_test (line 202)
oo_recursive_=dynare_estimation(var_list_);

Error in dynare (line 223)
evalin('base',fname) ;

it got stacked in the MH algorithm
lilia
 
Posts: 17
Joined: Mon Feb 15, 2016 1:48 pm

Re: problem with estimation_params

Postby jpfeifer » Thu Oct 06, 2016 9:48 am

That is strange. Could you please try try a new folder with a short filename.
If that does not work, go to
Code: Select all
check_posterior_sampler_options

and set
Code: Select all
            posterior_sampler_options.save_tmp_file=0;

in line 51 for
Code: Select all
case 'random_walk_metropolis_hastings'
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: problem with estimation_params

Postby lilia » Thu Oct 06, 2016 10:42 am

many thanks for the precious help! I have tried both options and the second works.

It is strange that the problem had arisen with this code/model. I had tried a similar code for a linear model, using both the stable and the unstable version, and everything was ok. may it depend on the non-linearity of the model?
lilia
 
Posts: 17
Joined: Mon Feb 15, 2016 1:48 pm

Re: problem with estimation_params

Postby jpfeifer » Fri Oct 07, 2016 3:53 pm

No, it is not related to linear vs. nonlinear. Something triggers unexpected side effects with Matlab.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: problem with estimation_params

Postby lilia » Fri Oct 07, 2016 4:08 pm

Thanks a lot!

something strange happens with this model, the posterior distribution has zero variance:

ESTIMATION RESULTS

Log data density is -2999.101860.

parameters
prior mean post. mean 90% HPD interval prior pstdev

b 0.800 0.8562 0.8562 0.8562 norm 0.0500
lilia
 
Posts: 17
Joined: Mon Feb 15, 2016 1:48 pm

Re: problem with estimation_params

Postby jpfeifer » Fri Oct 07, 2016 4:20 pm

Do the mode_check-plots look ok?
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: problem with estimation_params

Postby lilia » Fri Oct 07, 2016 4:40 pm

It does not, the plot is attached as pdf
Attachments
mode.zip
(20.19 KiB) Downloaded 60 times
lilia
 
Posts: 17
Joined: Mon Feb 15, 2016 1:48 pm

Next

Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 6 guests