Hello,

I have a question that is quite similar to this one.

Just like the author of that post, I use Dynare to construct the statespace of the model, and to estimate it. After doing that, I’d like to be able to, in a `.m`

file or the Matlab console, extract the smoothed & updated states from the Kalman filtering process when the model is defined by an arbitrary parameter vector.

My ideal `.m`

file would look something like this:

```
addpath C:\dynare\6.1\matlab;
dynare_config; % makes `dseries` objects interpretable
load {MOD_FILENAME}_results.mat;
N = 10; % number of times to run Kalman process
K = length(M_.state_var);
T = dseries_.nobs;
random_params = randn(N, M_.param_nbr);
random_states = zeros(T, K, N);
for i = 1:N
theta_i = random_params(i, :);
set_all_parameters(theta_i, estim_params_, M_);
random_states(:, :, i) = handy_kalman_function(dataset_, M_, obs_);
end
```

Is there a built-in Dynare function that would be able to do this?

The closest I’ve been able to get to this is:

```
addpath C:\dynare\6.1\matlab;
dynare_config; % makes `dseries` objects interpretable
load {MOD_FILENAME}_results.mat;
params = oo_.posterior_mode.parameters;
theta0 = cellfun(@(x)(params.(x)), fieldnames(params));
nobs = dataset_.nobs;
Y = transpose(dataset_.data);
aindex = dataset_info.missing.aindex;
state = dataset_info.missing.state;
DsgeSmoother(theta0, nobs, Y, aindex, state, M_, oo_, options_, bayestopt_, estim_params_, dataset_, dataset_info);
```

However, this throws an error in the `stochastic_solvers`

function. The full error message is in the attached file.

error_trace.txt (990 Bytes)

Thank you to anyone who might be able to help. Best,

Logan