Keep a selected subset of regions explicit while treating the remaining regions as exogenous imports and exports. This generalizes Database.to_single_region(...) to the case where more than one region must remain endogenous.

See Extract a region or subset for sector, commodity and producer import classifications, source-region detail and the native accounting blocks.

Database.to_region_subset(
regions,
inplace=True,
trade_resolution='aggregate',
externalized_trade_layout='legacy',
*,
imports_by=None,
import_representation='factor-accounts',
trade_mode=None,
)#

Keep one explicit region subset and externalize the remaining regions.

Parameters:
  • regions – One region label or an iterable of region labels to keep explicit.

  • inplace – When True, mutate the current database. When False, return a transformed copy.

  • trade_resolution – "aggregate" sums the excluded source regions within each requested import classification. "by_region" retains source regions as an explicit row dimension and separates export partners. "by_sector" is shorthand for sectorized imports plus one aggregate export column per selected region. "by_region_and_sector" is shorthand for sectorized imports and exports with one explicit excluded-region partner label.

  • externalized_trade_layout – "legacy" keeps separate intermediate/final-demand export categories. "sectorized" uses one Export column per selected region and defaults to sector import classification on IOTs or commodity classification on SUTs. IOT productive axes use explicit Region/Sector labels; SUT productive axes stay native.

  • imports_by – IOTs accept "sector". SUTs accept "commodity" or "activity". "commodity" keeps one account per commodity; "activity" attributes imports to foreign producing activities using their shares in the source supply matrix. None retains aggregate import accounts, or selects the table’s productive set when the layout is "sectorized". Combine with trade_resolution="by_region" to retain producer/partner regions too.

  • import_representation – "factor-accounts" stores external imports with factors. "separate" creates native import blocks and requires exactly one retained region. Inspect the choices with configuration.

  • trade_mode – Compatibility alias for trade_resolution.

Returns:

Transformed database when inplace=False, otherwise None.

Return type:

Database | None

Notes

The selected regions keep their endogenous transactions with each other. All excluded regions are moved outside the endogenous system and are represented as exogenous imports and exports.

Import rows share the factor label "imports". Their Sector, Commodity, Activity and optional Region dimensions are declared as matrix layouts, so aggregate() maps them wherever they occur. Original factors retain empty levels for dimensions that do not apply. Derived factor coefficients and multipliers use the same row layout.

SUT extraction preserves native blocks and direct final-demand imports in VY. Use-side imports enter Va; supply-side imports (including Chenery-Moses trade) enter Vc. Domestic Ea, Ec and EY remain separate. Original productive and final-demand classifications are retained; export columns are appended. Activity attribution is a proportional allocation, not observed producer-to-buyer transactions. Undefined allocation at a zero-supply node raises WrongInput. IOT final-demand imports are likewise retained in VY. Extraction retains the baseline and discards other scenarios.

Examples

Keep IT and FR explicit while treating the remaining regions as exogenous trade:

subset = db.to_region_subset(["IT", "FR"], inplace=False)

Keep the same subset but preserve exogenous trade partner detail:

subset = db.to_region_subset(
    ["IT", "FR"],
    inplace=False,
    trade_resolution="by_region",
)