Okay, so I made the test. Put the following in a mod file (file attached below):

```
@#define MaxIndex = [3]
@#define Indices = 1:MaxIndex[1]
// Expansion with only one index
@#for i in Indices
A_@{i}_@{i}
@#endfor
// Expansion with two indices
@#for i in Indices
@#for j in Indices
B_@{i}_@{j}
@#endfor
@#endfor
// Remove all the terms on the diagonal
@#for i in Indices
@#for j in Indices
@#if i != j
B_@{i}_@{j}
@#endif
@#endfor
@#endfor
// The same without the conditional statement (use a diff between two arrays instead)
@#for i in Indices
@#for j in Indices-[i]
B_@{i}_@{j}
@#endfor
@#endfor
```

This has no sense for Dynare, but the macro processor can expand the loops (and then you will obtain an error because Dynare does not understand what you want to do). You can call dynare from the terminal. First you need to know where is located the dynare binary. I will assume that

```
/Users/toto/dynare/4.5.1/matlab/preprocessor64/dynare_m
```

is the full path to the dynare binary (depending on your architecture you may have to replace `preprocessor64`

by `preprocessor32`

). Then in a terminal (assuming you are in the folder where you saved the mod file), just type:

```
~$ /Users/toto/dynare/4.5.1/matlab/preprocessor64/dynare_m example.mod savemacro
```

You will obtain an error, like this one:

```
Starting Dynare (version 4.6-unstable).
Starting preprocessing of the model file ...
ERROR: example.mod: line 35, cols 1-0: syntax error, unexpected $end
```

But you will have a new file in the same folder called `example-macroexp.mod`

. The content of this file contains the expanded version of the loops:

```
@#line "example.mod" 1
// Expansion with only one index
@#line "example.mod" 6
A_1_1
@#line "example.mod" 6
A_2_2
@#line "example.mod" 6
A_3_3
@#line "example.mod" 8
// Expansion with two indices
@#line "example.mod" 11
@#line "example.mod" 12
B_1_1
@#line "example.mod" 12
B_1_2
@#line "example.mod" 12
B_1_3
@#line "example.mod" 14
@#line "example.mod" 11
@#line "example.mod" 12
B_2_1
@#line "example.mod" 12
B_2_2
@#line "example.mod" 12
B_2_3
@#line "example.mod" 14
@#line "example.mod" 11
@#line "example.mod" 12
B_3_1
@#line "example.mod" 12
B_3_2
@#line "example.mod" 12
B_3_3
@#line "example.mod" 14
@#line "example.mod" 15
// Remove all the terms on the diagonal
@#line "example.mod" 18
@#line "example.mod" 19
@#line "example.mod" 22
@#line "example.mod" 19
@#line "example.mod" 20
B_1_2
@#line "example.mod" 22
@#line "example.mod" 19
@#line "example.mod" 20
B_1_3
@#line "example.mod" 22
@#line "example.mod" 23
@#line "example.mod" 18
@#line "example.mod" 19
@#line "example.mod" 20
B_2_1
@#line "example.mod" 22
@#line "example.mod" 19
@#line "example.mod" 22
@#line "example.mod" 19
@#line "example.mod" 20
B_2_3
@#line "example.mod" 22
@#line "example.mod" 23
@#line "example.mod" 18
@#line "example.mod" 19
@#line "example.mod" 20
B_3_1
@#line "example.mod" 22
@#line "example.mod" 19
@#line "example.mod" 20
B_3_2
@#line "example.mod" 22
@#line "example.mod" 19
@#line "example.mod" 22
@#line "example.mod" 23
@#line "example.mod" 24
// The same without the conditional statement
@#line "example.mod" 27
@#line "example.mod" 28
B_1_2
@#line "example.mod" 28
B_1_3
@#line "example.mod" 30
@#line "example.mod" 27
@#line "example.mod" 28
B_2_1
@#line "example.mod" 28
B_2_3
@#line "example.mod" 30
@#line "example.mod" 27
@#line "example.mod" 28
B_3_1
@#line "example.mod" 28
B_3_2
@#line "example.mod" 30
@#line "example.mod" 31
```

So it works like a charm (as expected) with the stable version of Dynare (I used the unstable version, but for this matter they are identical). As you can see we can build the list of variables with different index values without using a conditional statement in the inner loop (but a set difference).

I do not have time to test with 4.3.3 (I would have to grab the sources and recompile), I am on my summer vacation too

Best,

Stéphane.

example.mod (588 Bytes)