Dear Gretlers,
I would like to know how to do two specific operations which I am not able
to perform in a proper way:
1) delete variables using loop/for constructs
2) remove variables which contain only missing values and/or have less than
"N" valid observations
1) As far as the first problem is concerned, I partially solved it by
writing a file using outfile and printf but I guess it is not the most
efficient way to do it. That is, for the time being I solved it in the
following way:
loop for (i=1; i<100; i+=1)
outfile --append foo.inp
printf "delete %d\n", $i
outfile --close
endloop
run foo.inp
However, I cannot directly use something like this:
loop for (i=1; i<100; i+=1)
delete $i
endloop
because I receive the following error message: "You cannot delete series in
this context" .
2) Besides the problem at point 1), I would like to know if there is a way
to delete variables using some sort of condition upon the number of
observations they contain. That is, what I have in mind is something like
this (N is a scalar):
loop for (v=1; v<100; v+=1)
if (sum(missing($v))<N)
delete $v
endif
endloop
However, I cannot do it because if I run "missing($v)" inside a loop it
interprets "$v" as a number and not as a reference to a variable. Therefore,
I would like to know if there is any way to tell Gretl "consider that number
as a reference to a variable, not as a scalar" since this would come handy
also in many other situations. Notice also that, in my case, I cannot build
a list containing all the (string) names of all the variables since I get an
error (probably because Gretl cannot handle two thousands strings... I
guess..).
Thanks in advance for your help,
Matteo