Updated March 1, 2012 to use most recent version of MSVARSETUP.SRC
The following are the RATS program and data file for (somewhat) replicating the time-varying Hamilton-type switching model from Filardo(1994), "Business Cycle Phases and Their Transitional Dynamics", JBES, vol 12, no 3, 299-308. This requires the new MSVARSETUP.SRC procedure from http://www.estima.com/forum/viewtopic.php?f=7&t=512. We're fairly sure this does the estimation correctly given the data used. The paper, unfortunately, is rather vague on a few data preparation steps, and has some rather blatant errors in table 1 (the p-values don't match the AIC/SC).
This includes code for both EM and ML estimation. (It does EM for a certain number of iterations, then switches to maximum likelihood to get final estimates including standard errors). Maximum likelihood is not precisely defined for models with time-varying transition probabilties, since there is no unique ergodic solution for the pre-sample probabilities. This uses the probabilities with zero values for the explanatory variables to compute those. Because of this, the EM and ML use a different calculation for the likelihood, so "converged" EM estimates won't immediately give the same results in ML.
