forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter3_2.Prg
179 lines (153 loc) · 3.84 KB
/
Chapter3_2.Prg
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
* Chapter 3 part 2
*Program 3.4
cal 1959 1 4
all 2001:1
open data a:\money_dem.xls
data(org=obs,format=xls)
set dlrgdp = log(rgdp) - log(rgdp{1})
set price = gdp/rgdp
set lrm2 = log(m2/price)
dif lrm2 / dlrm2
dif tb3mo / drs
do lags = 16,8,-4
system(model=chap3)
vars dlrgdp dlrm2 drs
lags 1 to lags
det constant
end(system)
estimate(resids=unrestrict,noprint) 59:2+lags *
com aic_u = %nobs*%logdet + 2*(3*lags+1)*3
com sbc_u = %nobs*%logdet + log(%nobs)*(3*lags+1)*3
system(model=chap3)
vars dlrgdp dlrm2 drs
lags 1 to lags-4
det constant
end(system)
estimate(resids=restrict,noprint) 59:2+lags *
com aic_r = %nobs*%logdet + 2*(3*(lags-4)+1)*3
com sbc_r = %nobs*%logdet + log(%nobs)*(3*(lags-4)+1)*3
dis 'Lags = ' lags 'aic_r = ' aic_u 'sbc = ' sbc_u
dis 'Lags = ' lags-4 'aic = ' aic_r 'sbc = ' sbc_r
ratio(degrees=3*4*3,mcorr=3*lags+1,noprint) 59:2+lags *
# unrestrict
# restrict
dis 'Significance level = ' %signif ; dis ' '
end do
set f_ar1 = 0.
set f_ar2 = 0.
do i = 100,168
lin(noprint,define=ar1) dlrgdp 3 i; # constant dlrgdp{1}
forecast 1 1
# ar1 f_ar1
lin(noprint,define=ar2) dlrgdp 3 i; # constant dlrgdp{1 to 2}
forecast 1 1
# ar2 f_ar2
end do i
set pe_1 101 169 = (dlrgdp - f_ar1)**2
set pe_2 101 169 = (dlrgdp - f_ar2)**2
sta(noprint) pe_1
dis 'The MSPE from the AR(1) is: ' %mean
sta(noprint) pe_2
dis 'The MSPE from the AR(2) is: ' %mean
end =
**********
* Program 3.5
cal 1959 1 4
all 2001:1
open data a:\money_dem.xls
data(org=obs,format=xls) /
scratch 6 / scr_no
do i = 1,6
set scr_no+i = log((i+1){0}) - log((i+1){1})
labels scr_no+i ; # 'DL'+%l(i+1)
end do i
tab / scr_no+1 to scr_no+6
end =
***************
* Program 3.6
cal 1959 1 4
all 2001:1
open data a:\money_dem.xls
data(org=obs,format=xls)
set dlrgdp = log(rgdp) - log(rgdp{1})
set dlm3 = log(m3) - log(m3{1})
dif tb3mo / drs
set price = gdp/rgdp
set dlp = log(price) - log(price{1})
spgraph(hea='Graphs of Four Principal Series',hfi=2,vfi=2)
com j = 0
dofor i = dlm3 dlrgdp drs dlp
com j = j + 1
com headers = 'Panel ' + j + ': Time Path of ' + %label([series]i)
gra(hea= headers) 1 ; # i
end do i
spgraph(done)
end =
*********
* Program 3.7
cal 1959 1 4
all 2001:1
open data a:\money_dem.xls
data(org=obs,format=xls)
scratch 3 / scr_no
dofor i = rgdp m2 tb3mo
com j = j + 1
set scr_no+j = log(i{0}) - log(i{1})
labels scr_no+j ; # 'DL'+%l(i)
end dofor
table / scr_no+1 scr_no+2 scr_no+3
com a = %s('rgdp') ; dis a
dofor i = rgdp m2 tb3mo
set %s('dl'+%l(i)) = log(i{0}) - log(i{1})
end dofor
tab
end =
**************
*Program 3.8
cal 1959 1 4
all 2001:1
open data a:\money_dem.xls
data(org=obs,format=xls)
set dlrgdp = log(rgdp) - log(rgdp{1})
set dlm3 = log(m3) - log(m3{1})
dofor i = 7 8 14
do p = 1,2
lin(noprint,entries=i) dlrgdp 6 *
# constant dlrgdp{1 to p} dlm3 dlm3{1 to 4}
compute aic = %nobs*log(%rss) + 2*(%nreg)
compute sbc = %nobs*log(%rss) + (%nreg)*log(%nobs)
dis 'The aic = ' aic ' and sbc = ' sbc
end do p
end dofor i
lin dlrgdp 6 *
# constant dlrgdp{1 to 2} dlm3
dif tb3mo / drs
dif tb1yr / drl
com lags = 13, sign = .5
while sign > 0.05 {
com lags = lags - 1
lin(noprint) drl
# constant drl{1 to lags}
exclude(noprint) ; # drl{lags}
com sign = %signif
dis 'Significance of lag' lags '= ' sign
}
end while
lin drl
# constant drl{1 to lags}
*Jazzing up the program
set price = gdp/rgdp
set dlp = log(price) - log(price{1})
DOFOR i = dlrgdp dlm3 drs drl dlp
com lags = 13, sign = .5
while sign > 0.05 {
com lags = lags - 1
lin(noprint) i
# constant i{1 to lags}
exclude(noprint) ; # [series]i{lags}
com sign = %signif
}
dis %label([series]i) 'Lag length = ' lags
* lin i ; # constant i{1 to lags}
END DOFOR
end =