%% Simulate US GDP Rates and Economic States
% Consider a two-state Markov-switching dynamic regression model of the postwar US real GDP growth rate. The model has the parameter estimates presented in docid:econ_ug.mw_dbb8f03a-99f5-4b93-83b9-59ca36c84c73.
% Create a discrete-time Markov chain model that describes the regime switching mechanism. Label the regimes.

P = [0.92 0.08; 0.26 0.74];
mc = dtmc(P,'StateNames',["Expansion" "Recession"]);

% Create separate AR(0) models (constant only) for the two regimes.

sigma = 3.34; % Homoscedastic models across states
mdl1 = arima('Constant',4.62,'Variance',sigma^2);
mdl2 = arima('Constant',-0.48,'Variance',sigma^2);
mdl = [mdl1 mdl2];

% Create the Markov-switching dynamic regression model that describes the behavior of the US GDP growth rate.

Mdl = msVAR(mc,mdl);

% Mdl is a fully specified msVAR object.
% Generate one random path of 100 responses, corresponding innovations, and states from the model.

rng(1) % For reproducibility
[y,e,sp] = simulate(Mdl,100);

% y is a 100-by-1 vector of GDP rates, and e is a 100-by-1 vector of corresponding innovations. sp is a 100-by-1 vector of state indices.
% Copyright 2019 The MathWorks, Inc.
%
%
%