Loop in initval block

Hello, my model is a multi-country-multi-sector model. (Origin country * origin sector * destination country * destination sector). I solved for the steady state and stored inside a mat file. I load the mat file in dynare .mod file. Then I feed in the steady state I solved in the initval block. For each variable, the initial values are the same across destination countries, but varies across the other three dimensions. So I try to introduce a loop inside the initval block with a counter. But the dynare is regarding the counter as a variable. Could you please show me how to modify?
start_Benchmark_covid.m (29.2 KB)

Enclosed is the mod file
dynare_Benchmark_covid.mod (13.8 KB)

I think the proper way for the loop would be to not use counters:

@# define countries = ["H","F","R"]
@# define sectors   = ["D","N","S"]

@# for se in sectors
@# for co in countries
    var omega_@{se}@{co}; 
@# endfor
@# endfor  


initval;
@# for se in 1:length(sectors)
    @# for co in 1:length(countries)
        omega_@{sectors[se]}@{countries[co]} = xss_omega((@{se}-1)*@{length(sectors)}+@{co});
    @# endfor
@# endfor
end;

seems to yield the expected result.

Hi Professor,

Thank you very much for your reply. I will use this method. I think it will be great that later version dynare can deal with this in an easier way. It will benefit a lot for people working on multi countries and sectors model.

Best,
Chengyuan

How would you envision it to be easier?

Hi professor,

I think it will be great if we can feed the initial value into the mod file as the shape they were in the Matlab start file. Instead of using loop to shape them into a long vector. I am working on input-output and international trade, some of the variables have four dimensions.

Best,
Chengyuan

I am not sure I understand.

@# define countries = ["H","F","R"]
@# define sectors   = ["D","N","S"]

@# for se in sectors
@# for co in countries
    var omega_@{se}@{co}; 
@# endfor
@# endfor  


initval;
@# for se in 1:length(sectors)
    @# for co in 1:length(countries)
        omega_@{sectors[se]}@{countries[co]} = xss_omega(@{se},@{co});
    @# endfor
@# endfor
end;

should work to access n-dimensional arrays.