Good afternoon.
I need to find the argmax (the mode) of a conditional density, for many
different values of the conditioning variable. For a single value of the
conditioning series variable "res", the following block appears to work
(pre-accompanied by the generation of the various inputs needed)
<hansl>
scalar ressc = res[1]
function scalar udensity (const scalar sv, const scalar thu, matrix
param, scalar ressc)
scalar densu = -0.5*param[1,1]^2/sv^2 - ressc*param[1,1]/sv^2
-param[1,1]/thu + log(1-exp(-param[1,1]/thu)) #this is the conditional
density of the "param"
return densu
end function
matrix modeu[1,1] = 0.1 #intiial value for the unknown value
(argmax) we are seeking
densval = BFGScmax(&modeu, bounds, udensity(sv, thu, modeu, ressc))
</hansl>
The function above uses the value that the conditioning variable "res"
has at observation #1, and then BFGScmax finds the argmax given this
value of "res". If I then set scalar ressc = res[2], I can get what I
need given the value that the conditioning variable takes in observation
2, etc.
I was unsuccessful to transform the above script into a repetitive one,
starting with the fact that I cannot define a function inside a loop, as
Gretl informs me. I tried various other ways to essentially loop over a
command like BFGScmax that requires as input a function that must change
at each instance of the loop, but all failed.
Is there a way to do this?
--
Alecos Papadopoulos PhD
Athens University of Economics and Business
web:
alecospapadopoulos.wordpress.com/