[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Using multiple equations with Optimize()

From   "Andrew Lynch" <>
To   <>
Subject   st: Using multiple equations with Optimize()
Date   Mon, 12 Nov 2007 08:11:25 -0600

Stata Users,

I have run into a bit of a dilemma with programing a Kalman filter with the optimize() procedure. I have the full documentation and have not been able to clarify where exactly the optimize() command looks when it optimizes. I am minimizing the process below. My goal is to minimize the Log Likelihood function, but while I have observed data yt and xt, a and at are unobserved and my goal is to generate them. To do so, I need Stata to rerun the do loop every time it updates one of the four parameters (b1, b2, q and h). I say all that to ask the question, "Does optimize() only look to the v= equation to optimize with the parameters or does it look to the entire evaluation and move through it in some ordered fashion (thereby honoring the do loop)?" I have been unable to get this to run, and I am unsure whether it is my dumb coding error at some point or just that optimize() won't do what I want it to do.

Any enlightenment would be greatly appreciated!


Andrew Lynch
PhD Student
Department of Finance
Trulaske School of Busineses
University of Missouri - Columbia

/* Optimization Procedure */

void maxlik(todo, b, xt, yt, v, g, h)

do {
a[i]=b1*at[i] + b2*xt[i]
p[i]=(b1)^2*pt[i] + q
f[i]=ft[i] + h
at[i+1]=a[i] + ft[i+1]*p[i]*(yt[i]-y[i])
pt[i+1]=p[i] - ft[i+1]*p[i]*p[i]
L[i]=(.5)/f[i] + (.5)*(yt[i]-y[i])*(yt[i]-y[i])/f[i]

} while(i<(n+1))


S = optimize_init()
optimize_init_evaluator(S, &maxlik())
optimize_init_evaluatortype(S, "d0")
optimize_init_params(S, (0,0,0,0))
optimize_init_which(S, "min")
optimize_init_argument(S, 1, xt)
optimize_init_argument(S, 2, yt)
* For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index