Two index-summation loop

It seems the expression you want is:
y_i = c_i + \sum_{r=1}^{i-1} b_r*y_{i-r+1}

i.e. y_{i-r+1} instead of y_{i-r} . Implementing that gives the result you expect.

julia> test= DataFrame(months = 0:3, y = 0.0)
4×2 DataFrame
 Row │ months  y       
     │ Int64   Float64 
─────┼─────────────────
   1 │      0      0.0
   2 │      1      0.0
   3 │      2      0.0
   4 │      3      0.0

julia> for i in 1:nrow(test)
         test.y[i] = c_test[i]
         for r in 1:i - 1
           test.y[i] += b_test[r] * test.y[i - r + 1]
         end
       end

julia> test
4×2 DataFrame
 Row │ months  y       
     │ Int64   Float64 
─────┼─────────────────
   1 │      0      0.0
   2 │      1      1.0
   3 │      2      3.1
   4 │      3      9.5
1 Like