Examples / OBSERVABLEINDEX.RPF |
OBSERVABLEINDEX.RPF demonstrates estimation of an observable index model from Sargent & Sims(1977). It differs somewhat from the model actually used in the paper as we allow for contemporaneous loadings on the indexes. The model is
\({{\bf{Y}}_t} = A(L)C(L){{\bf{Y}}_t} + D(L){{\bf{Y}}_{t - 1}} + {{\bf{v}}_t}\)
where \({{\bf{Z}}_t} = C(L){{\bf{Y}}_t}\) are the "indexes", \(D(L)\) is diagonal and \({{\bf{v}}_t}\) is assumed to be uncorrelated across variables. Thus, all interactions among the variables are captured in the \(A(L){{\bf{Z}}_t}\) term. The model takes the form of a restricted VAR. With \(\dim ({\bf{Z}}) \ll \dim ({\bf{Y}})\), it will generally have many fewer free parameters than the corresponding full VAR.
The \(A(L)\) and \(C(L)\) aren't separately identifiable without restrictions. They obviously need to be normalized for scale and rotation since \(A(L)C(L) = A(L){\bf{G}}{{\bf{G}}^{ - 1}}C(L)\). It's also possible to have a dynamic invertible factor that cancels, that is, \(A(L)C(L) = A(L)G(L)G{(L)^{ - 1}}C(L)\), so a normalization which fixes the lags of \(C\) is also necessary.
Full Program
*
* Observable index model
* From Sargent & Sims(1977), "Business cycle modeling without pretending
* to have too much a priori economic theory," in "New Methods in
* Business Cycle Research: Proceedings from a Conference", Federal
* Reserve Bank of Minneapolis.
*
* This differs somewhat from the model actually used in the paper above
* because we allow for contemporaneous loadings on the indexes. The model is
*
* Y(t)=A(L)C(L)Y(t)+D(L)Y(t-1)+v(t)
*
* where Z(t)=C(L)Y(t) are the "indexes", D(L) is diagonal and v(t) is
* assumed to be uncorrelated across variables. Thus, all interactions
* among the variables are captured in the A(L)Z(t) term. The model takes
* the form of a restricted VAR. With dim(Z)<<dim(Y), it will generally
* have many fewer free parameters than the corresponding full VAR.
*
* The A(L) and C(L) aren't separately identifiable without restrictions.
* They obviously need to be normalized for scale and rotation since
* A(L)C(L)=A(L)GG^-1C(L). It's also possible to have a dynamic
* invertible factor that cancels, that is, A(L)C(L)=A(L)G(L)G(L)^-1C(L),
* so a normalization which fixes the lags of C is also necessary.
*
open data bbedata.rat
calendar(m) 1959
data(format=rats) 1959:01 2001:07 ipp ipf ipc ipcd ipcn ipe ipi ipm ipmd ipmnd ipmfg ipd ipn ipmin iput $
ip ipxmca pmi pmp gmpyq gmyxpq lhel lhelx lhem lhnag lhur lhu680 lhu5 lhu14 lhu15 lhu26 lpnag lp lpgd $
lpmi lpcc lpem lped lpen lpsp lptu lpt lpfr lps lpgov lphrm lpmosa pmemp gmcq gmcdq gmcnq gmcsq gmcanq $
hsfr hsne hsmw hssou hswst hsbr hmob pmnv pmno pmdel mocmq msondq fsncom fspcom fspin fspcap fsput fsdxp $
fspxe exrsw exrjan exruk exrcan fyff fygm3 fygm6 fygt1 fygt5 fygt10 fyaaac fybaac sfygm3 sfygm6 sfygt1 $
sfygt5 sfygt10 sfyaaac sfybaac fm1 fm2 fm3 fm2dq fmfba fmrra fmrnba fclnq fclbmc ccinrv pmcp pwfsa pwfcsa $
pwimsa pwcmsa psm99q punew pu83 pu84 pu85 puc pucd pus puxf puxhs puxm lehcc lehm hhsntn
*
* NLAGSC is the number of lags in C. It includes the 0 lag as well.
* NLAGSD is the number of lags in D.
* NLAGSA is the number of lags in A. It includes the 0 lag as well.
* NLAGSRF is the derived number of lags in the reduced form.
*
compute nlagsc=2
compute nlagsd=2
compute nlagsa=2
compute nlagsrf=%imax(nlagsc+nlagsa,nlagsd)
*
* NF is the number of factors (indexes)
*
compute nf=1
*
* Specifies the reduced form for the VAR. The variable list is taken
* from this.
*
system(model=reducedform)
variables ip ipd ipn ipp ipc ipcd ipcn ipe ipi ipm ipmd ipmnd ipmfg ipmin iput
lags 1 to nlagsrf
end(system)
*
* Determine the maximum estimation range
*
inquire(equation=%modeleqn(reducedform,1)) rstart rend
*
compute ny=%modelsize(reducedform)
*
dec vect[series] factors(nf)
*
* Set up and initialize the D's (one vector per variable)
*
dec vect[vect] d(ny)
do i=1,ny
compute d(i)=%zeros(nlagsd,1)
end do i
*
* Set up and initialize the C's (one NF x NY matrix per lag)
*
dec vect[rect] c(nlagsc+1)
do i=1,nlagsc+1
compute c(i)=%zeros(nf,ny)
end do i
*
* Set up and initialize the A's (one NY x NF matrix per lag). This is
* initialized with small random numbers so we'll have derivatives with
* respect to C parameters at the guess values.
*
dec vect[rect] a(nlagsa+1)
do i=1,nlagsa+1
compute a(i)=%ranmat(ny,nf)*.1
end do i
*
* Put together a full list of variables and lags. For general
* convenience, these are blocked by lag. Also, initialize the (log)
* variable shock variances using a linear regression.
*
dec vect lsv(ny)
dec table fulltable(2,ny*(nlagsrf+1))
do i=1,ny
compute xseries=%modeldepvars(reducedform)(i)
linreg(noprint) xseries rstart rend
# xseries{1 to nlagsd}
compute lsv(i)=log(%sigmasq)
compute d(i)=%beta
do j=0,nlagsrf
compute fulltable(1,j*ny+i)=xseries
compute fulltable(2,j*ny+i)=j
end do j
end do i
equation fulleqn *
# %rlfromtable(fulltable)
*
* These are the multiplied out coefficients in ARF(L)Y(t)=v(t), though
* this is actually organized as ARF(L)Y(t)=-v(t).
*
dec rect arf(ny,ny*(nlagsrf+1))
************************************************
function %%FillARF
local integer i j k f v
compute arf=%zeros(ny,ny*(nlagsrf+1))
do i=1,ny
compute arf(i,i)=-1.0
do j=1,nlagsd
compute arf(i,j*ny+i)=d(i)(j)
end do j
do j=0,nlagsa
do k=0,nlagsc
do f=1,nf
do v=1,ny
compute arf(i,(j+k)*ny+v)+=a(j+1)(i,f)*c(k+1)(f,v)
end do v
end do f
end do k
end do j
end do i
end %%FillARF
************************************************
dec symm sv
dec real jacobian
*
* This is called before the main function evaluation to multiply out the
* coefficients and create the target covariance matrix from the log
* variance parameters.
*
function %%IndexStart
compute %%fillarf()
compute sv=%diag(%exp(lsv))
compute jacobian=log(abs(%det(%xsubmat(arf,1,ny,1,ny))))
end %%IndexStart
*
* This includes the normalization that C(L) has a 1 coefficient on lag
* zero for the first variable, and 0 coefficients on the other lags on
* the first variable.
*
nonlin c a d lsv c(1)(1,1)=1.0 c(2)(1,1)=0.0 c(3)(1,1)=0.0
*
* Because the model is linear in variables, non-linear in parameters,
* it's possible to dramatically speed up the calculation by forming the
* crossproduct of the data and computing the implied sigma by a
* quadratic form.
*
cmom(equation=fulleqn) rstart rend
compute rnobs=%nobs
compute %cmom=%cmom/rnobs
*
* Because the likelihood function is computed in one shot using the
* quadratic form, we need to use FIND rather than MAXIMIZE. Since this
* includes current Y's on the RHS, we need to include a Jacobian term,
* which needs to be multiplied by the number of observations, since it
* occurs in each one.
*
find(method=bfgs,iters=800,stderrs) max %logl
compute %%IndexStart()
compute [symm] sigmahat=arf*%cmom*tr(arf)
compute %logl=%logdensitycv(sv,sigmahat,rnobs)+rnobs*jacobian
end find
*
* Create reduced form VAR
*
compute ainv=-1.0*inv(%xsubmat(arf,1,ny,1,ny))
compute rfcoeffs=%zeros(ny*nlagsrf,ny)
do k=1,nlagsrf
compute phi=ainv*%xsubmat(arf,1,ny,k*ny+1,(k+1)*ny)
do i=1,ny
do j=1,ny
compute rfcoeffs((j-1)*nlagsrf+k,i)=phi(i,j)
end do j
end do i
end do k
*
compute %modelsetcoeffs(reducedform,rfcoeffs)
compute factor=ainv*%diag(.5*%exp(lsv))
*
* Compute the decomposition of variance
*
errors(factor=factor,model=reducedform,steps=20)
Output
FIND Optimization - Estimation by BFGS
Convergence in 220 Iterations. Final criterion was 0.0000071 <= 0.0000100
Function Value 27494.2965
Variable Coeff Std Error T-Stat Signif
*************************************************************************************
1. C(1)(1,1) 1.00000000 0.00000000 0.00000 0.00000000
2. C(1)(1,2) 0.88608860 0.15090912 5.87167 0.00000000
3. C(1)(1,3) 0.66188629 0.11301619 5.85656 0.00000000
4. C(1)(1,4) -0.55734807 0.08096947 -6.88344 0.00000000
5. C(1)(1,5) 1.44405328 0.25018389 5.77197 0.00000001
6. C(1)(1,6) -0.32507938 0.05532773 -5.87552 0.00000000
7. C(1)(1,7) -1.03525787 0.17625910 -5.87350 0.00000000
8. C(1)(1,8) 0.06225983 0.01947542 3.19684 0.00138941
9. C(1)(1,9) 0.06896533 0.02081602 3.31309 0.00092272
10. C(1)(1,10) -0.28814985 0.04441216 -6.48809 0.00000000
11. C(1)(1,11) 0.04714660 0.01764817 2.67147 0.00755192
12. C(1)(1,12) 0.00529011 0.00460742 1.14817 0.25089824
13. C(1)(1,13) -0.85659486 0.16878318 -5.07512 0.00000039
14. C(1)(1,14) 0.03991730 0.01073563 3.71821 0.00020064
15. C(1)(1,15) 0.02722392 0.00795802 3.42094 0.00062405
16. C(2)(1,1) 0.00000000 0.00000000 0.00000 0.00000000
17. C(2)(1,2) 0.29334073 0.10269801 2.85634 0.00428552
18. C(2)(1,3) 0.24513065 0.08081600 3.03319 0.00241980
19. C(2)(1,4) -0.02979032 0.05752614 -0.51786 0.60455805
20. C(2)(1,5) -0.16574739 0.14550101 -1.13915 0.25464085
21. C(2)(1,6) 0.02732859 0.03175402 0.86063 0.38943975
22. C(2)(1,7) 0.07631517 0.09993858 0.76362 0.44509328
23. C(2)(1,8) -0.02332124 0.01636980 -1.42465 0.15425832
24. C(2)(1,9) -0.00215343 0.01634713 -0.13173 0.89519696
25. C(2)(1,10) -0.04939158 0.03268108 -1.51132 0.13070686
26. C(2)(1,11) -0.01698739 0.01484462 -1.14435 0.25247987
27. C(2)(1,12) 0.00603788 0.00577236 1.04600 0.29556173
28. C(2)(1,13) -0.56558628 0.15836053 -3.57151 0.00035493
29. C(2)(1,14) -0.00516671 0.00849876 -0.60794 0.54322899
30. C(2)(1,15) 0.00252478 0.00612786 0.41202 0.68032676
31. C(3)(1,1) 0.00000000 0.00000000 0.00000 0.00000000
32. C(3)(1,2) 0.05462361 0.07952849 0.68684 0.49218150
33. C(3)(1,3) 0.05395523 0.06338659 0.85121 0.39465334
34. C(3)(1,4) 0.18354499 0.06091329 3.01322 0.00258494
35. C(3)(1,5) 0.01684784 0.08250396 0.20421 0.83819216
36. C(3)(1,6) -0.02124364 0.01911538 -1.11134 0.26642328
37. C(3)(1,7) -0.07676716 0.06065154 -1.26571 0.20561752
38. C(3)(1,8) -0.03420957 0.01503417 -2.27545 0.02287866
39. C(3)(1,9) -0.04545800 0.01776632 -2.55866 0.01050761
40. C(3)(1,10) 0.03317730 0.02999711 1.10602 0.26871939
41. C(3)(1,11) -0.01325689 0.01562749 -0.84831 0.39626754
42. C(3)(1,12) 0.00053693 0.00465736 0.11529 0.90821815
43. C(3)(1,13) -0.10921400 0.13207048 -0.82694 0.40827264
44. C(3)(1,14) -0.00756226 0.00713797 -1.05944 0.28939869
45. C(3)(1,15) 0.00026825 0.00591722 0.04533 0.96384160
46. A(1)(1,1) 0.76593612 0.11366893 6.73831 0.00000000
47. A(1)(2,1) 1.02797310 0.14557166 7.06163 0.00000000
48. A(1)(3,1) 0.36877320 0.05359120 6.88123 0.00000000
49. A(1)(4,1) 0.68097388 0.10476948 6.49974 0.00000000
50. A(1)(5,1) -0.04267733 0.10540701 -0.40488 0.68556473
51. A(1)(6,1) 2.37268002 0.37129781 6.39023 0.00000000
52. A(1)(7,1) 0.63559929 0.10371229 6.12849 0.00000000
53. A(1)(8,1) 0.67644777 0.10452535 6.47161 0.00000000
54. A(1)(9,1) 0.63449738 0.09731038 6.52035 0.00000000
55. A(1)(10,1) 1.01286154 0.16043217 6.31333 0.00000000
56. A(1)(11,1) 1.35242937 0.20071194 6.73816 0.00000000
57. A(1)(12,1) 0.58030736 0.09801867 5.92038 0.00000000
58. A(1)(13,1) 0.85301529 0.12687585 6.72323 0.00000000
59. A(1)(14,1) 0.37002837 0.07426314 4.98267 0.00000063
60. A(1)(15,1) 0.28706690 0.07729959 3.71369 0.00020426
61. A(2)(1,1) 0.32078893 0.07675534 4.17937 0.00002923
62. A(2)(2,1) 0.25940194 0.11119563 2.33284 0.01965639
63. A(2)(3,1) 0.07943936 0.04110606 1.93255 0.05329212
64. A(2)(4,1) 0.03889366 0.06748864 0.57630 0.56441287
65. A(2)(5,1) 0.40209286 0.08807406 4.56539 0.00000499
66. A(2)(6,1) 0.20553597 0.21405520 0.96020 0.33695418
67. A(2)(7,1) -0.04663913 0.06419046 -0.72657 0.46748691
68. A(2)(8,1) 0.19876613 0.07201140 2.76020 0.00577653
69. A(2)(9,1) 0.17741511 0.06445665 2.75247 0.00591472
70. A(2)(10,1) 0.27248462 0.10532549 2.58707 0.00967954
71. A(2)(11,1) 0.09235544 0.13341858 0.69222 0.48879715
72. A(2)(12,1) 0.25527965 0.08460321 3.01738 0.00254974
73. A(2)(13,1) 0.33605946 0.09356435 3.59175 0.00032847
74. A(2)(14,1) -0.06480824 0.05756537 -1.12582 0.26024180
75. A(2)(15,1) 0.13631593 0.06533132 2.08653 0.03693041
76. A(3)(1,1) 0.05974859 0.02724203 2.19325 0.02828936
77. A(3)(2,1) -0.00286551 0.06018518 -0.04761 0.96202589
78. A(3)(3,1) 0.05632265 0.02542842 2.21495 0.02676357
79. A(3)(4,1) 0.01447838 0.02745716 0.52731 0.59797972
80. A(3)(5,1) -0.04803694 0.05701749 -0.84249 0.39951108
81. A(3)(6,1) -0.43137485 0.10833300 -3.98193 0.00006836
82. A(3)(7,1) -0.01871991 0.02600088 -0.71997 0.47154206
83. A(3)(8,1) -0.04892376 0.03014433 -1.62298 0.10459290
84. A(3)(9,1) 0.09044531 0.03542662 2.55303 0.01067895
85. A(3)(10,1) 0.08253662 0.06010583 1.37319 0.16969388
86. A(3)(11,1) 0.07501448 0.06941631 1.08065 0.27985449
87. A(3)(12,1) 0.24266367 0.07439450 3.26185 0.00110688
88. A(3)(13,1) 0.12289642 0.03323768 3.69750 0.00021773
89. A(3)(14,1) 0.02077981 0.04547654 0.45693 0.64771798
90. A(3)(15,1) 0.02284120 0.05716195 0.39959 0.68946036
91. D(1)(1) -0.22300389 0.05807474 -3.83995 0.00012306
92. D(1)(2) -0.02232446 0.04692918 -0.47571 0.63428441
93. D(2)(1) 0.00399755 0.04667312 0.08565 0.93174475
94. D(2)(2) 0.00295576 0.04022111 0.07349 0.94141786
95. D(3)(1) -0.01939499 0.04084237 -0.47487 0.63487659
96. D(3)(2) 0.07402472 0.04113283 1.79965 0.07191584
97. D(4)(1) 0.05897782 0.04169979 1.41434 0.15726113
98. D(4)(2) -0.02226095 0.04385933 -0.50755 0.61176658
99. D(5)(1) -0.27770691 0.07046365 -3.94114 0.00008110
100. D(5)(2) 0.11391754 0.06139940 1.85535 0.06354588
101. D(6)(1) 0.01709008 0.04355031 0.39242 0.69474678
102. D(6)(2) -0.01141678 0.04433499 -0.25751 0.79678370
103. D(7)(1) -0.18856305 0.04284421 -4.40113 0.00001077
104. D(7)(2) -0.12243198 0.04393466 -2.78668 0.00532505
105. D(8)(1) -0.00102467 0.03874513 -0.02645 0.97890137
106. D(8)(2) 0.24210955 0.04003934 6.04679 0.00000000
107. D(9)(1) -0.18617817 0.04130179 -4.50775 0.00000655
108. D(9)(2) -0.02112896 0.04125407 -0.51217 0.60853440
109. D(10)(1) -0.03533337 0.04008080 -0.88155 0.37801832
110. D(10)(2) -0.07069406 0.04117543 -1.71690 0.08599764
111. D(11)(1) 0.21263385 0.03916955 5.42855 0.00000006
112. D(11)(2) -0.09766225 0.04178702 -2.33714 0.01943174
113. D(12)(1) -0.19686835 0.04297523 -4.58097 0.00000463
114. D(12)(2) -0.04089869 0.04312891 -0.94829 0.34298220
115. D(13)(1) -0.20829838 0.05147334 -4.04672 0.00005194
116. D(13)(2) -0.07328170 0.04295190 -1.70613 0.08798312
117. D(14)(1) -0.02884491 0.04350712 -0.66299 0.50733517
118. D(14)(2) -0.10281274 0.04334824 -2.37179 0.01770236
119. D(15)(1) -0.22594516 0.04291775 -5.26461 0.00000014
120. D(15)(2) -0.19055415 0.04294394 -4.43728 0.00000911
121. LSV(1) -13.45291737 0.17601677 -76.42975 0.00000000
122. LSV(2) -10.84572264 0.07214179 -150.33898 0.00000000
123. LSV(3) -10.31477447 0.05900654 -174.80730 0.00000000
124. LSV(4) -11.26328681 0.05370997 -209.70569 0.00000000
125. LSV(5) -9.27565296 0.18898884 -49.08043 0.00000000
126. LSV(6) -7.72592325 0.06670875 -115.81573 0.00000000
127. LSV(7) -9.90277283 0.06943673 -142.61577 0.00000000
128. LSV(8) -9.47790452 0.06830019 -138.76836 0.00000000
129. LSV(9) -10.08241007 0.06292268 -160.23491 0.00000000
130. LSV(10) -10.30251566 0.06642661 -155.09620 0.00000000
131. LSV(11) -9.33079325 0.06135397 -152.08134 0.00000000
132. LSV(12) -8.36668171 0.06374042 -131.26180 0.00000000
133. LSV(13) -12.82063262 0.13590749 -94.33353 0.00000000
134. LSV(14) -8.49814344 0.06303401 -134.81839 0.00000000
135. LSV(15) -8.19473623 0.06179457 -132.61257 0.00000000
Copyright © 2025 Thomas A. Doan