On Thu, 2 Sep 2010, Allin Cottrell wrote:
On Thu, 2 Sep 2010, Henrique Andrade wrote:
> How can I accumulate a series in 12 months inside a script? Now this is what
> I'm doing:
>
> series var112m = var1 + var1(-1) + var1(-2) + var1(-3) + var1(-4) + var1(-5)
> + var1(-6) + var1(-7) + var1(-8) + var1(-9) + var1(-10) + var1(-11)
>
> Could you please suggest a more elegant way?
# cumulate var1
series var1cum = cum(var1)
# take the annual difference
series var112m = var1cum - var1cum(-12)
# and fill in the dropped observation
var112m[12] = var1cum[12]
Or, alternatively,
<script>
nulldata 72
setobs 12 1:1
x = normal()
# alternative 1
y1 = filter(x, ones(12,1))
# alternative 2
list X = x(0 to -11)
y2 = lincomb(X, ones(12,1))
</script>
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti