Problem with fsolve in staedy-state file

Hi all,

I am having problem with calling fsolve command in the steady-state file using Dynare. My model is a New-Keynesian model for calculating fiscal-multiplier. First, I have written a matlab file for calibrating the model (calibration_test.m ). In that file I use fsolve command (associated file consumption_trial.m), which works fine. Then I have written a mod file (kenynesian_fiscal_mult.mod) and the associated steady state file. In the steady state file, I try to use fsolve command (associated file consumption.m which is the same as consumption_trial.m). However, I get following error message
Preprocessing completed.

Error using ^
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform
elementwise matrix powers, use ‘.^’.

Error in consumption (line 4)
cnrhat = x(2).^((eepsilon-1)/eepsilon)+ oomega*cgbar^((eepsilon-1)/eepsilon);

Error in fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});

Error in keynes_fiscal_mult_steadystate (line 70)
x= fsolve(@consumption, xx0, options, wh, kg, l_v, kfp_v, s, ig, Vp, Vw);

I do not understand why I having this problem. Any help will be great!

Thanks

Ramaniconsumption.m (986 Bytes) keynes_fiscal_mult_steadystate.m (4.0 KB) calibration_test.m (3.9 KB) consumption_trial.m (1006 Bytes)
Keynes_fiscal_mult.mod (4.9 KB)

1 Like

Your global variables do not work. You should pass explicit input arguments.

Dear Dr. Pfeifer,

Thanks for the quick reply. I tried the solution suggested by you, but ran into another problem. When I run my mod file, I get following error message:
resid: The initial values for the steady state of the following variables are complex:
y
yf
ystar
nx
f1
f2
ln_y
ln_ip

which I find strange. I do not have the same problem when I run my matlab file for calibration (calibration_test.m) along with consumption_test.m although I am using the same syntax.

Sorry to bother you again.

Ramani
Keynes_fiscal_mult.mod (4.9 KB) consumption.m (997 Bytes) keynes_fiscal_mult_steadystate.m (4.1 KB) calibration_test.m (4.0 KB) consumption_test.m (1010 Bytes)

In consumption.m you switched the input argument of xx(2) to x(1):

lambdars = (1/((1+tcbar)*crhat))*xx(2)^(-1/eepsilon);

It works. I had a made a silly syntax error.

Thanks

Dear Dr. Pfeifer,

Sorry to bother you again. I am trying to calculate fiscal multipliers similar to Sims and Wolff (2017), IER and Leeper et. al. (2017), AER. I am using my own steady state file. In the steady state file,
I allow for the fact that if the steady state does not exist or steady state values are unreasonable, then
it should return without updating steady states as suggested in your new Keynesian model code :
https://github.com/JohannesPfeifer/dynare/blob/1b5641575f0f3e6f22c5d62f386446bdc774b491/examples/NK_baseline_steadystate.m. When I run my code, for some of the parameter values, steady state does not exist. In that case, my model stops running and does not move to new set of parameter values and I get following message:

Preprocessing completed.

Residuals of the static equations:

Equation number 1 : 0
Equation number 2 : 0
Equation number 3 : -0.25908
Equation number 4 : -0.25908
Equation number 5 : 0
Equation number 6 : 0
Equation number 7 : -1
Equation number 8 : 0.112
Equation number 9 : 0.03
Equation number 10 : 0.09305
Equation number 11 : 0.097043
Equation number 12 : 0.97159
Equation number 13 : -0.935
Equation number 14 : -0.054606
Equation number 15 : -1
Equation number 16 : 1.15
Equation number 17 : 1.5
Equation number 18 : 0
Equation number 19 : 0.435
Equation number 20 : 0.7
Equation number 21 : 1.865
Equation number 22 : 0
Equation number 23 : -0.32
Equation number 24 : -1
Equation number 25 : -0.22206
Equation number 26 : -0.22206
Equation number 27 : 0
Equation number 28 : -1
Equation number 29 : -0.25923
Equation number 30 : -0.25923
Equation number 31 : 0
Equation number 32 : -0.935
Equation number 33 : 0.097043
Equation number 34 : 0.97159
Equation number 35 : 0
Equation number 36 : -0.001874
Equation number 37 : 0
Equation number 38 : 0
Equation number 39 : 0
Equation number 40 : 0
Equation number 41 : 0
Equation number 42 : 0
Equation number 43 : -0.65
Equation number 44 : -2.65
Equation number 45 : 0
Equation number 46 : 0
Equation number 47 : 0.325
Equation number 48 : -2.35
Equation number 49 : 0
Equation number 50 : 0
Equation number 51 : 0.65
Equation number 52 : -1.8571
Equation number 53 : 0
Equation number 54 : 0
Equation number 55 : 0
Equation number 56 : 0.00741
Equation number 57 : 1.5798
Equation number 58 : -0.10748
Equation number 59 : 0.98503
Equation number 60 : 0.84204
Equation number 61 : 2.1231
Equation number 62 : 0.99938
Equation number 63 : 1.8585
Equation number 64 : 0.90029
Equation number 65 : 0.76968
Equation number 66 : 0
Equation number 67 : 0.65
Equation number 68 : 0.65
Equation number 69 : -1.35

