I tried to modify time-varying examples in Tsay's textbook. I have the data only with 53 number of observation and estimate oil demand equation using real oil price and real gdp as explanatory variables. I got the following error.
## MAT15. Subscripts Too Large or Non-Positive Error was evaluating entry 1
Could you please tell me what is wrong with this code. The code and data are attached
Best Regards
Code: Select all
open data 2017_oil_demand.xlsx
cal(a) 1960
data(for=xlsx,org=col) 1960 2012
table
linreg qtot 1960 *
# constant poil ygdp
*
equation(lastreg) mdeq
dec vect sigmav(%nreg)
dec real sigmae
*
* Get guess values based upon the results of a linear regression. All
* standard deviations are scales of the corresponding variances in the
* least squares regression. (The drift ones a much smaller multiple).
*
compute sigmae=.5*sqrt(%seesq)
compute sigmav=.01*%stderrs
*
nonlin sigmae sigmav
*
* The first DLM is Kim and Nelson's way to handle the pre-sample
* variances for the coefficients; large finite values with condition on
* the first 10 data points. A more technically correct way to do this is
* to use PRESAMPLE=DIFFUSE in place of SX0=50.0*%identity(5) as is done
* in the second DLM.
*
* If you use PRESAMPLE=DIFFUSE and don't use the CONDITION option,
* you'll automatically get the likelihood conditional on the first five
* data points (in general, the number of regressors) since there are
* five unit roots in the state-space model.
*
dlm(y=qtot,c=%eqnxvector(mdeq,t),sw=%diag(sigmav.^2),sv=sigmae^2,$
condition=5,method=bfgs) 1970 2012 xstates vstates
table
set b1 = xstates(t)(2)
set b2 = xstates(t)(3)
set lower1 1970 * = b1-1*sqrt(vstates(t)(2,2))
set upper1 1970 * = b1+1*sqrt(vstates(t)(2,2))
set lower2 1970 * = b2-1*sqrt(vstates(t)(3,3))
set upper2 1970 * = b2+1*sqrt(vstates(t)(3,3))
graph(footer="Time-varying regression coefficient of Oil Price") 3
# b1 1970 *
# lower1 1970 *
# upper1 1970 *
graph(footer="Time-varying regression coefficient of Y") 3
# b2 1970 *
# lower1 1970 *
# upper1 1970 *