Macro-processor conditionals with loops

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.

Macro-processor conditionals with loops

Postby wiczerd » Sat Dec 31, 2011 9:46 pm

I'm trying to simulate a multi-sector model with search frictions and running into problems with the macro preprocessor when I try to create an integer value for a conditional test using loop indices. Code like this:


Code: Select all
@#for l in 0:JJ
   @#for j in 1:JJ
      @#if (@{l} == @{j} || @{l}==0)
         Equation
      @#else
         Equation
      @#endif   
   @#endfor
@#endfor


Gives me the error
ERROR in macro-processor: occbc.mod:66.9: Macro lexer error: '@'


Should this operation be kosher, or does it make sense that I'd have trouble?
In the attached code, the problem first occurs on line 66, though I use a similar test elsewhere and get the same error.

Thanks very much,
David
Attachments
occbc.mod
(3.09 KiB) Downloaded 158 times
wiczerd
 
Posts: 1
Joined: Sat Dec 31, 2011 9:38 pm

Re: Macro-processor conditionals with loops

Postby HoutanBastani » Mon Jan 02, 2012 11:09 am

Once

Code: Select all
@#


is encountered, the macroprocessor interprets/expands everything else on that line. So, since l and j are macro variables, you do not need to dereference them with the

Code: Select all
@{}


; you would only do this when you are NOT on a line that's already being interpreted by the macroprocessor. Thus, the correction to the above buggy line is:

Code: Select all
@#if (l==j || l==0)


For more details, see the macroprocessor.pdf file in the doc directory of your Dynare distribution.
Best,
Houtan
HoutanBastani
 
Posts: 197
Joined: Fri Jan 22, 2010 4:11 pm
Location: Paris, France


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 10 guests