very general question about calling user defined functions .
Posted: Wed Jan 12, 2011 6:10 pm
Hi,
I am new to Rats, so please be patient ...
I want to estimate linear regressions with Hansen-Hodrick (JPE, 1980) autocorrelation-consistent std errors.
I thought I would just write a function that creates the adjusted covariance matrix, and just call it every time I need it.
this is what I have writen in a file named "hansenhodrick.src" (is this file extension correct? should it be .prg instead? or .txt ? or no extension at all ?)
function hansenhodrick X U nlags
type integer nlags
type rectangular X
type rectangular U
local rectangular ru
local rectangular Theta
local rectangular Omega
local rectangular vcov_HH
compute T = %nobs
compute K = %nreg
compute ru = %zeros(T,1)
do i = 0,(nlags-1)
compute ru(i+1,1) = %scalar(tr(%xsubvec(u,nlags,T))*%xsubvec(u,nlags-i,T-i))/T
end do
compute Omega = %zeros(T,T)
do i=1,T
do j=1,T
compute a = %iabs(j-i)
compute omega(i,j) = %scalar(%xsubvec(ru,1+a,1+a))
end do
end do
compute Theta = T*inv(tr(X)*X)*tr(X)*Omega*X*inv(tr(X)*X)
compute vcov_HH = (Theta/T)
compute hansenhodrick = vcov_HH
end hansenhodrick
Anyway, these calculations, if used in the main code (after a linreg command, extracting the residuals U, using the "make" command to build the X matrix of regressors, and doing "compute nlags = 12 " in a separate line) give me the correct vcov matrix. Its just that, when I try to do it by calling the function by itself, using:
compute hh_vcov = hansenhodrick(X,u,nlags)
RATS gives me the following error:
## SX11. Identifier HANSENHODRICK is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>ov = hansenhodrick(<<<<
I would reeeally appreciate any help or clarification about what I am doing wrong.
Thank you,
Jesus
I am new to Rats, so please be patient ...
I want to estimate linear regressions with Hansen-Hodrick (JPE, 1980) autocorrelation-consistent std errors.
I thought I would just write a function that creates the adjusted covariance matrix, and just call it every time I need it.
this is what I have writen in a file named "hansenhodrick.src" (is this file extension correct? should it be .prg instead? or .txt ? or no extension at all ?)
function hansenhodrick X U nlags
type integer nlags
type rectangular X
type rectangular U
local rectangular ru
local rectangular Theta
local rectangular Omega
local rectangular vcov_HH
compute T = %nobs
compute K = %nreg
compute ru = %zeros(T,1)
do i = 0,(nlags-1)
compute ru(i+1,1) = %scalar(tr(%xsubvec(u,nlags,T))*%xsubvec(u,nlags-i,T-i))/T
end do
compute Omega = %zeros(T,T)
do i=1,T
do j=1,T
compute a = %iabs(j-i)
compute omega(i,j) = %scalar(%xsubvec(ru,1+a,1+a))
end do
end do
compute Theta = T*inv(tr(X)*X)*tr(X)*Omega*X*inv(tr(X)*X)
compute vcov_HH = (Theta/T)
compute hansenhodrick = vcov_HH
end hansenhodrick
Anyway, these calculations, if used in the main code (after a linreg command, extracting the residuals U, using the "make" command to build the X matrix of regressors, and doing "compute nlags = 12 " in a separate line) give me the correct vcov matrix. Its just that, when I try to do it by calling the function by itself, using:
compute hh_vcov = hansenhodrick(X,u,nlags)
RATS gives me the following error:
## SX11. Identifier HANSENHODRICK is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>ov = hansenhodrick(<<<<
I would reeeally appreciate any help or clarification about what I am doing wrong.
Thank you,
Jesus