How to replicate 100 times an RBC model?

Hi, I am trying to replicate 100 times a basic RBC economy as follows.

for j=1:100,
stoch_simul(periods=128, hp_filter=1600,IRF=0,noprint);
end;

I have got complex numbers in filtering the simulated series and computing the mean of my summary statistics. This is due to the fact that dynare has generated negative values for investment.
I would appreciate if you could suggest another way of writing the loop to avoid these problems. Regards

See [N stochastic simulations for a number of periods T)
Negative values should not be an issue unless you take logs of these values and I don’t see why you are doing this.

Thanks for your reply, Johannes. The link you suggested is useful.
Indeed I took logs of the series Dynare simulated in order to compute myself the relative standard deviations of the filtered series. That is why I’m getting complex numbers in the averages.

Then you should set up your model in loglinear form (e.g. using an exp()-transformation or the loglinear option).

Thanks, dear