write_dynare: Export a model to a Dynare .mod file

View source: R/dynare.R

write_dynareR Documentation

Export a model to a Dynare .mod file

Description

Writes the model as Dynare source so that anyone can re-solve it in Dynare and compare. This is deliberate: qpmR's solver is pinned in its own tests to analytic solutions, but "does it agree with Dynare?" is the first question a modeller asks, and the answer should be cheap to check rather than something to take on trust.

Usage

write_dynare(model, file = NULL, irf = 40, order = 1, extra = NULL)

Arguments

model

A qpm_model.

file

Output path. The default NULL returns the Dynare source as a character vector; a file is written only when a path is given.

irf

Horizon for stoch_simul; 0 omits impulse responses.

order

Approximation order passed to stoch_simul (the models are linear, so first order is exact).

extra

Character vector of extra Dynare statements appended after stoch_simul, e.g. code to export results.

Details

The original equations are exported, not qpmR's internal first-order system: Dynare creates its own auxiliary variables for long leads and lags, so the two implementations agree only if both handle them correctly. Expectation wrappers are dropped (E(pi[+1]) becomes pi(+1)), since leads in Dynare are already model-consistent expectations.

Value

The file path invisibly, or the Dynare source as a character vector when file is NULL.

Examples

src <- write_dynare(qpm_template("bkl"), file = NULL)
cat(head(src, 15), sep = "\n")

qpmR documentation built on Sept. 29, 2026, 5:10 p.m.