*! version 1.0.1 21aug2026

Title

gvar foreign -- build the foreign-specific variables

Syntax

gvar foreign [, options]

options

generate write the foreign variables into the dataset.

prefix(name) prefix for the generated names.

suffix(name) suffix for the generated names. Default _star.

replace overwrite existing variables.

list list each unit's foreign block.

nosummary suppress the report.

Description

gvar foreign constructs x*_it = W_i x_t, the weighted average of
the other units' variables that each country model treats as weakly
exogenous. It runs after gvar weights and before
gvar estimate.

The summary reports the modal specification and then every unit that departs
from it. That is usually a short list and is the quickest way to see whether
the model is specified as intended.

Options

generate writes the foreign-specific series into the dataset as new
variables, rather than keeping them only inside the model. Useful when you want
to plot y* against y, or feed a star variable to some other command.

prefix(name) and suffix(name) name those variables. Without either,
the default naming is used; give one or the other when the default would collide
with something already in the data. Only one is needed -- a prefix or a
suffix -- and supplying both is allowed but usually makes the names unwieldy.

replace overwrites existing variables of the same name. Without it a
collision is an error, which is the safer default: a silently overwritten
y_star from a previous specification is very hard to notice later.

list prints the weight vector actually used for each unit. Read it once
per new dataset. It is the cheapest way to catch a weight matrix that is
transposed, mis-scaled, or missing a country -- all of which produce star
variables that look plausible and are wrong.

nosummary suppresses the report.

Remarks

A foreign variable is built only over the units that own the matching domestic
variable, with the weights renormalised over those units. A weakly exogenous
global variable, owned by no unit, gets an unweighted indicator row
instead of a weighted average.

Blanks downstream start here. If a unit has no long rate it has no
lr and no lr* entry in any later table. In the shipped demo fourteen
units have a short domestic block and the United States, as numeraire, carries
no exchange rate and only three foreign variables. Those are specification
facts; gvar describe, varlist lists them explicitly.

What the foreign variables are for. Including them is what soaks up the
cross-section dependence that would otherwise invalidate the country-by-country
estimation. gvar avgcorr measures whether it worked: in
the demo the average pairwise correlation falls from 0.6514 in the levels to
0.0484 in the residuals.

Examples

. gvar foreign
. gvar foreign, generate suffix(_star)
. gvar foreign, list

Stored results

gvar foreign stores the following in r():

r(N) units

r(K) endogenous variables

r(T) periods

Source

Toolbox create_foreignvariables.m, create_linkmatrices.m.

Author

Dr Merwan Roudane

merwanroudane920@gmail.com

https://github.com/merwanroudane