Function to get the powerset
by Henrique Andrade

Dear Gretl Community,
I really stuck trying to define a function that gives a power set of a
set. Suppose I have a set S:
S = {"A", "B", "C"}
The associated power set, P(S), is:
P(S) = {{ }, {"A"}, {"B"}, {"C"}, {"A", "B"}, {"A", "C"}, {"B", "C"},
{"A", "B", "C"}}
All that I can think by now (shame on me!) is this:
strings S = defarray("A", "B", "C")
scalar P_S_len = 2^nelem(S) # the size of the power set
strings P_S = array(P_S_len) # an array with 8 spaces.
Does anyone have any ideas?
Best,
Henrique Andrade
1 year, 9 months

Lead operartor/variables
by José Belbute

I need to use the Stock and Watson (1993) procedure to which I need leads
(and lags) of the first difference of all my variables
How can I compute the lead variables using gretl?
Thanks
José
2 years, 3 months

Re: [Gretl-users] AR-GARCH-t MLE
by mandar phatak

Sir,
I faced a strange problem in while performing GARCH (1, 1) in Gretl for daily log returns for historical data on bitcoin it said convergence could not be met, but when i used GARCH variants everything is working well. So its a humble request kindly provide me where i am doing a mistake. Secondly i was trying use the multivariate GARCH in Gretl as now there is a package available using BEKK. As i felt since i have the historical data on log daily returns for euro( against dollar ) it will great to see the multivariate Garch. but there also it said error in line 7.
So a humble request to kindly guide me in resolving these problems.
Thanking you
With Regards,
Mandar Priya Phatak
2 years, 3 months

2018a release
by Allin Cottrell

The 2018a release is now on sourceforge.
Allin
2 years, 4 months

R-functions update
by Allin Cottrell

The facility for defining and calling R functions in gretl has now
been extended to support strings on input and output. (Previously this
worked only for scalars and matrices). This is in git, and will be in
the 2018a release. Trivial example follows:
<hansl>
set R_functions on
foreign language=R
strfun <- function(s) {
s <- paste(s, "blossom")
}
end foreign
string s = R.strfun("cherry")
print s
</hansl>
Allin
2 years, 4 months

Problems with R function in foreign block
by Artur T.

Dear all,
I want to call an R function for drawing stacked histograms using
gretl's foreign block. As only numeric values (scalar, matrix) can be
passed to R, I first write a temporary txt-file containing the string
for the path+file-name for the plot into $dotdir. Then I call the R
function and read-in the txt-file.
Using R, this function works fine. But it doesn't work properly when
calling from inside gretl. I obtain the error:
<error>
External command failed
*** error in function Rhist, line 8
</error>
and in the CLI error
<CLI>
gretl_R_function_exec: R_catch failed on HIST_R
</CLI>
Here is the script:
<hansl>
set verbose off
set R_functions on
function void Rhist (matrix X, string fname)
# MAIN FUNCTION
string sdir = sprintf("%s/tmpRhist.txt", $dotdir)
outfile @sdir --write --quiet # write the path+file name into a
txt-file
printf "%s\n", fname
outfile --close
ret = R.HIST_R(X) # Should "R.HIST_R(X)" also just work?
end function
foreign language=R
HIST_R <- function(X) {
library(Cairo)
library(cairoDevice)
# FIXME
# for (i in 1:dim(X)[2]){
# #v <- as.numeric()
# H$i <- numeric( hist(X[,i]) ) #,breaks=seq(mn,mx,bin))
# }
H1 <- hist(X[,1])
H2 <- hist(X[,2])
H3 <- hist(X[,3])
# read-in "path+file name" string
fname <- paste(readLines("/home/at/.gretl/tmpRhist.txt"), collapse=" ")
CairoPNG(filename = fname, width = 600, height = 600, pointsize = 26,
bg = NA, res = NA)
par(family="Times", las=1)
plot(H1, col=rgb(0,0,0,1/2), xlab="", main="")
plot(H2, add=T, col=rgb(0.5,0.5,0.5,1/2), xlab=NULL, ylab=NULL
,main=NULL)
plot(H3, add=T, col=rgb(1,1,1,1/2), xlab=NULL, ylab=NULL ,main=NULL)
dev.off()
ret<-1
return(ret)
}
end foreign
#---------
# EXAMPLE
#---------
matrix M = mnormal(200,3)
string fname = sprintf("%s/Rhistcheck.png", $dotdir)
Rhist(M, fname)
</hansl>
Best,
Artur
2 years, 4 months