Error using print_info (line 76)
The steadystate file did not compute the steady state

Error in steady (line 104)
print_info(info,options_.noprint, options_);

I have attached the relevant files. Any help will be great.

Thanks
AlokKeynes_multiplier.mod (6.5 KB) multiplier_cal.m (10.5 KB) consumption_bay.m (1008 Bytes) keynes_multiplier_steadystate.m (6.3 KB)

Dear Professor,

I run multiplier_cal.m to calculate the multiplier which calls the mod and other related files.

Thanks
Ramani

You are not running a loop the way you are supposed to run it. By looping over all of Dynare, you cannot easily control the error codes returned, e.g. when the steady state file signals an error. You can either use a try-catch-statement or use the noprint-option and read out the info-code returned.

Thanks Dr. Pfeifer,

I have tried following command using info- code given below (file name multiplier_cal.m) following tips given on
https://forum.dynare.org/t/loop-over-parameters/3335https://forum.dynare.org/t/loop-over-parameters/3335
While the program runs, I get same values of endogenous variables regardless of parameter values.
I have attached the relevant files.

for i=1:500

first_time = 1;

if first_time
set_param_value(‘aalpha_g’, rand_alphag(i));
set_param_value(‘oomega’, rand_omega(i));
set_param_value(‘etapi’, rand_etapi(i));
set_param_value(‘etay’, rand_etay(i));
set_param_value(‘etarg’, rand_etarg(i));
set_param_value(‘iotap’, rand_iotap(i));
set_param_value(‘iotaw’, rand_iotaw(i));
set_param_value(‘cchi’, rand_chi(i));
set_param_value(‘pphi’, rand_phi(i));
set_param_value(‘rho_cg’, rand_rhocg(i));
set_param_value(‘rho_ig’, rand_rhoig(i));

dynare keynes_multiplier.mod nostrict noclearall;

   first_time = 0;
else
   set_param_value('aalpha_g', rand_alphag(i));
   set_param_value('oomega', rand_omega(i));
   set_param_value('etapi', rand_etapi(i));
   set_param_value('etay', rand_etay(i));
   set_param_value('etarg', rand_etarg(i));
   set_param_value('iotap', rand_iotap(i));
   set_param_value('iotaw', rand_iotaw(i));
   set_param_value('cchi', rand_chi(i));
   set_param_value('pphi', rand_phi(i));
   set_param_value('rho_cg', rand_rhocg(i));
   set_param_value('rho_ig', rand_rhoig(i));
   
  info = stoch_simul(var_list_);
       
if info
        disp('Failed Stoch_Simul')        

end

end

gdp_cg_mul(i)= (gdp_eps_cg(1)exp(oo_.steady_state(1)))/(.01exp(oo_.steady_state(4)));
cp_cg_mul(i)= (cp_eps_cg(1)exp(oo_.steady_state(2)))/(.01exp(oo_.steady_state(4)));
cpr_cg_mul(i)= (cpr_eps_cg(1)exp(oo_.steady_state(6)))/(.01exp(oo_.steady_state(4)));
cpnr_cg_mul(i)= (cpnr_eps_cg(1)exp(oo_.steady_state(7)))/(.01exp(oo_.steady_state(4)));
ip_cg_mul(i)= (ip_eps_cg(1)exp(oo_.steady_state(3)))/(.01exp(oo_.steady_state(4)));
gdp_steady(i)=exp(oo_.steady_state(1));

end

Thanks for all the helpkeynes_multiplier.mod|attachment (6.4 KB) multiplier_cal.m (5.1 KB) keynes_multiplier_steadystate.m (6.0 KB)

Ramani

The mod-file was not uploaded correctly, but from what I can see, the problems are that oo_.steady_state is not the correct field. oo_.dr.ys and that gdp_eps_cg may have to be replaced by oo_.irfs.gdp_eps_cg or something like that.

Dear Dr. Pfeifer,

Thanks for reply. keynes_multiplier.mod (6.4 KB) I made the suggested changes. Problem remains the same. The model runs 500 times, but uses parameter values given in the mod file. It does not do any updating of parameters.

I have attached the relevant files. Thanks again for your patience.

Ramani

keynes_multiplier.mod (6.4 KB)
multiplier_cal.m (5.1 KB)
keynes_multiplier_steadystate.m (6.0 KB)

Use multiplier_cal.m (4.6 KB)
You for example set the first time counter within the loop.

Dear Dr. Pfeifer,

It works! Thank a lot for your help!

Ramani