should I use a loop in calculate standard deviation

Hi!

I have a problem with calculating the standard deviation in my model.
I would like to assume that standard deviation is the difference between the previously estimated demand and actual demand and I have the equation shows below.

for example, if I want to get the standard deviation of demand at period 9, I should calculate the ste.dev. at period 8.
to get the ste.dev at period 8, I need period 1~7 expected demand and actual demand to calculate it.
and I write the code in GAMS as

AA(k-1)..SS(k)=e=SQRT(sum(k,DF(k-1)-X(k-1))**2/ord(k-1);

BUT it said I already control the set. and too many ‘)’ and ')'expected.
I think I need to revise the problem of the controlled set.
I am wondering what the problem is. should I use a loop to get the value?

Thank you for reading! I appreciate any help!

Sincerely,
Sandy
image.png

Hi Sandy
See my answer to your other post regarding ord(k-1).
To sum, you should sum over an alias as the equation is defined over k.

alias(k,kk)
sum(kk, ....)

CHeers
Renger