*! version 1.0.1 21aug2026

Title

gvar save -- write the fitted GVAR to disk

Syntax

gvar save filename [, replace nosummary]

options

replace overwrite filename if it exists.

nosummary suppress the confirmation line.

If filename has no suffix, .gvar is added.

Description

gvar save writes everything the package holds about the current model to
a single file: the panel it was built from, the weight matrices, every
country-model estimate, the residuals, the stacked system and the reduced
form. gvar use reads it back.

The point is that estimating, solving and bootstrapping a model of realistic
size takes minutes. Do it once, save, and every later session starts from the
solved model.

Options

filename is required. The extension .gvar is added if none is given.

replace overwrites an existing file. Without it, an existing file is an
error rather than being silently replaced -- a saved model represents a
specification that took work to arrive at.

nosummary suppresses the report.

What is saved is the model, not the data: the specification, the weights, the
estimates and whatever has been solved. Reload it with
gvar use. The dataset is not stored with it, so keep the two
together if any command you plan to run afterwards writes variables back.

Remarks

The file is self-contained. It carries its own copies of the data, so
after gvar use you can run gvar irf,
gvar fevd, gvar spillover and the
rest with no dataset in memory at all. Nothing in the dynamic analysis
reads the panel; it all reads the stored model. The exception is
gvar setup itself, which starts a new model rather than
using a saved one.

Save at whatever stage you have reached. A model that is set up but not
estimated saves and restores just as well as a solved one;
gvar use reports which stage it found and tells you what to run next.

Version. The file is a serialised Mata structure, so it can only be read
by a version of the package whose structure definition matches. If the package
is upgraded in a way that changes the structure, gvar use refuses with a
clear message rather than restoring something half-formed, and you re-estimate
and save again. For long-lived work keep the do-file that built the model, not
only the .gvar file.

Size. The dominant term is the residual matrix and the stacked system, so
the file grows roughly with K^2. The 26-unit demo model is a few
megabytes.

Examples

Fit once

. use gvar_demo26, clear
. gvar setup y Dp eq ep r lr, unit(country) time(quarter) global(poil pmat pmetal) gendog(poil=usa pmat=usa pmetal=usa) spec(gvar_demospec.dta)
. gvar weights using gvar_flows.dta, flow(trade) source(partner) destination(home) year(year) years(2009 2011) type(1) map(gvar_demoagg.dta)
. gvar foreign
. gvar estimate
. gvar solve
. gvar save demo_fitted, replace

Analyse later, with no data in memory

. clear all
. gvar use demo_fitted
. gvar irf, shock(usa:r) response(*:y) step(24) reps(200) shuffle

Stored results

gvar save stores the following in r():

r(filename) the file written

Source

Utility command. There is no counterpart in the reference implementations:
GVAR Toolbox 2.0 persists its state in the MATLAB workspace, and the R
packages in the returned object.

Author

Dr Merwan Roudane

merwanroudane920@gmail.com

https://github.com/merwanroudane