Estimation of AR(2) with t-student

For technical questions regarding estimation of single equations, systems, VARs, Factor analysis and State Space Models in EViews. General econometric questions and advice should go in the Econometric Discussions forum.

Moderators: EViews Gareth, EViews Moderator

Chuse
Posts: 3
Joined: Thu Nov 28, 2013 9:54 am

Estimation of AR(2) with t-student

Postby Chuse » Thu Nov 28, 2013 10:02 am

Dear all,

I am new with Eviews and i have no idea how to implement it. I would like to estimate an AR(2) with ML method and errors a t-distribution with 3 degree of freedom.
The same with errors distribution N(0,3).

Thank you beforehand.
Chuse.

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Estimation of AR(2) with t-student

Postby trubador » Thu Nov 28, 2013 2:12 pm

There is nothing built-in. You need to write a program using the LogL object and/or the Optimize command. You can work on the following code that I've just cooked up:

Code: Select all

'Maximum likelihood estimation of AR(2) model with t-distributed errors 'Create a workfile wfcreate ar2model u 250 'Generate a series that follows an AR(2) process !rho1 = 0.6 !rho2 = 0.3 !dof = 3 smpl @first @first+1 series y=0 smpl @first+2 @last y = !rho1*y(-1) + !rho2*y(-2) + @rtdist(!dof) 'Declare coefficent vectors and assign initial values coef(2) rho = .5 coef(1) dof = 2 coef(1) var = 1 !pi = @acos(-1) 'Initialize presample values smpl @first @first+1 series res = 0 'Set up logl object logl ar2t ar2t.append @logl maxlik ar2t.append res = y - rho(1)*y(-1) - rho(2)*y(-2) ar2t.append sqres = ((res^2/var(1))/dof(1))+ 1 ar2t.append maxlik = @gammalog((dof(1) + 1)/2) - @gammalog(dof(1)/2) - log(!pi)/2 - log(dof(1))/2 - log(var(1))/2 - (dof(1)+1)*log(sqres)/2 'Use the following spec. for normally distributed errors 'ar2t.append sqres = res^2/var(1) 'ar2t.append maxlik = log(@dnorm(@sqrt(sqres))) -log(var(1))/2 'Run MLE and display results smpl @first+2 @last ar2t.ml(showopts,m=1000,c=1e-5) show ar2t.output 'Get the gradients ar2t.makegrads(n=gradslogl) gradlogl1 gradlogl2 gradlogl3 gradlogl4 '************************************************************************************************************************************************************ 'We can also use Optimize instead of LogL subroutine loglikelihood(series logl, vector beta, series y) series res = y - beta(1)*y(-1) - beta(2)*y(-2) series sqres = ((res^2/beta(3))/beta(4))+ 1 logl = @gammalog((beta(4) + 1)/2) - @gammalog(beta(4)/2) - log(!pi)/2 - log(beta(4))/2 - log(beta(3))/2 - (beta(4)+1)*log(sqres)/2 endsub series logl vector(4) beta beta(1) = .5 beta(2) = .5 beta(3) = 1 beta(4) = 2 optimize(ml=1, finalh=hessmat, hess=opg) loglikelihood(logl, beta, y) vector semat = @sqrt(@getmaindiagonal(-@inverse(hessmat))) 'standart errors of estimated coefficents smpl @all
Last edited by trubador on Sat Nov 30, 2013 8:30 am, edited 1 time in total.

Chuse
Posts: 3
Joined: Thu Nov 28, 2013 9:54 am

Re: Estimation of AR(2) with t-student

Postby Chuse » Fri Nov 29, 2013 1:06 pm

Thank you very much. It work very well.
Now I would like to construct the estimation erros of the QML method using the score function. I checked that there is possible to get it as a table of the gradients.
But i dont know how to manipulate it, e.x. how can i get the Hessian matrix?. could you please help with it?

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Estimation of AR(2) with t-student

Postby trubador » Sat Nov 30, 2013 8:27 am

It is quite difficult to construct the Hessian matrix from the estimation results of LogL object. Therefore, I built the same model within the user-defined optimization framework, which also produces that output. I do not recall whether it was possible to retrieve gradients via the Optimize command, but it is with the LogL object. I've edited the code in my previous post, where "gradslogl" is the group of gradients and "hessmat" is the final hessian matrix.

Chuse
Posts: 3
Joined: Thu Nov 28, 2013 9:54 am

Re: Estimation of AR(2) with t-student

Postby Chuse » Mon Dec 02, 2013 3:25 am

Thank you again, Trubador. Using both methods I can construct the standard errors for QML. :)


Return to “Estimation”

Who is online

Users browsing this forum: No registered users and 2 guests