Include file stored as string variable


when using Dynare 4.4.2, I usually split the model files in calibration, model equations, and others. Some of these files are not located in the same folder but in a subfolder or an other folder on the same directory level. I have already figured out that dynare can handle expressions as @#include "../model_specs/calibration.mod" to get the file located somewhere else. However, I have a MATLAB path function running in background which returns the absolute path to the specific files. Is there any possibility to load the string variable returned from the path function e.g. xy directly with something like @#inlcude xy?

Thanks in advance. Best,

Not at the moment.

The macroprocessor does text expansion within the preprocessor and thus does not have direct access to the matlab workspace.

However, I say not at the moment, because it would be possible to add this functionality. In essence, you would pass the matlab variable of your choice at the dynare command line using the -D switch. At the current time, this does not work with the @#include macro command as it’s expecting a quoted string. This could be changed, and I’ll add it to our long to do list and it might just be done in the next version of dynare. It also might not. So, in the meanwhile, you’ll have to hard code these strings.

So this has just been fixed in unstable, and will be available in tomorrrow’s snapshot package.

To summarize, you need to do something of the order of the following in Matlab:

>> xy='/path/to/dir/with/other/modfile/';
>> dynare modfile.mod -Dpath=xy

and then, in your modfile, you’ll have:

@#define othermodfile=path+'othermodfile.mod'
@#include othermodfile