jmaih / RISE_toolbox

Solution and estimation of Markov Switching Rational Expectations / DSGE Models
BSD 3-Clause "New" or "Revised" License
103 stars 77 forks source link

Backing out data series from an estimated model #23

Closed aaronsun87 closed 8 years ago

aaronsun87 commented 8 years ago

Hi Junior,

Is there a function in your RISE toolbox that is similar to Dynare simult(y0,dr,ex,iorder) so that users can back out data from smoothed shocks and regime probabilities?

Thanks, Aaron

jmaih commented 8 years ago

Hi Aaron, The function you are describing takes as inputs some initial condition (y0), the model environment (dr), some shock data (ex_) and the order of approximation (iorder). The function is then expected to return some forecast/projection/simulation whose length is potentially the length of the shocks.

This is a simple exercise, which is best implemented in RISE as a conditional forecast. But the setup is more involved with a regime switching model since the information on the regimes is also relevant and in general we never know with certainty the history of the regimes. But for a given sequence of regimes, you can do a conditional forecast as well.

Cheers,

Junior

aaronsun87 commented 8 years ago

Hi Junior,

Thanks for your reply. The shock data (ex_) in Dynaresimult(y0,dr,ex_,iorder) is provided by users (an output of the estimation). However what you suggest, as I understand, is to draw random shocks and then do a conditional forecast based on them. How can this guarantee the forecasts match the data precisely?

Do you by any chance have an example to share?

Thank you very much for your help.

Regards, Aaron

On Tue, Aug 16, 2016 at 2:54 AM, Junior Maih notifications@github.com wrote:

Hi Aaron, The function you are describing takes as inputs some initial condition (y0), the model environment (dr), some shock data (ex_) and the order of approximation (iorder). The function is then expected to return some forecast/projection/simulation whose length is potentially the length of the shocks.

This is a simple exercise, which is best implemented in RISE as a conditional forecast. But the setup is more involved with a regime switching model since the information on the regimes is also relevant and in general we never know with certainty the history of the regimes. But for a given sequence of regimes, you can do a conditional forecast as well.

Cheers,

Junior

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jmaih/RISE_toolbox/issues/23#issuecomment-240043100, or mute the thread https://github.com/notifications/unsubscribe-auth/AOo-EaYydOXHVmI-fh6X7gqBRwOPhEbxks5qgXrVgaJpZM4Jkmoc .

jmaih commented 8 years ago

Hi Aaron,

The shock data cannot be provided by the user and be an output of estimation. It is one or the other, not both at the same time.

I did not suggest drawing random shocks. I was just drawing your attention to the fact that the exercise you are talking about is a conditional forecasting exercise. You condition on the model, on initial conditions, on shocks and on the order of approximation.

There is nothing in what I have just written that refers to estimation or to smoothing. Strictly speaking, all those three things (estimation, smoothing and simulating/forecasting) are independent from one another. At least that is the way RISE implements them. i.e. you don't need to estimate a model before simulating or filtering it.

When it comes to simulation, RISE implements very complex forms of simulations, allowing the user to condition, not only on shocks, but also on future values of endogenous variables and on the regimes. The events can be anticipated or unanticipated, the conditional information can come in the form of density, etc.

Unfortunately I am overstretched right now. I will try and add an example for doing simple forecasting/simulation to the toolbox over the weekend.

Cheers,

Junior

aaronsun87 commented 8 years ago

Hi Junior,

Thank you for your reply. I followed what you did in the Ireland (JMCB, 2011) example and I successfully backed out data from smoothed shocks for a non-switching model. But when I tried to do the same for a regime-switching model, this didn't work and it reported an error "sub-variables are not expected to have names when using collect." I guess the reason is that sub-variables have names like "regime_1" and "regime_2" in regime-switching models. It would be highly appreciated if you could make an example to show how this works under a regime-switching scenario.

Thank you very much, Aaron

%% Counterfactuals clc close all db=mest.filtering.smoothed_variables; dbshocks=mest.filtering.smoothed_shocks; db=pages2struct(ts.collect(db,dbshocks)); for irecess=1:numel(recessions) recess=recessions{irecess}; serials=date2serial(recess); serials=serials(1):serials(2); nsteps=numel(serials)-1; figure('name',['Counterfactual output paths for ',recess,' recession']) for ishock=1:nshocks shock=mest.exogenous.name{ishock}; fkst=forecast(mest,'data',pageify(serials(2)-1,db),... 'forecast_start_date',serials(2),... 'forecast_cond_exo_vars',shock,... 'forecast_nsteps',nsteps); subplot(2,2,ishock) toplot=[db.GHAT+log(pest.zss),fkst.GHAT+log(pest.zss)]; toplot=cumsum(toplot(recess)); benchmark=double(toplot); benchmark=max(benchmark(:));

plot(toplot,'linewidth',2)%plot((toplot-benchmark)/benchmark,'linewidth',2) title(mest.exogenous.tex_name{ishock}) if ishock==1 legend({'actual','forecast'}) end end end

On Wed, Aug 17, 2016 at 9:08 AM, Junior Maih notifications@github.com wrote:

Hi Aaron,

The shock data cannot be provided by the user and be an output of estimation. It is one or the other, not both at the same time.

