Index in position 2 is invalid. Array indices must be positive integers or logical values

Dear all,

I have a simple model with neither forward nor backward-looking variables.
I have one exogenous shock, whose value I’d like to specify and then solve for a deterministic transition path.
I use

shocks;
    var A;
    periods 1:200;
    values 1;
end;

followed by

endval;
A=1;
end;

perfect_foresight_setup(periods=200);
perfect_foresight_solver;

I keep getting the warning:
“”"
Index in position 2 is invalid. Array indices must be positive integers or logical values.
“”"
Appearantly the error occurs in:
“”"
Error in sim1_purely_backward (line 42)
yb = endogenousvariables(:,it-1); % Values at previous period, also used as guess value for current period
“”"
And I can’t figure out why.
Following advice on this forum, I am not specifying values for period 0, since I don’t have lagged variables.
Is there something similar for the case of not having forward-looking variables?

Thank you for your help =)

Additionally, I noticed that

perfect_foresight_setup(periods=4);
oo_.exo_simul
oo_.endo_simul

creates a 3x1 and a 4x4 array i.e. does not include the initial and the final period.
Is that correct?
Any help is appreciated.
Many greetings =)

Please provide the full file.

Dear Professor Pfeifer,
thank you very much for your quick reply.
I include a minimal example that replicates the error (mod file attached as well).

% declare variables and parameters
var
    Y
    ;

varexo
    A
;

parameters
    alpha 
 ;

% define the model
model;
    Y = A;
end;

% set parameter values
alpha = 0.3;

% set initial values
initval(all_values_required);
    A = 1;
    Y = 1;
end;

% look at residual and compute steady state
resid;
steady;

% now I want to set a sequence of A's
% initial value
initval;
    A=1;
end;
% define value for a specified number of periods
shocks;
    var A; 
    periods 1:4; 
    values 2.0;
end;

% define value in the end
endval;
    A=1;
end;

% compute a perfect foresight path
perfect_foresight_setup(periods=4);
perfect_foresight_solver;

Thank you very much for your help and many greetings
minimal_example.mod (645 Bytes)

I cannot replicate the error in Dynare 5.1.

Dear Professor Pfeifer,
thank you very much for your quick reply!
I have version 4.6.3.
I will upgrade and see what happens.
Thank you very much and many greetings

Dear Professor Pfeifer,
I am using Ubuntu and

sudo apt-get upgrade dynare-matlab

tells me I already have the newest version.
Is there a way to upgrade without reinstalling everything?
Many greetings

You would need to build Dynare from Source in this case. See Dynare / dynare · GitLab

Dear Professor Pfeifer,

thank you very much for your help.
Since I shied away from building from source, I found a hack that does the job :see_no_evil::
Introducing a (needless) variable that is forward-looking, e.g.

% expected value for Y in the next period 
EYnext = Y(+1);

fixes the problem =).
Therefore I conjecture the problem was indeed related to having no forward-looking variable.
Thank you very much and many greetings.

Yes, the cause is a bug in handling purely backwards models with no states.