[Gretl-users] (no subject)
Allin Cottrell
cottrell at wfu.edu
Sat Oct 31 11:39:39 EDT 2009
On Sat, 31 Oct 2009, Kehl Dániel wrote:
> I have a realy simple question. In my script I want to use two
> loops. In fact I want to make some rounding. The first loop
> takes only integer values (1 to bmax), but the other should go
> from a = -b/2 to a=b/2 with specified steps. I want to name the
> resulting serires, but the genr function can not take names
> which include "-" or ",". How can I solve this problem?
Use the "sprintf" command -- see below.
> In the future I want to store the mean and the standard
> deviation of the resulting series in a matrix. How is it
> possible?
Just set up a suitable sized matrix and write into it.
> The short script reads as:
>
> alepes = 10
> bmax = 2
> loop for b=1..bmax
> loop for (a=-b/2; a<b/2; a+=b/alepes)
> genr x_$a_$b = round((Hozam-a)/b)*b+a
> endloop
> endloop
Revised version:
<script>
nulldata 10
alepes = 10
bmax = 2
# dummy 'Hozam' series
series Hozam = normal()
# count the number of rows we need
k = 0
loop b=1..bmax
loop for (a=-b/2; a<b/2; a+=b/alepes)
k++
endloop
endloop
# initialize statistics matrix
matrix stats = zeros(k,2)
# do the actual calculations
k = 1
loop b=1..bmax
j = 1
loop for (a=-b/2; a<b/2; a+=b/alepes)
sprintf vname "x_%d_%d", j, b
genr @vname = round((Hozam-a)/b)*b+a
stats[k,1] = mean(@vname)
stats[k,2] = sd(@vname)
j++
k++
endloop
endloop
print stats
</script>
Allin Cottrell
More information about the Gretl-users
mailing list