*******************************************************************************
*
*   Computes 'excact' critical values for the Dickey-Fuller and the
*   Engle-Granger cointegration tests from the response surface
*   regression in MacKinnon (1991)
*
*   @EGCRTVAL nobsv nvar critval
*
*   written 08/24/2000 by Stephan Kohns
*
*   Parameters:
*   nobsv   = number of observations of the series to be tested
*   nvar    = number of variables in the underlying regression (1 to 6)
*   critval = vector with 3 entries for the computed critical values at the
*             1%, 5% and 10% level (in this order)
*
*   Options:
*   detcomp = deterministic component in the regression: NCONST for
*             'no constant' (only with nvar=1, i.e. the (A)DF-test), CONSTANT
*             for 'constant term' (default) and TREND for 'constant and trend'
*
*
*******************************************************************************


*******************************************************************************
****
DECLARE RECTANGULAR[REAL] critmat
DIMENSION critmat(39,3)
INPUT critmat
 -2.5658   -1.9600  -10.0400
 -1.9393   -0.3980    0.0000
 -1.6156   -0.1810    0.0000
 -3.4335   -5.9990  -29.2500
 -2.8621   -2.7380   -8.3600
 -2.5671   -1.4380   -4.4800
 -3.9638   -8.3530  -47.4400
 -3.4126   -4.0390  -17.8300
 -3.1279   -2.4180   -7.5800
 -3.9001  -10.5340  -30.0300
 -3.3377   -5.9670   -8.9800
 -3.0462   -4.0690   -5.7300
 -4.3266  -15.5310  -34.0300
 -3.7809   -9.4210  -15.0600
 -3.4959   -7.2030   -4.0100
 -4.2981  -13.7900  -46.3700
 -3.7429   -8.3520  -13.4100
 -3.4518   -6.2410   -2.7900
 -4.6676  -18.4920  -49.3500
 -4.1193  -12.0240  -13.1300
 -3.8344   -9.1880   -4.8500
 -4.6493  -17.1880  -59.2000
 -4.1000  -10.7450  -21.5700
 -3.8110   -8.3170   -5.1900
 -4.9695  -22.5040  -50.2200
 -4.4294  -14.5010  -19.5400
 -4.1474  -11.1650   -9.8800
 -4.9587  -22.1400  -37.2900
 -4.4185  -13.6410  -21.1600
 -4.1327  -10.6380   -5.4800
 -5.2497  -26.6060  -49.5600
 -4.7154  -17.4320  -16.5000
 -4.4345  -13.6540   -5.7700
 -5.2400  -26.2780  -41.6500
 -4.7048  -17.1200  -11.1700
 -4.4242  -13.3470    0.0000
 -5.5127  -30.7350  -52.5000
 -4.9767  -20.8830   -9.0500
 -4.6999  -16.4450    0.0000

PROCEDURE EGCRTVAL nobsv nvar critval
TYPE INTEGER nobsv nvar
TYPE VECTOR[REAL] *critval

OPTION CHOICE detcomp 2 NCONST CONST TREND

* LOCAL RECTANGULAR[REAL] critmat
LOCAL INTEGER row i
DIMENSION critval(3)

IF (nvar.LT.1).OR.(nvar.GT.6)
 {
 DISPLAY 'You must have between 1 and 6 variables!'
 RETURN
 }
IF (detcomp.EQ.1).AND.(nvar.NE.1)
 {
 DISPLAY 'Option "DETCOMP=NCONST" is only possible with one variable!'
 RETURN
 }
COMPUTE row = fix(%IF(detcomp.EQ.1,0,3+(nvar-1)*6+(detcomp-2)*3))
DO i = 1, 3
 COMPUTE critval(i) = critmat(row+i,1)+critmat(row+i,2)/nobsv+critmat(row+i,3)/(nobsv**2)
END DO i

END EGCRITVAL

