## Kim and Nelson, State-space Models with Regime Switching

A forum for students and teachers using RATS in a classroom setting
TomDoan
Posts: 7538
Joined: Wed Nov 01, 2006 4:36 pm

### Kim and Nelson, State-space Models with Regime Switching

The attached zip has the examples and data files for Kim and Nelson, State-space Models with Regime Switching, 1999, MIT Press. The book demonstrates estimation of state-space models with Markov switching using both approximate maximum likelihood using the "Kim" filter and MCMC methods. In both cases, it starts with simpler models and works up, so the examples through kimnp126.rpf are for maximum likelihood and those starting with kimnp180.rpf are for MCMC.

Quite a few of these examples (switching space-space models and some of the simpler examples) are explained in much greater detail in the "Structural Breaks and Switching Models" e-course.
kim-nelson_1.zip
Zip with programs/data
mob7
Posts: 9
Joined: Tue May 03, 2011 9:40 am

### Re: Kim and Nelson, State-space Models with Regime Switching

Hi Tom, thanks for posting these examples. I have a query on the setting of initial values in KIMNP111.RPF. Specifically the phi and x0 vectors

compute phi=||1.2,-.3||
compute sigsq=%seesq
*
frml kimf = kf=KimFilter(t),log(kf)
compute x0=||5.224,2.699||

Am I right to say the phi's are AR coefficients for loggdp? I'm not sure where the x0 values are derived from.
TomDoan
Posts: 7538
Joined: Wed Nov 01, 2006 4:36 pm

### Re: Kim and Nelson, State-space Models with Regime Switching

mob7 wrote:Hi Tom, thanks for posting these examples. I have a query on the setting of initial values in KIMNP111.RPF. Specifically the phi and x0 vectors

compute phi=||1.2,-.3||
compute sigsq=%seesq
*
frml kimf = kf=KimFilter(t),log(kf)
compute x0=||5.224,2.699||

Am I right to say the phi's are AR coefficients for loggdp? I'm not sure where the x0 values are derived from.
Yes. The phi's are the AR coefficients. The x0's are taken from the book. Since the pre-sample values are estimated (that is, x0 is considered to be free parameters), those really just need to be in the right ballpark. The published results in the book actually aren't quite right---Kim cleaned up the code after the book went to press.
Tsaritsa
Posts: 2
Joined: Wed Feb 14, 2024 12:33 pm

### Re: Kim and Nelson, State-space Models with Regime Switching

Hello Mr. Doan,

I try to execute kimnp115 procudure with my own data set. However some standart errors have negative sign.Also standart errors transition probabilities are 0 all the time. What should I do for this situation?
TomDoan
Posts: 7538
Joined: Wed Nov 01, 2006 4:36 pm

### Re: Kim and Nelson, State-space Models with Regime Switching

The negative "standard deviations" aren't a problem as they get squared to produce the variance, so the sign is arbitrary.

Note that if there is no actual switching much of the model is unidentified, and you get results that make little sense. Have you done the simpler models to see whether they seem to be adequate?
Tsaritsa
Posts: 2
Joined: Wed Feb 14, 2024 12:33 pm