On Tue, 13 Nov 2012, Mariusz Doszyń wrote: > Dear Gretl Useres! > I've 30 variables and want to generate vector (n) with number of valid > observations for each variable. I'm using 'ok' function but something is > wrong (see script below). Probably '$i' is not taken as an i-th variable > but as a series containg only "i". What do you think about it? How to be > sure that '$i' is taken as an i-th variable? > > <hansl> > n=zeros(30,1) > loop i=1..30 > a=sum(ok($i)) > n[i,1]=a > endloop > print n
For a start, you may want to use the version nobs(), but that's very marginal. In order to do what you want, you have to supply the name of the series to the function, not its number: you may do so in (at least) two ways. Method 1: <hansl> open AWM.gdt list L = CAN .. EER n = zeros(nelem(L),1) j = 1 loop foreach i L --quiet n[j] = nobs($i) j++ end loop print n </hansl> Method 2: <hansl> open AWM.gdt n = zeros(20,1) loop i=1..20 --quiet s = varname(i) n[j] = nobs(@s) end loop print n </hansl> -------------------------------------------------- Riccardo (Jack) Lucchetti Dipartimento di Economia Università Politecnica delle Marche (formerly known as Università di Ancona) r.lucchetti(a)univpm.it http://www2.econ.univpm.it/servizi/hpp/lucchetti --------------------------------------------------