Page 1 of 1
Usual functions within macro-expression or processor
Posted:
Mon Aug 29, 2016 4:38 pm
by abman10
Hello,
I am trying to use DSGE models to create artificial data in order to build a hybrid model DSGE-VAR. Indeed, i need to construct observations with a size Ta = k*Tr. Tr represents a real observations size and k a weight that is given the prior information in our analysis. Nevertheless, when computing my programs, i encounter the following problem. If k is not an integer such as (1;2;3;...), my program can not run because Ta should be also an integer. So, my question is:
Can we use usual functions like "sqrt" or "floor" within macro-expression, to resolve my problem?
For example:
@# define k=1/2
@# define m=39
@# define n=floor(k*m)
To see my exact problem, you find attached the following files: Go to line 388 in model file.
Your help really appreciated.
Thanks a lot.
Re: Usual functions within macro-expression or processor
Posted:
Tue Aug 30, 2016 8:21 am
by jpfeifer
Sorry, but the preprocessor is for text operations. The expressions you create will not be parsed.
You can get around some of the restriction by directly using the expression for n:
- Code: Select all
test1=normrnd(0,0.0001,floor(@{poids}*@{j})),1);
But this only works for code parts interpreted by Matlab, which knows the floor()-command. It will fail with
- Code: Select all
periods 1:@{n};
Have you considered doing the first loop via Dynare and then manually iterating over perfect_foresight_setup and perfect_foresight_solver via a Matlab-script?
Re: Usual functions within macro-expression or processor
Posted:
Thu Sep 01, 2016 7:00 pm
by abman10
No, i did not consider this way of dealing. And, i don't know how i can carry out this way in my case.
Any other help is appreciated.
Re: Usual functions within macro-expression or processor
Posted:
Sat Sep 03, 2016 9:51 am
by jpfeifer
If I understand it correctly, you are using the macro-processor to loop over
- Code: Select all
simul
where you change the number of periods. What you can do is run the mod-file once for the first step of the loop. Dynare will provide you with the code for this in the m-file. Then you can just take that piece of code and adjust it. If you provide me with a clean mod-file for the first step (i.e. without the macroprocessor stuff) and tell me what you are trying to do, I might be able to help you.
Re: Usual functions within macro-expression or processor
Posted:
Sun Sep 04, 2016 12:24 am
by abman10
Before preparing a clean mod-file to be send, i have a question about arithmetic operators( namely division) on macro-variables.
Can this following code be compiled?
@# define a=1
@# define b=2
@# define p= a/b
Because i remark that in my programs p gets 0 instead of 1/2.
Thanks a lot for your help!!
Re: Usual functions within macro-expression or processor
Posted:
Sun Sep 04, 2016 3:02 pm
by jpfeifer
This seems to be buggy. Please do not rely on the output of arithmetic in define statements. We are investigating the issue. See
https://github.com/DynareTeam/dynare/issues/1278
Re: Usual functions within macro-expression or processor
Posted:
Sun Sep 04, 2016 3:41 pm
by abman10
OK!!
Re: Usual functions within macro-expression or processor
Posted:
Tue Sep 06, 2016 10:34 pm
by jpfeifer
As you might have seen, downward truncation is actually a design feature of the preprocessor.