call matlab function within model block

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.

call matlab function within model block

Postby David » Mon Apr 29, 2013 3:33 am

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?
David
 
Posts: 24
Joined: Fri Sep 28, 2012 3:46 pm

Re: call matlab function within model block

Postby kyri82 » Mon Apr 29, 2013 12:27 pm

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
kyri82
 
Posts: 141
Joined: Thu Feb 10, 2011 6:14 pm
Location: Toulouse - France

Re: call matlab function within model block

Postby David » Sun May 05, 2013 8:51 am

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.
David
 
Posts: 24
Joined: Fri Sep 28, 2012 3:46 pm

Re: call matlab function within model block

Postby jpfeifer » Sun May 05, 2013 9:09 am

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.
------------
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: call matlab function within model block

Postby David » Sun May 05, 2013 9:24 am

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.
David
 
Posts: 24
Joined: Fri Sep 28, 2012 3:46 pm


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 8 guests