* DOLS.SRC  Stock-Watson's Dynamic OLS estimation of Cointeg. Vectors
*
*   3/8/94 Written by Ken Hirayama
*
* Syntax:
*   DOLS series start end R r
*   # list of regressors (levels, leads and lags of differences, det. regs.)
*
* (NB: For ease of specifying restriction matrix R, levels should come first.)
*
*     series = dependent variable
*     start end = sample range
*     R = matrix of restrictions for R x b = r  (call by reference)
*     r = vector of constants for R x b = r     (call by reference)
*
* Options:
*   ar =  order of AR for the error process.  2 by default.
*   nr =  number of restrictions.  Equals %rows(R).  0 by default.
*
* References:
*   Hirayama, Kenjiro, and Munehisa Kasuya.  "Financial Deregulation
*      and Divisia Monetary Aggregates in Japan."
*
*  which appears in:
*
*   Andrew Mullineux, ed., Financial Innovation, Banking and
*       Monetary Aggregates, London: Edward Elgar, 1996.  pp. 104-130.
*
procedure dols y ls le rmat rconst
*
type series y                        ;* dependent variable
type integer ls le                   ;* sample range for regression
* following two entries are called by reference not by value.
type rectangular *rmat               ;* R matrix of restrictions (in rows)
type vector *rconst                  ;* r vector of constants
*
option integer ar 2                  ;* AR order of the error process
option integer nr 0                  ;* num. of restrictions = %rows(rmat)
*
local vector[integer]  rhs          ;* regressor list
local symmetric cov                 ;* inverse of (X'X)
local vector bols sebols phi        ;* beta of OLS, its std. err., AR coeffs
local vector tst                    ;* 't' statistics for beta
local real yse2 resse2 a ase2       ;* ase2=adjusted s.e. squared
local real jb w
local integer nobs nvar
local series resid eps
local rectangular rxr
local integer i nv
* Regressor list is read from a supplementary card
enter(varying,entries=nv) rhs
* disp 'nv=' nv ; disp '    rhs=' ;write rhs
linreg y ls le resid
# rhs
compute cov=%xx, bols=%beta, yse2=%seesq, nobs=%nobs, nvar=%nreg
dimension sebols(nvar) tst(nvar) phi(ar)
* dimension R and r for Wald tests, if they are specified.
if nr  {dimension rmat(nr,nvar) rconst(nr)} ;endif
* Estimate AR model for the error process
linreg(noprint) resid / eps
# resid{1 to ar}
compute phi=%beta, resse2=%seesq
* Jarque-Bera test of normality
stat(noprint) eps /
compute jb = (%nobs/6.0)*(%skewness**2) + (%nobs/24.0)*(%kurtosis**2)
disp 'Nobs = ' %nobs ' JB test =' jb '(' #.#### %chisqr(jb,2) ')'
* Covariance adjustment
compute a=1.0                          ;* initialize a
do i=1, ar
  compute a = a - phi(i)               ;* subtract AR coefficient
end do i
compute ase2 = resse2/(a*a)            ;* spectral density at frequency 0
ewise sebols(i) = sqrt(ase2*cov(i,i))  ;* adjusted standard errors
* disp ' a = ' a '     adjusted se2 = ' ase2
* display ' Adjusted Standard Errors of the OLS Estimates '
* write sebols
ewise tst(i) = bols(i)/sebols(i)       ;* 't' statistics
disp ' Standard Errors are adjusted for long-run variance.'
disp $
'  Var.#         Coeff.      S.E.        t-statistic'
do i=1,nvar
  disp @3 ## i @11 #####.##### bols(i) @22 #####.##### sebols(i) $
       @40 ###.### tst(i)
end do i
disp ''
if nr == 0  {
  * disp 'No Wald test: nr = 0 '
  return
  }
if nr <> %rows(rmat) {
  disp ' !!! WARNING !!! The number of restrictions does not match the parameter, nr.'
  return
  }
* Wald test
if nr {
  compute rxr = %mqform(ase2*cov,tr(rmat))
  compute w = %qform(inv(rxr), rmat*bols - rconst)
  disp 'Wald statistic ='  w  '(' #.#### %chisqr(w,%rows(rmat)) ')'
  }
end

