On Thu, 1 Apr 2010, Riccardo (Jack) Lucchetti wrote: > On Thu, 1 Apr 2010, Giorgio Gozzi wrote: > > > > > Hi everone.. I am recently trying to use and learn GRETL..I need help..when > > i try� to confront the sign of the return of the time series of index > > FTSEMIB with the sign of the > > time series of the returns of every of the of every of its 40 elementary > > members. In order to count how many times there is an agreement between the > > sign of each return and > > that one of index FTSEMIB. > > > > I wanted to resolve the problem using the function SIGN� but such function > > lacks in the directory of Gretl. > > > > I will be very pleased to have some suggestion to this issue. > > How about the following? > > <script> > series agree = (ret * FTSEMIB) > 0 > </script>
That's nice. The following may be overkill, but it handles a list of series of arbitrary length (as in Giorgio's 40 components of an index). function series all_signs_same (series y, list L) series ret = 1 scalar n = $nobs loop t=1..n loop foreach i L prod = y[t] * L.$i[t] if (missing(prod)) ret[t] = NA break elif prod < 0 ret[t] = 0 break endif endloop endloop return ret end function illustrative use: open data9-7 series y = diff(QNC) list L = 2 3 4 L = diff(L) series same = all_signs_same(y, L) printf "proportion of obs all same sign = %g\n", mean(same) print y d_* same -o Allin Cottrell