On Tue, 16 Sep 2014, Dominik Menno wrote:
Dear All,
I would like to estimate a symmetric VAR(1) process
y = Ay(-1) + u
where u is random variable with variance covariance matrix S.
Symmetric in the sense that the diagonal elements of A are equal and the
off-diagonals are equal, i.e. a11 = a22 and a12=a21. But now the
problem: I also want to restrict the variance covariance matrix to be
symmetric, that is, the variances should be the same.
The way _I_ would do this is by numerically maximising the loglikelihood
with respect to the unconstrained parameters. Of course, to evaluate the
loglikelihood you need a function that returns the unconstrained
parameters given the constrained ones: here's an example.
<hansl>
set echo off
set messages off
function scalar make_matrices(matrix theta, matrix *A,
matrix *S, scalar *ldetS)
A[1,1] = theta[1]
A[1,2] = theta[2]
A[2,1] = theta[2]
A[2,2] = theta[1]
S[1,1] = theta[3]
S[1,2] = theta[4]
S[2,1] = theta[4]
S[2,2] = theta[3]
if theta[3] >= 0
lA = eigensym(A)
lS = eigensym(S)
scalar stable = maxc(abs(lA)) < 1
scalar pd = minc(lS) > 0
scalar err = ! (stable && pd)
scalar ldetS = sumc(ln(lS))
else
scalar err = 1
scalar ldetS = 0
endif
return err
end function
function scalar VAR_loglik(list Y, matrix theta)
matrix mY = {Y}
scalar T = rows(mY)
scalar n = cols(mY)
matrix A = zeros(2,2)
matrix S = zeros(2,2)
scalar l = 0
err = make_matrices(theta, &A, &S, &l)
if err
scalar LL = NA
else
matrix E = mY - mlag(mY, 1)*A
matrix V = E'E
scalar LL = -T/2 * (n*ln(2*$pi) + l) - 0.5 * tr(S\V)
endif
return LL
end function
# --- example data -------------
nulldata 100
mE = mnormal($nobs-1, 2)
mA = {0.8, 0.1; 0.1, 0.8}
mY = varsimul(mA, mE, zeros(1,2))
series y1 = mY[,1]
series y2 = mY[,2]
list Y = y1 y2
var 1 Y --nc --silent
Ahat = $compan
Shat = $sigma
LL0 = $lnl
print Ahat Shat LL0
theta = Ahat[,1] | Shat[,1]
mle LL = VAR_loglik(Y, theta)
params theta
end mle --verbose
</hansl>
In this case, the function that maps the free parameters onto the
constrained ones also performs a few basic checks so BFGS doesn't go
berserk :)
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------