Related to my earlier request, the following works (perhaps
clumsily), so maybe it will be useful to somebody else also. The
full illustrative script is
<hansl>
nulldata 50
series res = randgen(N,0,1) #the conditioning variable
scalar sv = 0.3 #remains fixed
scalar thu = 0.5 #remains fixed
matrix param = ones(1,1) #initialize the object in the function
"udensity"
function scalar udensity (const scalar sv, const scalar thu,
matrix param, series res)
scalar k = $t2
densu = -0.5*param[1,1]^2/sv^2 - res[k]*param[1,1]/sv^2
-param[1,1]/thu + log(1-exp(-param[1,1]/thu)) # this is the
conditional density of "param"
return densu
end function
series modeuvals = 0 # declare the series to hold the results
from the consecutive BFGScmax in the loop
matrix bounds = {1,0,$huge} #argmax cannot be lower than zero
matrix modeu = ones(1,1) #initialize the object we are seeking to
compute. "modeu" will take the place of "param" in the "udensity"
function
loop i=1..$nobs --quiet
smpl 1 i
matrix modeu[1,1] = 0.1 #intiial value for the unknown value
(argmax) we are seeking
densval = BFGScmax(&modeu, bounds, udensity(sv, thu,
modeu, res))
series modeuvals[i] = modeu[1,1]
smpl full
endloop
</hansl>
Alecos Papadopoulos PhD Athens University of Economics and Business web: alecospapadopoulos.wordpress.com/
Subject: | Re: functions and loops |
---|---|
Date: | Sun, 6 Oct 2019 21:50:37 +0300 |
From: | Alecos Papadopoulos <papadopalex@aueb.gr> |
To: | gretl-users@gretlml.univpm.it |
-- Alecos Papadopoulos PhD Athens University of Economics and Business web: alecospapadopoulos.wordpress.com/