structural models for time series

Discussion of State Space and Dynamic Stochastic General Equilibrium Models
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: structural models for time series

Unread post by TomDoan »

For quarterly, this would be something like:

Code: Select all

compute s=4
all 200
*
dec vect[series] zt(s-1)
dec frml[vect] cf
do h=1,s/2
   set zt(2*h-1) = cos(2*%pi*h*t/s)
   if 2*h<=s-1
      set zt(2*h) = sin(2*%pi*h*t/s)
end do h
frml cf = %xt(zt,t)
*
dec symm sigmaeta(s-1,s-1)
compute sigmaeta=%diag(||.1,.1,.3||)
compute sigmaeps=||1.0||
*
dlm(type=simulate,c=cf,sw=sigmaeta,sv=sigmaeps,yhat=ysim,presample=ergodic) 1 200 
set y = ysim(t)(1)
mcorozcos
Posts: 23
Joined: Wed Feb 08, 2012 10:04 am

Re: structural models for time series

Unread post by mcorozcos »

Hello Tom,

Thanks for your help.
But now I need to change a serie of Random Walk that I attachment the code, in one serie that include elements seasonal, like this equation

yt = summation of h=1 until h=[s/2] of γt(h),

Where,
yt is a random walk, like that, γt(h) = γt−1(h) + ηt(h), h= 1, ..., [s/2],
nt is a white noise, like that, ηt(h) ∼ IID (0, Σ η(h)), h= 1, ..., [s/2],

I don´t understand how I include h= 1, ..., [s/2], in the random walk and the white noise in order to create the serie simulated

Again, I need a simulate serie of 500 observations, the same that I created

thanks for your help

Regards

Code: Select all

compute n = 500
compute rvar=1.0
set a 1 n = 0.0
set u 1 n = 0.0
do i=1,n
compute a(i)=%ran(rvar)
end do i
compute p = 1
do i=1,p
compute u(i)=%ran(rvar)
end do i
do i=p+2,n
compute u(i)=u(i-1)+a(i)
end do i
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: structural models for time series

Unread post by TomDoan »

The program I wrote does that. The "sum" is done by the C vector. Work through the state-space representation, and you'll see.
mcorozcos
Posts: 23
Joined: Wed Feb 08, 2012 10:04 am

Re: structural models for time series

Unread post by mcorozcos »

Hello Tom,

I tried to write the program but I have problems:
1. I have a problem when I tried to make a white noise with the rank h=1......[s/2], because it show only fourth observations, the others are zero.
2. When, I created a vector c, it have an error " ## DLM5. Probable Model Error. Diffuse prior was not reduced to zero rank" and I tried to make differents things in order to find a solution for this error, but I do not know what happened.

Can you help? I attachment my code in order to revise which is the problem.

Code: Select all

compute n = 500
compute rvar=1.0
set a 1 n = 0.0
set u 1 n = 0.0
compute s = 4

do h=1, s/2
compute a(h)=%ran(rvar)
end do h                            
print / a

compute p = 1
do h=1,p
compute u(h)=%ran(rvar)
end do h
*do i=p+2,n
*compute u(i)=u(i-1)+a(i)
*end do i
*print / u

all 500
*
dec vect[series] vt(s-1)
dec frml[vect] cf
do h=1,s/2
   set vt(h) = u(h-1)*t+a(h)*t
end do h
frml cf = %xt(vt,t)
*
dec symm sigmaeta(s-1,s-1)
compute sigmaeta=%diag(||.1,.1,.3||)
compute sigmaeps=||1.0||
*
dlm(type=simulate,c=cf,sw=sigmaeta,sv=sigmaeps,yhat=ysim,presample=ergodic) 1 500
set y = ysim(t)(1)
Thanks for your help.

Regards
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: structural models for time series

Unread post by TomDoan »

What I wrote does your model. I converted it into state space form from the somewhat odd notation used by the authors. The DLM does the simulations---all you have to do is change the variances.
mcorozcos
Posts: 23
Joined: Wed Feb 08, 2012 10:04 am

Re: structural models for time series

Unread post by mcorozcos »

thanks, but if I created a randown walk with variance 1.0 for one distribution normal, what kind of variance I have to put in the instruction dlm?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: structural models for time series

Unread post by TomDoan »

The variances are controlled by:

compute sigmaeta=%diag(||.1,.1,.3||)
compute sigmaeps=||1.0||

sigmaeta are the variances of the random walks on the Fourier series. It sounds like you want those all to be 1.0. sigmaeps is the purely random error---you'll have to figure out what you want there.
mcorozcos
Posts: 23
Joined: Wed Feb 08, 2012 10:04 am

Re: structural models for time series

Unread post by mcorozcos »

Hello Tom,

I have a question: I tried to change of code, data monthly and I have many problems with dimension of matrix cf because it is diferent. How I use this instrucction for data monthly?