I did not suggest drawing random shocks. I was just drawing your attention to the fact that the exercise you are talking about is a conditional forecasting exercise. You condition on the model, on initial conditions, on shocks and on the order of approximation.

There is nothing in what I have just written that refers to estimation or to smoothing. Strictly speaking, all those three things (estimation, smoothing and simulating/forecasting) are independent from one another. At least that is the way RISE implements them. i.e. you don't need to estimate a model before simulating or filtering it.

When it comes to simulation, RISE implements very complex forms of simulations, allowing the user to condition, not only on shocks, but also on future values of endogenous variables and on the regimes. The events can be anticipated or unanticipated, the conditional information can come in the form of density, etc.

Unfortunately I am overstretched right now. I will try and add an example for doing simple forecasting/simulation to the toolbox over the weekend.

Cheers,

Junior

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jmaih/RISE_toolbox/issues/23#issuecomment-240442325, or mute the thread https://github.com/notifications/unsubscribe-auth/AOo-EXGfICONg9I_GuvFKT8XJREgAXDOks5qgyPngaJpZM4Jkmoc .

jmaih commented 8 years ago

Hi Aaron,

There is a simpler way of doing what you would like to do i.e. a historical decomposition to see the contribution of a particular shock to a the evolution of one variable.

I modified the Ireland(2011,JMCB) model to include switches in the volatility of the shocks as well as in the coefficients of the monetary policy reaction function. I use a calibration (essentially a slight modification of the estimated parameters in the paper) to run the decomposition exercise. As you will see, there is no need to estimate the model first if one already has the parameters (and of course the data).

The new model file is called "nkp_switch.rs" and the driver to run the example is called "master_switch.m". Update RISE from github to get hold of the example, which is located in the same folder as the original model.

As I said earlier in a previous post, this decomposition exercise is fragile in the sense that the decomposition is not exact in the presence of regime switching, which makes the problem nonlinear. This is, however, the easiest way to achieve what you have in mind.

The alternative is to go through the forecast route as it is done the constant-parameter version of the paper. The problem here is that you will have to deal with multiple series for the shocks as well as the regimes for which all you have are probabilities.

If what you want to do is really forecasting, then the constant-parameter version already offers a simple example,

Cheers,

Junior

aaronsun87 commented 8 years ago

Hi Junior,

Thank you so much for your time. Let me explain my goal more explicitly. Just focus on the the Ireland model with two monetary policy regimes and two volatility regimes. People usually find that monetary policy was passive before 1980 and became active since then. What I really want to do is the counterfactual analysis on what would have happened, given the estimated smoothed shocks, if monetary policy did not become active but stayed passive. I wanted to go through the forecast route because this kind of counterfactual analysis can be simply done, I think, by forecasting based on smoothed shocks and modified smoothed regime probabilities. When I tried the forecast route on a regime-switching model, I got the error "sub-variables are not expected to have names when using collect" which would not show up on the constant-parameter version. May you please advise me how to get around this error? I greatly appreciate your help.

Thank you, Aaron

On Sun, Aug 21, 2016 at 10:19 AM, Junior Maih notifications@github.com wrote:

Hi Aaron,

There is a simpler way of doing what you would like to do i.e. a historical decomposition to see the contribution of a particular shock to a the evolution of one variable.

I modified the Ireland(2011,JMCB) model to include switches in the volatility of the shocks as well as in the coefficients of the monetary policy reaction function. I use a calibration (essentially a slight modification of the estimated parameters in the paper) to run the decomposition exercise. As you will see, there is no need to estimate the model first if one already has the parameters (and of course the data).

The new model file is called "nkp_switch.rs" and the driver to run the example is called "master_switch.m".

As I said earlier in a previous post, this decomposition exercise is fragile in the sense that the decomposition is not exact in the presence of regime switching, which makes the problem nonlinear. This is, however, the easiest way to achieve what you have in mind.

The alternative is to go through the forecast route as it is done the constant-parameter version of the paper. The problem here is that you will have to deal with multiple series for the shocks as well as the regimes for which all you have are probabilities.

If what you want to do is really forecasting, then the constant-parameter version already offers a simple example,

Cheers,

Junior

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jmaih/RISE_toolbox/issues/23#issuecomment-241266685, or mute the thread https://github.com/notifications/unsubscribe-auth/AOo-EUPhp0M9cOgZlLjO9Uuo5-QXduS3ks5qiHp1gaJpZM4Jkmoc .

jmaih commented 8 years ago

Hi Aaron,

There often many ways to do the same thing in RISE and it does take some understanding of the toolbox to figure out how to adapt the examples to a different or slightly different problem. The starting point is to know what you are looking for, which I now understand a bit better.

The difficulty arises from the fact that in the regime switching case, RISE produces a time series for each of the regimes. And so in the case of smoothed shocks you have multiple series as well. In order to do forecasting or even better conditional forecasting (you are conditioning on the shocks and on the passive regime) you will have to use one series for the shocks. The question is which one? There is an additional field that store shocks after filtering and is called "Expected_smoothed_shocks" and in there you have a weighted average of the estimated shocks. These series do not have sub-names and would therefore not produce the type of error you encountered. If you want to use the other shocks in some way or another, you will have to use time series manipulations to pick the one you want to use and discard the names.

When it comes to forecasting itself, just type help help dsge/forecast

Cheers,

Junior