BookmarkSubscribeRSS Feed
Fluorite | Level 6

Hello, I have been working on US recession turning point analysis using LEI data, and I have run into a bit of a snag. One of the models I am working with is a Markov Switching model, seen here: (I believe this is the most famous example of how to do this in SAS by far)

However this code only estimates the parameters of the equation in each state, as well as a series of tests to see if the parameters are significantly different between states. What I am looking for out of this model is a monthly time series output (I'm using monthly time series data) of which state it believes is active in a given month, so basically a series of regime/state probabilities. Is there any way to get this working in SAS?

SAS Employee

Using the switching regression example in the PROC MODEL chapter you could output the predicted regime probabilities by using the following FIT and OUTVARS statemnt in place of the FIT statement in the example:

   fit starts / method=marquardt converge=1.0e-5 out=o;
   outvars d;

The values of 'd' written to the ouput data set represent the predicted probabiltiy each observation is in regime 2. 

Fluorite | Level 6

Thanks, that worked perfectly. However, it brought another issue to my attention that I'm not sure how to solve.

For this Markov Switching model, I'm using LEI to predict whether or not the economy is in a recession, using the binary indicator provided by the NBER as a point of reference. Following the example I linked to, I ended up using the binary recession indicator to construct 'd'. But this is obviously an issue since my goal is to predict the state variable endogenously, rather than figure out the parameters in different states.If I am using the NBER indicator in my markov chain, which is the thing I'm trying to predict, then I'm not actually doing anything.

Would you know how I could set up this model in SAS to predict the state variable, ONLY using %change in the LEI (without referencing the NBER indicator?).

For reference, here is my code (mostly taken wholesale from the example):


proc model data=revisedLEI_and_nber;
	parms sig1=10 sig2=10 int1 int2;
	bounds 0.0001 < sig1 sig2;
	a = NBER_binary; 
	d = probnorm(a);
	rtchglei = (1 - d)*y1 + d*y2;
	logL = ((1/2)*( (log(2*3.1415)) +
log( (sig1**2)*((1-d)**2)+(sig2**2)*(d**2) )
+ (resid.rtchglei*( 1/( (sig1**2)*((1-d)**2)+(sig2**2)*(d**2) ) )*resid.rtchglei) ) );

	errormodel rtchglei ~ general(logL);
	fit rtchglei / method=marquardt converge=1.0e-5 out=o;
	outvar d;



SAS Employee
If I understand your question correctly you would just need to model 'a' using one or more parameters that are also estimated. In the original PROC MODEL example 'p' plays the role of this parameter.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 2 in conversation