On Thu, 7 Nov 2013, antonio.puca(a)enel.com wrote:
Hello Gretl communuty,
i'm writing for an easy question (I hope). I need to standardize a daily
time series based on a monthlly mean and standard deviation (not global
mean and standard deviation, this is the main problem). I've tried with
matrix but I'm not able to convert a matrix, which is made with an
aggregate function (based on monthly mean and stddev), in a variable in
my TS with almost 300 obs.
Two nearly equivalent methods (they only differ in the way you define
standard deviation, really):
<hansl>
nulldata 700
setobs 7 2012-01-01
series x = normal()
period = $obsminor + ($obsmajor - min($obsmajor))*12
# -------- method 1 ---------------------------------
matrix m = aggregate(x, period, mean)
matrix s = aggregate(x, period, sd)
series mm = replace(period, m[,1], m[,3])
series sm = replace(period, s[,1], s[,3])
series z1 = (x - mm)/sm
# -------- method 2 ---------------------------------
ols x const dummify(period) --quiet
series w = $uhat
series w2 = w*w
ols w2 const dummify(period) --quiet
series s2 = $yhat
series z2 = w / sqrt(s2)
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------