-
Notifications
You must be signed in to change notification settings - Fork 0
/
chow_dummy_matrix.inp
42 lines (42 loc) · 1.92 KB
/
chow_dummy_matrix.inp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function bundle chow_dummy_matrix (const series Y "Dependent Variable",
const list xvars "Regressors",
const string break_date "Break Date",
const bool auxregprint[0] "Print Auxiliary Regression or not")
bundle dummy_chow
matrix y = {Y}
matrix X = {xvars}
matrix len = zeros(nelem(xvars),1)
loop i=1..nelem(xvars) -q
len[i,] = nobs(xvars[i])
endloop
scalar idx_row = $nobs - min(len) + 1
scalar idx_col = obsnum(break_date) - ($tmax - $nobs)
matrix dummy = I($nobs)
matrix dummy = dummy[idx_row:,idx_col:]
matrix y = y[idx_row:,]
matrix X_test = X ~ dummy
matrix beta_u = inv(X_test'X_test)*X_test'y
matrix e_u = y - X_test*beta_u
scalar SSR_u = e_u'e_u
matrix beta_r = inv(X'X)*X'y
matrix e_r = y - X*beta_r
scalar SSR_r = e_r'e_r
matrix var_beta_u = (SSR_u/(rows(X_test)-cols(X_test)))*inv(X_test'X_test)
matrix df = {cols(dummy),(rows(X_test) - cols(X_test))}
scalar dummy_chow.F = ((SSR_r - SSR_u)/df[,1])/(SSR_u/df[,2])
matrix dummy_chow.df = df
scalar dummy_chow.pval = pvalue(F,df[,1],df[,2],dummy_chow.F)
matrix dummy_chow.auxreg = beta_u ~ beta_u ./ sqrt(var_beta_u[diag]) ~ (pvalue(t,df[,2],abs(beta_u ./ sqrt(var_beta_u[diag]))))*2
scalar dummy_chow.rsq_aux = 1 - (SSR_u/(y - mean(y))'(y - mean(y)))
rnameset(dummy_chow.auxreg, varnames(xvars))
if auxregprint
printf "Chow test (dummy version) auxiliary regression\
\n coeffs ttest p-value\
\n%10.4f",dummy_chow.auxreg
printf "R^2 auxiliary regression: %.4g\n", dummy_chow.rsq_aux
endif
printf "Chow Test (dummy version) break at observation %s\nH0: No structural break\n\
\t F(%g,%g) = %.6g\n\
\t P-value = %.6g\n\n", break_date, df[,1], df[,2], dummy_chow.F, dummy_chow.pval
return dummy_chow
end function