Page 1 of 1

call matlab function within model block

PostPosted: Mon Apr 29, 2013 3:33 am
by David
Hi, I have two questions.
1. how to load steady state values into mod file?
2. how to call a matlab function within the model block?

My purpose is to have a loop over parameters to see how IRF and other endogenous variables behave. Because of changing exogenously specified deep parameters, the utility function form and thus the marginal utility form in the Euler equation will change, as well as all steady state values.

The scenario is like this: first, I have defined a matlab function "solveSS" that with solve for steady state values of all endogenous variables according to exogenously given deep parameters (all deep parameters are exogenously specified); second, I have defined a matlab function call "unmu" which return utility and marginal utility when two variables and some exogenously specified parameters are input, so
Code: Select all
function [u muc muh]=unmu(c,h,paras)
if paras==1
   u=....% equation that calculate utility level
   muc=... % calculate marginal utility of c
   muh=... % calculate marginal utility of h
else
   u=....% equation that calculate utility level
   muc=... % calculate marginal utility of c
   muh=... % calculate marginal utility of h
end


Obviously, the way to calculate marginal utility depends on the parameters input.

Could anyone provide some hints about how to do such loops?

Ideally, I would think it is feasible to code like this:
Code: Select all
//**************************************
// dynare mod file
//**************************************

//**************************************
// Declare variables and parameters
//**************************************
var ...
varexo ...
parameters ...

// provide parameter values

load parameters.mat
for npara=1:length(M_.params)
    deep_parameter_name = M_.param_names(npara,:);
    eval(['M_.params(npara)  = ' deep_parameter_name ' ;'])
end

// provide steady state values
[b]Please, how to load steady state values from my defined function 'solveSS'? [/b]
....

//**************************************
model;
//**************************************
[b]please, how to call matlab function 'unmu' I defined that return marginal utility to me such that I can use it in my Euler equation?[/b]
// Function 'unmu' will give me [u muc muh]=unmu(c,h,parameters), where [u muc muh] are utility level, marginal utility of c and h, respectively,
//but I only need muc and muh
// so could I write like this:

[u muc muh]=unmu(c,h,parameters);
muc=beta*mucXXXXXXXXXXXXXXXXXXXXXXXXXXXX // No, wrong! Do not know how to do it, I need c(+1) and unmu(c(+1),h(+1), parameters) but this cannot be handle in unmu function

end;


Could someone provide samples that have similar scenarios?

Re: call matlab function within model block

PostPosted: Mon Apr 29, 2013 12:27 pm
by kyri82
I am sure you can call a matlab function outside the model block (I do it myself) however I am not sure if this is feasible within it. Btw, why does your MU change so dramatically with parametres? I mean, I would understand if you changed the functional form.

Kyriacos

Re: call matlab function within model block

PostPosted: Sun May 05, 2013 8:51 am
by David
kyri82 wrote:I am sure you can call a matlab function outside the model block (I do it myself) however I am not sure if this is feasible within it. Btw, why does your MU change so dramatically with parametres? I mean, I would understand if you changed the functional form.

Kyriacos


Yes the utility function form changes, e.g., from CES to Cobb-Douglas, and from power utility to log utility, according to parameters input.

Re: call matlab function within model block

PostPosted: Sun May 05, 2013 9:09 am
by jpfeifer
From my understanding, you want to determine at the beginning which parameter and thus utility function to use, but having only one mod-file instead of 2. Your best shot seems to be the Dynare macro language that would paste the required utility function depending on your specification. Using an external file seems not sensible to me as you lose Dynare's ability to take (higher order) derivatives for you.

Re: call matlab function within model block

PostPosted: Sun May 05, 2013 9:24 am
by David
jpfeifer wrote:From my understanding, you want to determine at the beginning which parameter and thus utility function to use, but having only one mod-file instead of 2. Your best shot seems to be the Dynare macro language that would paste the required utility function depending on your specification. Using an external file seems not sensible to me as you lose Dynare's ability to take (higher order) derivatives for you.


Thank you very much.
Instead of trying a loop over the mod file, I may turn to specify separate mod file according to the utility function and thus the Euler equation now because I have not mastered Dynare macro language yet. Learn it later.