R/model_commons.R
check_world_trade_balance.RdIn every shipped model, world exports equal world imports, so the solved trade balances of all countries must sum to zero. The trade balance rule sets the world sum of `trade_balance_new`: `"fixed"` keeps the baseline sum, `"fixed_global_share"` scales it with world value added, `"zero"` sets it to zero, and `"fixed_country_share"` gives each country's baseline share of its own value added. When this world sum is not zero, the rule cannot hold for the world: labour markets do not clear and the fixed point that the solver reaches depends on `vfactor`. This happens with `"fixed_country_share"` after a shock that does not move value added proportionally in every country, and under every rule except `"zero"` when the baseline trade balances do not sum to zero.
The check passes when the absolute world sum is at most `tolerance` times world value added. It also refuses a solution with non-finite trade balances or with value added that is not positive.
check_world_trade_balance(
trade_balance,
trade_balance_new,
value_added,
value_added_new = NULL,
trade_balance_rule = "fixed",
tolerance = 1e-06
)Vector of baseline trade balances, dimension: country.
Vector of solved trade balances, dimension: country. Each of the four inputs may also be a long table with a `value` column.
Vector of baseline value added, dimension: country.
Vector of solved value added, dimension: country, or NULL when the model does not return it.
Character string, the trade balance rule.
Tolerance relative to world value added.
List with `ok` (TRUE, FALSE, or NA when the model returns no `trade_balance_new`), `rule`, `world_trade_balance`, `baseline_world_trade_balance`, `world_value_added`, `tolerance` and `reason`.