On Wed, 20 Jul 2011, Johann Jaeckel wrote:

> It's my first time posting on this list. I hope the issue I am having is
> appropriate for this forum. Any help is greatly appreciated.
>
> I want to estimate a simple model with one independent variable using
> MLE with a twist.
>
> The twist is the following, the effect of the independent variable (X)
> is split into a short run (SR) and a long run (LR) coefficient. My model
> thus looks like this:
>
> Y = a + b1*X_LR + e_LR + b2*X_SR + e_SR
>
> where e_LR and e_SR are i.i.d. disturbances. X_LR is a centered moving
> average of the independent variable and X_SR is the deviation of the
> actual series from its moving average.
>
> The length of the moving average should be determined endogenously, i.e.
> in such a way that the likelihood function is maximized.
>
> Now, I am capable of running a basic MLE in Gretl by specifying the
> log-likelihood function and the derivatives. However, I am having
> troubles with creating the short run and the long run series and in
> particular with the endogenous determination of the length of the moving
> average.
>
> I have a hunch that I need to iterate the MLE command itself, but I have
> no clue how to implement this in a script.

I don't know how helpful this is, but here's illustrative use 
of a loop:

<hansl>
nulldata 200

series y = normal()
series x = normal()
# set the longest allowable MA
pmax = 30
# observations lost at start and end
lost = int(pmax / 2)
p_mle = 0
llmax = -1e300

loop p=2..pmax -q
   smpl --full
   series LR = movavg(x, p, 1)
   series SR = x - LR
   # ensure common sample size
   smpl +lost -lost
   ols y 0 LR SR --quiet
   printf "p = %02d, loglik = %f\n", p, $lnl
   if $lnl > llmax
     llmax = $lnl
     p_mle = p
   endif
endloop

printf "\nloglik maximized at %f for p = %d\n",
    llmax, p_mle
</hansl>

Allin Cottell

Reply via email to