On Tue, 6 Jan 2015, Daniel Bencik wrote:
Dear forum,
I am struggling with my variable lists once again. I expected the following
two ML estimations to give the same results, but they don't. Any ideas?
#estimation 1
scalar c_ = 0.1
scalar rng = 0.1
scalar err = 0.2
mle ll = -ln(lambda) - sqrtPark/lambda
series lambda = mean(sqrtPark)
series lambda = c_ + rng * sqrtPark(-1) + err * lambda(-1)
params c_ rng err
end mle --robust
#estimation 2
list xDepVars = sqrtPark
list xExpVars = sqrtPark(-1)
c_ = 0.1
rng = 0.1
err = 0.2
series xDepVar = xDepVars[1]
series xExpVar = xExpVars[1]
mle ll2 = -ln(lambda2) - xDepVar/lambda2
series lambda2 = mean(xDepVar)
series lambda2 = c_ + rng * xExpVar + err * lambda2(-1)
params c_ rng err
end mle --robust
Many thanks in advance,
Thank you for posting. The facility of "indexing into" a list is
fairly new, and although it is now mentioned in the documentation it
is not adequately explained.
Let's start from basics. In the gretl main window you can see that
each series (whose name appears in the second column from the left)
is associated with an index number (in the leftmost column). Now,
internally, a gretl "list" is just an array of integers, each
integer being the index number of a series. So when you "index into"
a list, what you get back is an integer index number.
Suppose we have lists Y and X, each containing at least one series.
Then if we do, for example,
ols Y[1] 0 X[1]
this will work OK. The expressions "Y[1]" and "X[1]" will each yield
a series index number, and such index numbers are valid input for
the "ols" command. However, now suppose we try
series x1 = X[1]
You might think this would give us a series, x1, whose values are
those of the first member of the list named "X", but that's not so.
Let's say the first member of list X is the series with index number
3; in that case the statement above is equivalent to
series x1 = 3
That is, x1 will be a series with constant value 3.0. This explains
the results you got via mle.
So how can you get what you want, namely the actual values of the
series at position i in a list? For that you need a "foreach" loop
across the list, using "$i" to get the name of the series in
question, as in
loop foreach i List
series x = $i
print x
endloop
Allin Cottrell