Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: state space model estimation in STATA
From
"Adjmal Sekander Sirak" <[email protected]>
To
<[email protected]>
Subject
st: state space model estimation in STATA
Date
Thu, 9 Feb 2012 13:40:08 +0100
Hello Stata list,
I have trouble with the sspace command in STATA. The description of my
problem is lengthy, but detailed:
I use STATA 11 SE with all the latest updates. I want to estimate a so
called Dynamic Nelson-Siegel model for sovereign bond yields, which is
basically just a dynamic factor model. I have daily observations over a span
of several years for yields of zero coupon bonds for 16 maturities ranging
from 3 months to ten years. They are all for the same country, of course.
The model that I want to estimate looks like this:
y_{t}(tau) = Lambda(tau)*f_{t}+eps_{t}
f_{t} = A*f_{t-1} + (I-A)*mu + eta_{t}
where t denotes the time of observation and tau the maturity. y_{t} is a
16x1 vector and f_{t} is usually 3x1, but I discard the third element for
parsimony. This is also done by other authors in the literature. The
elements of Lambda(tau) are fixed values given by the Nelson-Siegel model
and need not be estimated. The two error terms are independent of each other
and of their own lags or leads.
There is a total of 25 parameters to be estimated based on 3001
observations. However, the ML estimation routine invoked by the sspace
command does not converge. In general, the loglikelihood attains values of
about +24000 to +26000 and then I receive an error message either telling me
that a flat region was encountered or that the Hessian is not positive
definite.
Below, you will find the most important parts of a log I have recorded for
the latest run.
I have done a couple of things to ease the problem.
- I have cut the sample at Januray 1st 2008, such as to exclude a very sharp
decline in yields that occured shortly afterwards.
- I have estimated the model using a so called 2-step OLS approach and used
the results as initial values for the ML estimation. It is remarkable that
the log-likelihood associated with these values is about -22 million (!). It
quickly improves, and after 435 iterations it has attained a value of
+24296. Then a refining of the parameters starts and eventually terminates
because of a bad Hessian.
- I set the -difficult- option in the sspace command.
Furthermore, I have generated artificial data from the model I try to
estimate and provided population moments as initial values for the ML
maximization. The routine did converge, but it took her more than 1 hour.
Basically, I have two questions:
1: Could it be that STATA is just incapable of estimating state space models
with say more than 20 parameters? My ultimate goal is to include more
regressors, so the number of parameters would increase at a later stage. If
so, what other packages can you recommend?
2: Am I doing something wrong in the model set-up? How can it be that the
log-likelihood is -22 million when my initial guess comes from a less
sophisticated, but decent estimate of the model? Do I assign the initial
values in a wrong manner? I made sure to use the same order of coefficients
in my initial values vector "init" (see below) as in the parameter vector
e(b). Could you please take a look at my sspace command and the constraints?
Any help will gratefully be appreciated.
Please find below the most important parts of my log-file. The 32
constraints that I impose fix the matrix Lambda(tau) from the model above:
opened on: 9 Feb 2012, 01:21:54
.
. use "Italy_filled.dta"
.
.
.
. constraint drop _all
. constraint define 1 [italy_3m]lev = 1
. constraint define 2 [italy_3m]slo = 0.9139681245
. constraint define 3 [italy_6m]lev = 1
. constraint define 4 [italy_6m]slo = 0.8376600229
. constraint define 5 [italy_9m]lev = 1
. constraint define 6 [italy_9m]slo = 0.7698466392
. constraint define 7 [italy_12m]lev = 1
. constraint define 8 [italy_12m]slo = 0.7094641255
. constraint define 9 [italy_15m]lev = 1
. constraint define 10 [italy_15m]slo = 0.6555907479
. constraint define 11 [italy_18m]lev = 1
. constraint define 12 [italy_18m]slo = 0.6074271117
. constraint define 13 [italy_24m]lev = 1
. constraint define 14 [italy_24m]slo = 0.5255439287
. constraint define 15 [italy_30m]lev = 1
. constraint define 16 [italy_30m]slo = 0.4592799502
. constraint define 17 [italy_36m]lev = 1
. constraint define 18 [italy_36m]slo = 0.4051959175
. constraint define 19 [italy_48m]lev = 1
. constraint define 20 [italy_48m]slo = 0.3236995842
. constraint define 21 [italy_60m]lev = 1
. constraint define 22 [italy_60m]slo = 0.2665880208
. constraint define 23 [italy_72m]lev = 1
. constraint define 24 [italy_72m]slo = 0.2252177110
. constraint define 25 [italy_84m]lev = 1
. constraint define 26 [italy_84m]slo = 0.1943071438
. constraint define 27 [italy_96m]lev = 1
. constraint define 28 [italy_96m]slo = 0.1705510595
. constraint define 29 [italy_108m]lev = 1
. constraint define 30 [italy_108m]slo = 0.151828781
. constraint define 31 [italy_120m]lev = 1
. constraint define 32 [italy_120m]slo = 0.136744642
.
. matrix init = J(1, 57, 1)
. matrix init[1,1] = 0.9971
. matrix init[1,2] = 0.0028
. matrix init[1,3] = 4.8495
. matrix init[1,4] = -0.0003
. matrix init[1,5] = 0.9986
. matrix init[1,6] = -1.4208
. matrix init[1,8] = 0.9139681245
. matrix init[1,10] = 0.8376600229
. matrix init[1,12] = 0.7698466392
. matrix init[1,14] = 0.7094641255
. matrix init[1,16] = 0.6555907479
. matrix init[1,18] = 0.6074271117
. matrix init[1,20] = 0.5255439287
. matrix init[1,22] = 0.4592799502
. matrix init[1,24] = 0.4051959175
. matrix init[1,26] = 0.3236995842
. matrix init[1,28] = 0.2665880208
. matrix init[1,30] = 0.2252177110
. matrix init[1,32] = 0.1943071438
. matrix init[1,34] = 0.1705510595
. matrix init[1,36] = 0.151828781
. matrix init[1,38] = 0.136744642
. matrix init[1,39] = 0.0031
. matrix init[1,40] = -0.003
. matrix init[1,41] = 0.0045
. matrix init[1,42] = 0.0687
. matrix init[1,43] = 0.0134
. matrix init[1,44] = 0.0015
. matrix init[1,45] = 0.0056
. matrix init[1,46] = 0.0124
. matrix init[1,47] = 0.0174
. matrix init[1,48] = 0.0201
. matrix init[1,49] = 0.0185
. matrix init[1,50] = 0.0157
. matrix init[1,51] = 0.0070
. matrix init[1,52] = 0.0018
. matrix init[1,53] = 0.0006
. matrix init[1,54] = 0.0030
. matrix init[1,55] = 0.0078
. matrix init[1,56] = 0.0137
. matrix init[1,57] = 0.0199
.
. sspace (lev L.lev L.slo, state) (slo L.lev L.slo, state) ///
(italy_3m lev slo, noconstant) (italy_6m lev slo, noconstant) ///
(italy_9m lev slo, noconstant) (italy_12m lev slo, noconstant) ///
(italy_15m lev slo, noconstant) (italy_18m lev slo, noconstant) ///
(italy_24m lev slo, noconstant) (italy_30m lev slo, noconstant) ///
(italy_36m lev slo, noconstant) (italy_48m lev slo, noconstant) ///
(italy_60m lev slo, noconstant) (italy_72m lev slo, noconstant) ///
(italy_84m lev slo, noconstant) (italy_96m lev slo, noconstant) ///
(italy_108m lev slo, noconstant) (italy_120m lev slo, noconstant) ///
in 1/3001, constraints(1/32) covstate(unstructured) covobserved(diagonal)
///
technique(bfgs 30 dfp) difficult trace from(init)
-----------------------------------------------------------------------------------------------------------------------------------
Iteration 0:
Parameter vector:
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 4.8495 -.0003 .9986 -1.4208 .9971
.0028 -2.888177 -.0538816 -3.219885 -1.339003 -2.15625
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 -3.251145 -2.592494 -2.195029 -2.025643 -1.953518 -1.994992 -2.077047
-2.480923 -3.159984 -3.70929 -2.904571
c23 c24 c25
r1 -2.426816 -2.14518 -1.958518
(setting technique to bfgs)
log likelihood
-22048580
Gradient vector (length = 6.56e+08):
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 -1.09e+07 -1.08e+08 1.86e+08 -6161710 -1.27e+08 3.06e+08
5.21e+07 5.20e+08 2.01e+07 5394.853 8661.72
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 12309.06 131.864 1014.223 1857.758 3677.1 5067.992
5759.784 8498.294 12013.51 81.54907 3463.534
c23 c24 c25
r1 6878.738 8596.718 9743.972
Step vector (length = 6.56e+08):
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 -1.09e+07 -1.08e+08 1.86e+08 -6161710 -1.27e+08 3.06e+08
5.21e+07 5.20e+08 2.01e+07 5394.853 8661.72
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 12309.06 131.864 1014.223 1857.758 3677.1 5067.992
5759.784 8498.294 12013.51 81.54907 3463.534
c23 c24 c25
r1 6878.738 8596.718 9743.972
Parameters + step -> new parameters
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 -1.09e+07 -1.08e+08 1.86e+08 -6161711 -1.27e+08 3.06e+08
5.21e+07 5.20e+08 2.01e+07 5393.514 8659.563
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 12305.81 129.2715 1012.028 1855.732 3675.147 5065.997
5757.707 8495.813 12010.35 77.83978 3460.629
c23 c24 c25
r1 6876.312 8594.573 9742.013
log likelihood =
.
(initial step
bad)
(1) Reducing step size (step length = 3.28e+08)
New parameter vector:
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 -5468925 -5.42e+07 9.29e+07 -3080856 -6.34e+07 1.53e+08
2.60e+07 2.60e+08 1.00e+07 2696.088 4328.704
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 6151.28 63.33949 504.9167 926.8534 1836.597 2532.001
2877.815 4246.666 6003.597 37.06524 1728.862
c23 c24 c25
r1 3436.942 4296.214 4870.027
log likelihood =
.
[...]
(26) Reducing step size (step length = 9.771832)
New parameter vector:
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 4.686513 -1.614795 3.768134 -1.512617 -.8935636
4.567683 -2.112357 7.696786 -2.921106 -1.338923 -2.156121
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 -3.250962 -2.592492 -2.195014 -2.025615 -1.953463 -1.994917 -2.076961
-2.480796 -3.159805 -3.709289 -2.90452
c23 c24 c25
r1 -2.426713 -2.145052 -1.958373
log likelihood
= -1747077.9
[...]
Iteration 435:
Parameter vector:
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 .0073259 .0011075 .9976741 -.0081533 .9988128
.0009616 -2.969368 -.0433153 -2.625749 -.3030527 -.6747271
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 -1.090965 -1.528132 -1.933222 -2.395474 -8.722267 -3.255435 -3.28521
-4.237834 -2.861202 -2.037721 -1.558244
c23 c24 c25
r1 -1.246959 -1.037893 -.8863995
Changed elements of parameter vector:
c1 c2
r1 1.04e-06 1.17e-06
log likelihood =
24296.763
(backed
up)
g inv(H) g' =
4.453e-06
Gradient vector (length = .4679292):
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 -.0194624 .2637659 -.072292 .0743563 -.3376707 .0521295
.0124938 .1099943 .0106004 .0223551 .0182446
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 .0009588 .000975 .0146925 -.0373481 -.00183 -.0055763
.0039956 .0003285 -.0202807 .0371865 -.0158965
c23 c24 c25
r1 -.0434237 -.0207417 -.0478214
-----------------------------------------------------------------------------------------------------------------------------------
Refining estimates:
-----------------------------------------------------------------------------------------------------------------------------------
Iteration 0:
Parameter vector:
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 .0073259 .0011075 .9976741 -.0081533 .9988128 .0009616
.0026354 -.0022236 .0071159 .5454712 .2593818
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 .1128237 .0470632 .0209327 .0083046 2.65e-08 .0014872
.0014012 .0002085 .0032718 .0169847 .0443125
c23 c24 c25
r1 .0825858 .1254577 .1698569
log likelihood =
24296.763
(backed
up)
Gradient vector (length = 34473.89):
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 -.0194624 .2637658 -.0722921 .0743563 -.3376711 .0521295
3.994529 3.84967 1.011552 .0204915 .0351693
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 .0042489 .0103589 .3509474 -2.248642 -34473.89 -1.874775
1.425784 .7877479 -3.099286 1.094707 -.1793684
c23 c24 c25
r1 -.2629005 -.0826643 -.1407696
Step vector (length = .0006004):
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 -.0000349 .0000109 -.0000362 -.00011
7.83e-06 -6.11e-07 -8.97e-06 -4.84e-07 .0001031 .000444 .0002568
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 .0001368 .0000686 .0000323 .0000114 -6.03e-06 -2.33e-06
3.50e-07 5.01e-06 -7.90e-06 -.0000302 -.0000591
c23 c24 c25
r1 -.0000898 -.0001173 -.0001448
Parameters + step -> new parameters
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 .0072911 .0011184 .9976379 -.0082633 .9988207 .000961
.0026264 -.0022241 .007219 .5459152 .2596386
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 .1129605 .0471318 .020965 .008316 -6.01e-06 .0014849
.0014016 .0002135 .0032639 .0169545 .0442534
c23 c24 c25
r1 .082496 .1253404 .1697121
log likelihood =
.
(initial step
bad)
[...]
Iteration 14:
Parameter vector:
c1 c2 c3 c4 c5 c6
c7 c8 c9 c10 c11
r1 .0073258 .0011075 .997674 -.0081537 .9988129 .0009616
.0026353 -.0022236 .0071163 .5454731 .2593829
c12 c13 c14 c15 c16 c17
c18 c19 c20 c21 c22
r1 .1128243 .0470635 .0209328 .0083046 1.27e-10 .0014872
.0014012 .0002085 .0032718 .0169846 .0443123
c23 c24 c25
r1 .0825854 .1254572 .1698563
optimization terminated because the negative hessian in the untransformed
space is not positive definite; it may be that your model
is not identified
r(430);
end of do-file
r(430);
. log close
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/