* This command file shows: * - The use of the RECUNIT= option on the DIAGNOS command. * - SHAZAM commands for calculating recursive coefficient estimates. * This replicates the results obtained with the RECUR option * on the DIAGNOS command. * - SHAZAM commands for calculating the Hansen test of model stability. * This replicates the results obtained with the HANSEN option * on the DIAGNOS command. SAMPLE 1 17 * Load the Theil textile data set read year consume income price 1923 99.2 96.7 101.0 1924 99.0 98.1 100.1 1925 100.0 100.0 100.0 1926 111.6 104.9 90.6 1927 122.2 104.9 86.5 1928 117.6 109.5 89.7 1929 121.1 110.8 90.6 1930 136.0 112.3 82.8 1931 154.2 109.3 70.1 1932 153.6 105.3 65.4 1933 158.5 101.7 61.3 1934 140.6 95.4 62.5 1935 136.2 96.4 63.6 1936 168.0 97.6 52.6 1937 154.3 102.4 59.7 1938 149.0 101.6 59.5 1939 165.5 103.8 61.3 GEN1 NOBS=17 * Save the recursive residuals in the file RESID.DAT FILE 11 RESID.DAT OLS CONSUME INCOME PRICE DIAGNOS / RECUR RECUNIT=11 * Load the recursive residuals SAMPLE 4 NOBS READ (11) OBS RR CUSUM BOUND LOWER CUSUMSQ UPPER / REWIND PRINT OBS RR * Generate recursive estimates and save in the matrix REST DIM REST 15 3 GEN1 BEG=3 SET NOOUTPUT NODOECHO DO #=BEG,NOBS SAMPLE 1 # OLS CONSUME INCOME PRICE / COEF=BETA GEN1 ROW=#-2 DO !=ROW,ROW MATRIX REST(!,0)=BETA' ENDO ENDO * Note that the first regression with 3 observations generates * the message: ...WARNING..ZERO DEGREES OF FREEDOM LEFT * OLS coefficient estimates can be calculated but the standard * errors are zero. PRINT REST * Hansen test of model stability. SET OUTPUT SAMPLE 1 17 OLS CONSUME INCOME PRICE / RESID=E DN DIAGNOS / HANSEN * Now show the calculations with SHAZAM commands. GEN1 SIG2=$SIG2 GEN1 KK=$K+1 GENR ONE=1 COPY INCOME PRICE ONE X DIM ST KK F KK KK S KK KK DO #=1,NOBS MATRIX F1=X(#,0)'*E:# MATRIX F2=(E:#)**2 - SIG2 MATRIX FT=(F1'|F2')' MATRIX F=F+FT*FT' MATRIX ST=ST+FT MATRIX S=S+ST*ST' ENDO * The Hansen test statistic MATRIX HANSEN=TRACE(INV(F)*S)/NOBS PRINT HANSEN STOP