Re: [Gretl-users] Quadratic form in log-likelihood (CONT'D)
by Alecos Papadopoulos

Thanks for this. I waited until I run various cases before providing
feedback. Both approaches work fine in general... but not in a specific
model I work with now. And I cannot understand why, because even in the
simple bivariate normal example, the qqq construct includes parameters
under estimation in any case. So I would really appreciate any idea why
the following does not work (it gives immediately a numerical derivative
value of exactly zero for the rho correlation parameter irrespective of
starting value, which is suspicious, and stays there for ever, and after
some iterations it aborts with a message "matrix is not
positive-definite") . I am not saying that it necessarily has to do with
the code, it may be the model's problem. But the thing is, if I write
out explicitly the likelihood (since this is the bivariate case),
without using the qqq construct, the code does provide results, this is
why I am at a loss here.
<hansl>
[data...]
[starting values for the parameters...]
matrix R2 = {1,rho; rho,1}
mle logl = check ? -0.5*ldet(R2) -0.5*qqq + 0.5*((invcdf(N,CDF))^2) +
log(B1+B2) :NA
series resCor = Depv - Regrs*kVec
series B1 = (resCor/vu)+ ...
series B2 = (resCor/vu) +...
series CDF = cnorm(resCor/vu) + mix*B1 - (1-mix)*B2
matrix q = {W, invcdf(N,CDF)}
matrix qq = q*inv(R2)
series qqq = sumr(q.*qq)
scalar check = (vu>0) && (mix>0) && (mix < 1) && (abs(rho)<1)
params kVec vu mix rho
end mle
</hansl>
Alecos Papadopoulos
PhD Candidate
Athens University of Economics and Business, Greece
School of Economic Sciences
Department of Economics
https://alecospapadopoulos.wordpress.com/
On 16/2/2018 09:22, gretl-users-request(a)lists.wfu.edu wrote:
> A minimal modification of your script that fixes this is
>
> <hansl>
> nulldata 128
> series N1 = normal()
> series N2 = normal()
>
> scalar s1 = 1
> scalar s2 = 1
> scalar c12 = 0.5
> matrix q = {N1, N2}
>
> mle logl = check ? -0.5 * (qqq + ldet(S)) : NA
> matrix S = {s1^2,c12;c12,s2^2}
> scalar check = (s1>0) && (s2>0) && (abs(c12)<1)
> matrix qq = q * inv(S)
> series qqq = sumr(q.*qq)
> params s1 s2 c12
> end mle
>
> # check
> Shat = q'q ./ $nobs
> print Shat
> eval sqrt(diag(Shat))
> </hansl>
Having said this, though, there's a more general point, on the check for
positive definiteness of S. If you reparametrise the problem, you can make
S pd by construction simply optimising over the elements of the Cholesky
factor of S rather than S itself. This is a very nice trick, which saves
you lots of intermediate computation, works quite well in practice and is
trivial to generalise to any number of columns of q. For example:
<hansl>
nulldata 128
series N1 = normal()
series N2 = normal()
scalar s1 = 1
scalar s2 = 1
scalar c12 = 0.5
matrix q = {N1, N2}
matrix S = I(2)
matrix theta = vech(S)
mle logl = -0.5 * (qqq + ldet(S))
matrix K = lower(unvech(theta))
matrix S = K*K'
matrix qq = q * invpd(S)
series qqq = sumr(q.*qq)
params theta
end mle
# check
Shat = q'q ./ $nobs
eval cholesky(Shat)
</hansl>
Hope this helps.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Universit? Politecnica delle Marche
(formerly known as Universit? di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
2 years, 4 months

Re: [Gretl-users] One-sided HP filter
by Riccardo (Jack) Lucchetti

On Thu, 8 Mar 2018, Allin Cottrell wrote:
>> Ok, so the consensus seems to be including my script in the relevant
>> chapter of the User's Guide, with adequate accompanying text, and
>> extending the existing hpfilt() function with a third optional argument
>> (I'm not a great fan of a string argument; I'd rather have a boolean flag
>> --- better for scripting).
>>
>> I can take care of the former over the weekend and of the latter later on.
>> But I suppose we don't want to wait for these for release, do we?
>
> Not necessarily, but I have a little unfinished business with svm() that
> I'd like to get into the release if possible, so if you're quick enough...
> ;-)
First installment is done: I've just committed to SourceForge a revised
version of the Kalman chapter in the User's Guide. Please note that the
script is a slightly revised version of the one I posted yesterday.
Comments welcome.
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------
2 years, 4 months

building Gretl from source issue
by Denys Braga

Dear Gretl teem,
I`ve downloaded the latest tar.gz (2017d) source archive and build Gretl
from source.
My machine runs Gentoo with KDE Plasma DE but for Gretl needs I`ve
installed gtk3 dependencies.
The build options are ./configure --enable-build-addons
--enable-quiet-build all others settings remain defaults, make && make
install
The issue is that I do not see some menu entries in Tools (Preferences)
from main GUI and some tests in model GUI.
On Windows machine everything is visible.
Any ideas or suggestions?
Regards,
Denys
2 years, 4 months

One-sided HP filter
by Riccardo (Jack) Lucchetti

Folks,
I just implemented the one-sided HP filter as per Stock & Watson (1999),
"Forecasting Inflation", JME. It was quite easy, in fact. The Hansl code
is below.
However, I'd like to ask the community a question: how should we use this:
I have three possibilities:
* Put the code below in the Kalman filter chapter of the User's Guide, as
an example of how you do simple things of some practival value;
* implement this as a function package (but then, we already have the
Christiano-Fitzgerald filter, and it may make sense to coalesce the two
filters into one package)
* implement this as a variant of our native hpfilt() function, with an
extra boolean flag for one-sidedness.
Opinions?
<hansl>
function series oshpfilt(series y, scalar lambda[0])
if lambda == 0
lambda = 100 * $pd^2
endif
# State transition matrix
matrix F = {2,-1;1,0}
# Observation matrix
matrix H = {1;0}
# Covariance matrix in the state equation
matrix Q = diagcat(1/lambda, 0)
ssm = ksetup(y, H, F, Q)
ssm.obsvar = 1
ssm.inistate = {2*y[1]-y[2] ; 3*y[1]-2*y[2]}
err = kfilter(&ssm)
series ret = err ? NA : y - ssm.state[,2]
return ret
end function
# --- example ----------------------------------------------
clear
open fedstl.bin
data houst
series y = log(houst)
series hp1 = oshpfilt(y) # one-sided
series hp2 = hpfilt(y) # two-sided (traditional)
series t1 = y - hp1
series t2 = y - hp2
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------
2 years, 4 months