function - pass global string variable via pointer
by Schaff, Frederik
Hi there,
from hansl-primer p. 36 it is clear there are no global variables.
Is there any way to circumvent this? For example by using default options defined outside the function body and passing them with pointers to the function body? I would like to have a function to "set" some global options for the plotting package I am working on. However, to do so, I need to define a kind of global container (a bundle, e.g.) with the default values, upon which the function can then work (a) and whose values I can also load, say as defaults in the function header, to other functions (b). Finally (c), is there an option to define pointer-type string variables and pass pointers to a string?
Best
Frederik
6 years, 11 months
passing list to function, loop
by Schaff, Frederik
Hi there,
I have a function (WIP) to produce input for a boxplot side-by-side comparison of cross-section statistics of two samples (see below). The list seems to pass the names of the series, but does not work. If I remove the function body, everything works.
<hansl>
function matrix MatOrderDist (list ls, list lsB[null])
#A function to create data for order stats boxplots (cross-section)
scalar two = 0 #no
scalar entries = nelem(ls)
if exists(lsB)
if nelem(lsB)==entries
two = 1 #yes
endif
endif
strings coln = array(6)
coln[1] = "min"
coln[2] = "lq"
coln[3] = "med"
coln[4] = "uq"
coln[5] = "max"
coln[6] = "avg"
if two
matrix to_plot = zeros(entries,12)
strings colnf = array(12)
loop i=1..12
colnf[i]=coln[i]
colnf[i+1]=coln[i]
i+=1
endloop
else
matrix to_plot = zeros(entries,6)
strings colnf = array(6)
loop i=1..6
colnf[i]=coln[i]
endloop
endif
colnames(to_plot,colnf)
scalar r = 0
scalar offset = 0
if two
offset = 1
endif
loop foreach item ls -q
r+=1
to_plot[r,1] = min($item)
to_plot[r+offset*r,2] = quantile($item,.25)
to_plot[r+offset*r,3] = quantile($item,.5)
to_plot[r+offset*r,4] = quantile($item,.75)
to_plot[r+offset*r,5] = max($item)
to_plot[r+offset*r,6] = mean($item)
endloop
if two
loop foreach item lsB -q
r+=1
to_plot[r+offset*(r-1),1] = min($item)
to_plot[r+offset*(r-1),2] = quantile($item,.25)
to_plot[r+offset*(r-1),3] = quantile($item,.5)
to_plot[r+offset*(r-1),4] = quantile($item,.75)
to_plot[r+offset*(r-1),5] = max($item)
to_plot[r+offset*(r-1),6] = mean($item)
endloop
endif
#boxplot --matrix=to_plot --output=display {set title "Cross-Section Distribution of Summary Statistics (Original Programme)"; }
return to_plot
end function
</hansl>
6 years, 11 months
dotdir / getenv alternative for scriptdir?
by Schaff, Frederik
Is there a way to yield the dir-path of a script? I'd like to include scripts via a "head"script, similar to c #include which is relative to the path.
i.e. In a script "c:/myscript.inp" I include a script "c:/scriptfolder/script.inp" and this script in turn includes other scripts on its own, relative to its path. E.g. with a line ' include "scripts/a.inp" '. Currently this is not working and I guess the reason is that gretl looks for "scripts/a.inp" relative to the scriptdir in which I included "c:/scriptfolder/script.inp"; i.e. it tries to open "c:/scripts/a.inp" and not "c:/scriptfolder/scripts/a.inp" (in this example)
Best
Frederik
6 years, 11 months
precision / format of large (integer) numbers imported in gretl
by Schaff, Frederik
Happy New Year!
I have rather large numbers (seed number, in float representation), saved with fixed precision (although that is, I guess, not the problem). Here a screenshot from the file opened with a text-editor (PSpad)
[cid:image001.png@01D3854C.3263B400]
When I import the data into gretl (from a tsv) and "show" the data, the scientific format is chosen and distorts the true values
[cid:image002.png@01D3854C.696287B0]
the same "view" is presented if I print the data to the log:
[cid:image003.png@01D3854D.01E3D200]
Because same issues do not apply for numbers with large fractions, I guess it is a problem with large integer (part) of the numbers? Is this only the visible behaviour or can it really distort the data and computations? In this case it wouldn't matter, but in other cases it might...
Best
Frederik
6 years, 11 months