Usual functions within macro-expression or processor

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.

Usual functions within macro-expression or processor

Postby abman10 » Mon Aug 29, 2016 4:38 pm

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.
Attachments
MSSF_VAR_forecast_2_steps_steadystate.m
Steady state file
(3.64 KiB) Downloaded 60 times
MSSF_VAR_forecast_2_steps.mod
main model
(18.19 KiB) Downloaded 54 times
abman10
 
Posts: 14
Joined: Thu Jan 15, 2015 3:22 am

Re: Usual functions within macro-expression or processor

Postby jpfeifer » Tue Aug 30, 2016 8:21 am

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?
------------
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: Usual functions within macro-expression or processor

Postby abman10 » Thu Sep 01, 2016 7:00 pm

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.
abman10
 
Posts: 14
Joined: Thu Jan 15, 2015 3:22 am

Re: Usual functions within macro-expression or processor

Postby jpfeifer » Sat Sep 03, 2016 9:51 am

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.
------------
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: Usual functions within macro-expression or processor

Postby abman10 » Sun Sep 04, 2016 12:24 am

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!!
abman10
 
Posts: 14
Joined: Thu Jan 15, 2015 3:22 am

Re: Usual functions within macro-expression or processor

Postby jpfeifer » Sun Sep 04, 2016 3:02 pm

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
------------
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: Usual functions within macro-expression or processor

Postby abman10 » Sun Sep 04, 2016 3:41 pm

OK!!
abman10
 
Posts: 14
Joined: Thu Jan 15, 2015 3:22 am

Re: Usual functions within macro-expression or processor

Postby jpfeifer » Tue Sep 06, 2016 10:34 pm

As you might have seen, downward truncation is actually a design feature of the preprocessor.
------------
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


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 6 guests