03 — Bring your own SAM#

Open In Colab

A social accounting matrix (SAM) is a square accounting table: rows record receipts, columns record expenditures, and each account must balance. This notebook uses the bundled Hosoe SAM so every cell is reproducible, then shows the exact call you would use for a country SAM.

%pip install -q "https://github.com/miraflor/CGE-core/releases/download/v0.8.0/cge_core-0.8.0-py3-none-any.whl"

Inspect the SAM before modelling#

import pandas as pd
from cge_core import example_data

sam_file = example_data("stdcge") / "param-sam-.csv"
sam = pd.read_csv(sam_file, index_col=0)
sam
balance = pd.DataFrame({
    "row_total": sam.sum(axis=1),
    "column_total": sam.sum(axis=0),
})
balance["row_minus_column"] = balance["row_total"] - balance["column_total"]
balance

Build the Standard CGE directly from the SAM#

For the canonical labels (CAP, LAB, HOH, GOV, INV, EXT, IDT, TRF) no extra account mapping is needed.

from cge_core import StandardCGE

economy = StandardCGE.from_sam(sam_file)
base = economy.solve()
base.summary()

Country-specific account labels#

State the economic roles explicitly. CGE-Core deliberately does not guess that ROW, EXT, WORLD, or another spelling means the rest of the world.

# Example template — replace the file and labels with your own SAM.
# economy = StandardCGE.from_sam(
#     "country_sam.csv",
#     factors=["LAB", "CAP"],
#     household="HH",
#     government="GOVT",
#     investment="SAVINV",
#     rest_of_world="ROW",
#     indirect_tax="PTAX",
#     tariff="TARIFF",
# )

A balanced table is necessary but not sufficient: the benchmark flows must also satisfy the economic structure and calibration assumptions of the Hosoe Standard model.