A couple of months ago I sent a question regarding a MLE with an endogenously determined moving average over the list. In response, Allin provided a generic script for a loop, which was exactly what I needed for my estimation. (See mail below.)

Now, I would like to add a second independent variable, which, like the first independent variable, should be split into a short-run (SR) and a long-run (LR) coefficient:

Y = a + b1*X1_LR + e_(X1_LR) + b2*X1_SR + e_(X1_SR) + b3*X2_LR + e_(X2_LR) + b4*X2_SR + e_(X2_SR)

where all of the error terms are i.i.d. disturbances. X1_LR and X2_LR are centered moving averages of the two independent variables, and X1_SR  and X2_SR are the deviations of the actual series from their moving averages.

As in the baseline model, the length of the moving average should be set such that the likelihood function is maximized. The loop script below runs the estimation for 'pmax' times, i.e. the maximum allowed length of the moving average.

Since I am using the same value of 'pmax' for both independent variables, I need a loop that runs 'pmax' to the square estimations. Put differently, I want to determine, for which combination of p for X1 and X2 the likelihood function is maximized.

Conceptually, this should be a relatively simple addition to the script. However, I do not know how to add the necessary commands. Any help is appreciated.


Date: Thu, 21 Jul 2011 10:46:54 -0400 (EDT)
From: Allin Cottrell <cottrell@wfu.edu>
Subject: Re: [Gretl-users] MLE with endogenouly determined moving
       average
To: Gretl list <gretl-users@lists.wfu.edu>
Message-ID: <alpine.LNX.2.00.1107211039570.12081@waverley.Belkin>
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed

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


------------------------------

_______________________________________________
Gretl-users mailing list
Gretl-users@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users

End of Gretl-users Digest, Vol 54, Issue 28
*******************************************

--
Johann