I'm working through this book (Commandeur, Jacques JF, and Siem Jan Koopman. An introduction to state space time series analysis. Oxford University Press, 2007.) and I want to replicate a few of the simple models in Stata 13.1. The two related models I'm working on now are special cases of the local level model:
\begin{align}
y_t &= u_t + \epsilon_t \\
u_{t+1} &= u_t + \xi_t
\end{align}
In the first example (the "deterministic level"), $$\xi_t = 0$$, so $$y_t = u_1 + \epsilon_t$$. I know this is a trivial model to estimate (because we're just estimating the mean and variance of the y's), but I wanted to match the book and estimate it with state space commands. Here is the code I'm using for this example (this code includes the data; the actual sspace statement is at the bottom):
Code:
clear cls input ksi t ksi t 1687 108 1508 109 1507 110 1385 111 1632 112 1511 113 1559 114 1630 115 1579 116 1653 117 2152 118 2148 119 1752 120 1765 121 1717 122 1558 123 1575 124 1520 125 1805 126 1800 127 1719 128 2008 129 2242 130 2478 131 2030 132 1655 133 1693 134 1623 135 1805 136 1746 137 1795 138 1926 139 1619 140 1992 141 2233 142 2192 143 2080 144 1768 145 1835 146 1569 147 1976 148 1853 149 1965 150 1689 151 1778 152 1976 153 2397 154 2654 155 2097 156 1963 157 1677 158 1941 159 2003 160 1813 161 2012 162 1912 163 2084 164 2080 165 2118 166 2150 167 1608 168 1503 169 1548 170 1382 171 1731 172 1798 173 1779 174 1887 175 2004 176 2077 177 2092 178 2051 179 1577 180 1356 181 1652 182 1382 183 1519 184 1421 185 1442 186 1543 187 1656 188 1561 189 1905 190 2199 191 1473 192 1655 193 1407 194 1395 195 1530 196 1309 197 1526 198 1327 199 1627 200 1748 201 1958 202 2274 203 1648 204 1401 205 1411 206 1403 207 1394 208 1520 209 1528 210 1643 211 1515 212 1685 213 2000 214 2215 215 1956 216 1462 217 1563 218 1459 219 1446 220 1622 221 1657 222 1638 223 1643 224 1683 225 2050 226 2262 227 1813 228 1445 229 1762 230 1461 231 1556 232 1431 233 1427 234 1554 235 1645 236 1653 237 2016 238 2207 239 1665 240 1361 241 1506 242 1360 243 1453 244 1522 245 1460 246 1552 247 1548 248 1827 249 1737 250 1941 251 1474 252 1458 253 1542 254 1404 255 1522 256 1385 257 1641 258 1510 259 1681 260 1938 261 1868 262 1726 263 1456 264 1445 265 1456 266 1365 267 1487 268 1558 269 1488 270 1684 271 1594 272 1850 273 1998 274 2079 275 1494 276 1057 277 1218 278 1168 279 1236 280 1076 281 1174 282 1139 283 1427 284 1487 285 1483 286 1513 287 1357 288 1165 289 1282 290 1110 291 1297 292 1185 293 1222 294 1284 295 1444 296 1575 297 1737 298 1763 299 end tsset t, monthly gen lgksi = log(ksi) sspace (u L.u, state noerror noconstant) (lgksi u, noconstant)
Code:
sspace (u L.u, state noerror noconstant) (lgksi u, noconstant)
In the second model, $\xi_t$ is allowed to vary, so we're simply estimating the basic local level model. This is my code:
Code:
clear input t norway t norway 1970 560 1971 533 1972 490 1973 511 1974 509 1975 539 1976 471 1977 442 1978 434 1979 437 1980 362 1981 338 1982 401 1983 409 1984 407 1985 402 1986 452 1987 398 1988 378 1989 381 1990 332 1991 323 1992 325 1993 281 1994 283 1995 305 1996 255 1997 303 1998 352 1999 304 2000 341 2001 275 2002 312 2003 280 end g lgnorway = log(norway) tsset t, yearly sspace (u L.u, state noconstant) (lgnorway u, noconstant)
Code:
Iteration 394: log likelihood = 17.749084 (not concave) Iteration 395: log likelihood = 17.749084 (not concave) Iteration 396: log likelihood = 17.749084 (not concave) Iteration 397: log likelihood = 17.749084 (not concave) Iteration 398: log likelihood = 17.749084 (not concave) Iteration 399: log likelihood = 17.749084 (not concave) Iteration 400: log likelihood = 17.749084 (not concave) Iteration 401: log likelihood = 17.749084 (not concave) Iteration 402: log likelihood = 17.749084 (not concave) Iteration 403: log likelihood = 17.749084 (not concave)
Thank you,
Michael Anbar
P.S. As a side note, mathjax rendering doesn't seem to work in previews on Windows 7/Firefox 31.
Comment