Page 1 of 1

programming rolling moving averages

Posted: Tue Oct 27, 2009 1:29 am
by yoniboi
I am trying to program a rolling moving average, meaning i want to run

Code: Select all

'a is how many leaps back !a= 2 ' x is the series genr x =y matrix (!a , !a) mataic matrix (!a , !a) matschw matrix (!a , !a) mathq matrix (!a , !a) matlogl for !i =1 to !a for !j =1 to !a equation eq!i_!j eq!i_!j.ls x c x(-1 to -!i) ma(1 to !j) mataic(!i , !j) = eq!i_!j.@aic matschw(!i , !j) = eq!i_!j.@schwarz mathq(!i , !j) = eq!i_!j.@hq matlogl(!i , !j) = eq!i_!j.@logl next next
i want the output to give me 4 equations:

x c x(-1) ma(1)
x c x(-1) ma(1) ma(2)
x c x(-1) x(-2) ma(1)
x c x(-1) x(-2) ma(1) ma(2)

but what i am getting is:

x c x(-1) ma(1)
x c x(-1) ma(1)
x c x(-1) x(-2) ma(1)
x c x(-1) x(-2) ma(1)

i tried writing:

Code: Select all

eq!i_!j.ls x c x(-1 to -!i) ma(!j)
and i get:
x c x(-1) ma(1)
x c x(-1) ma(2)
x c x(-1) x(-2) ma(1)
x c x(-1) x(-2) ma(2)

is there a way to do this parsimoniously in the code?

Re: programming rolling moving averages

Posted: Tue Oct 27, 2009 7:31 am
by EViews Gareth

Re: programming rolling moving averages

Posted: Tue Oct 27, 2009 7:50 am
by yoniboi
thank you