I have an other question: which is the best form to extract of seasonal for two simulated series? I tried to use X11 but this instruction can´t use for negative data, only data positive, acording with error of RATS

Finally, I need to fit a model, for two series of data reals (monthly or quarterly), the model is:

yt = μt+st + εt,
μt = random walk
st = component seasonal, like the code of down
εt ∼ IID (0, Σ ε) white noise
yt = are series of data reals, monthly or quarterly

I hope you can help me, again thank you so much


Thanks for your help

TomDoan wrote:For quarterly, this would be something like:

Code: Select all

compute s=4
all 200
*
dec vect[series] zt(s-1)
dec frml[vect] cf
do h=1,s/2
   set zt(2*h-1) = cos(2*%pi*h*t/s)
   if 2*h<=s-1
      set zt(2*h) = sin(2*%pi*h*t/s)
end do h
frml cf = %xt(zt,t)
*
dec symm sigmaeta(s-1,s-1)
compute sigmaeta=%diag(||.1,.1,.3||)
compute sigmaeps=||1.0||
*
dlm(type=simulate,c=cf,sw=sigmaeta,sv=sigmaeps,yhat=ysim,presample=ergodic) 1 200 
set y = ysim(t)(1)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: structural models for time series

Unread post by TomDoan »

Change S=4 to S=12. There are now 11 component variances in sigmaeta.

You can use X11 with an additive adjustment (not multiplicative or log additive). However, isn't this supposed to be a state-space model of seasonality?
mcorozcos
Posts: 23
Joined: Wed Feb 08, 2012 10:04 am

Re: structural models for time series

Unread post by mcorozcos »

Hello Tom

Thanks for your explication about the change a data monthly, I have a question, the values of matriz of variances sigmaeta, can be numbers anyone?

Yes, it is a model space state of seasonality, but I need to apply a other metodology, for this reason I need to extract the seasonality.

What about the fit of the model before?

Thanks for your help
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: structural models for time series

Unread post by TomDoan »

mcorozcos wrote:Hello Tom

Thanks for your explication about the change a data monthly, I have a question, the values of matriz of variances sigmaeta, can be numbers anyone?

Yes, it is a model space state of seasonality, but I need to apply a other metodology, for this reason I need to extract the seasonality.

What about the fit of the model before?

Thanks for your help
Perhaps you should contact the authors of the paper to find out what kinds of values they think are reasonable. They could be any non-zero values, but what's reasonable (in comparison to the pure-noise variance) is not clear. If they are too high, the seasonals will be too variable to be useful.
mcorozcos
Posts: 23
Joined: Wed Feb 08, 2012 10:04 am

Re: structural models for time series

Unread post by mcorozcos »

Hello Tom,

Thanks for your help.

Can you help me with a example: how do I use the instruction @LocalDLM(options) and @SeasonalDLM(options)? because I need to fit the next model:

yt = μt+st + εt,
μt = random walk
st = summation of h=1 until h=[s/2] of zt(h)*γt(h)

Where,
Zt(h) = (IN ⊗ zt(h)') , zt(h) = (cos λ(h)t, sin λ(h)t)0 for h < s/2 and, when s is even, zt(s/2) = cos λ(s/2)t = cos πt.
yt is a random walk, like that, γt(h) = γt−1(h) + ηt(h), h= 1, ..., [s/2],
nt is a white noise, like that, ηt(h) ∼ IID (0, Σ η(h)), h= 1, ..., [s/2],
εt ∼ IID (0, Σ ε) white noise
yt = are series of data reals, monthly or quarterly

I think that with it instruction, is posible fit the model a set of data. Because I revised the components of instruction its has the elements the model that I write above. But I don´t understand how do I use those instruction in a model fit, with the instruction dlm.

I hope you can help me

Regards
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: structural models for time series

Unread post by TomDoan »

Your model has a non-standard treatment of seasonality. I have no idea what reasonable values are. What did the authors of the article tell you? It's their model.
mcorozcos
Posts: 23
Joined: Wed Feb 08, 2012 10:04 am

Re: structural models for time series

Unread post by mcorozcos »

Hello Tom,

Yes, I understand that the seasonal component its different for this reason, I need to help. But, you doesn´t matter. Don´t worry. Thanks

Now, you can help with any example about how used the instruction: @localdlm and @seasonaldlm, in the instruction dlm, for two series, the idea is to estimate the parametres of trend component, seasonal component and irregular component,(yt =ut + st + et), and I need the residuals or errors of model. I need to extract each comun components for the two series.

I read the manual for those instructions, but only have example, for one series, I can see that in this example is posible to do things that I need to do for two series.

I hope you can help me

Regards
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: structural models for time series

Unread post by TomDoan »

There are quite a few examples of @seasonaldlm in various textbook examples. See the list at

http://www.estima.com/cgi-bin/bookbrows ... xtbook=Any
Post Reply