|
| 1 | +# Using Your Own SAM |
| 2 | + |
| 3 | +This page explains how to load a custom Social Accounting Matrix (SAM) with an |
| 4 | +arbitrary number of products (goods) and production factors. |
| 5 | + |
| 6 | +## What the loader expects |
| 7 | + |
| 8 | +The CSV file must include a header row with column labels and a first column |
| 9 | +with row labels. The loader uses these labels to index the SAM: |
| 10 | + |
| 11 | +- `goods` and `factors` are not inferred from the CSV. You must pass them in |
| 12 | + `load_sam_table(...; goods=..., factors=...)`. |
| 13 | +- The CSV must include rows and columns for all `goods`, `factors`, and the |
| 14 | + special sectors listed below. |
| 15 | + |
| 16 | +Required sector labels (defaults shown): |
| 17 | + |
| 18 | +- `indirectTax_label` = `IDT` |
| 19 | +- `tariff_label` = `TRF` |
| 20 | +- `households_label` = `HOH` |
| 21 | +- `government_label` = `GOV` |
| 22 | +- `investment_label` = `INV` |
| 23 | +- `restOfTheWorld_label` = `EXT` |
| 24 | +- `numeraire_factor_label` = `LAB` (must be one of the factor labels) |
| 25 | + |
| 26 | +If your CSV uses different labels, pass them as keyword arguments to |
| 27 | +`load_sam_table`. |
| 28 | + |
| 29 | +## Minimal structure example |
| 30 | + |
| 31 | +The table must be square and include all the labels you reference. This |
| 32 | +illustrative header shows the kind of layout expected: |
| 33 | + |
| 34 | +```text |
| 35 | +Column1,BRD,MLK,CAP,LAB,IDT,TRF,HOH,GOV,INV,EXT |
| 36 | +BRD, ... |
| 37 | +MLK, ... |
| 38 | +CAP, ... |
| 39 | +LAB, ... |
| 40 | +IDT, ... |
| 41 | +TRF, ... |
| 42 | +HOH, ... |
| 43 | +GOV, ... |
| 44 | +INV, ... |
| 45 | +EXT, ... |
| 46 | +``` |
| 47 | + |
| 48 | +## Loading a custom SAM |
| 49 | + |
| 50 | +```julia |
| 51 | +using StandardCGE |
| 52 | + |
| 53 | +goods = ["A", "B", "C"] |
| 54 | +factors = ["LAB", "CAP", "LAND"] |
| 55 | + |
| 56 | +sam = load_sam_table( |
| 57 | + "path/to/your_sam.csv"; |
| 58 | + goods = goods, |
| 59 | + factors = factors, |
| 60 | + numeraire_factor_label = "LAB", |
| 61 | + indirectTax_label = "IDT", |
| 62 | + tariff_label = "TRF", |
| 63 | + households_label = "HOH", |
| 64 | + government_label = "GOV", |
| 65 | + investment_label = "INV", |
| 66 | + restOfTheWorld_label = "EXT", |
| 67 | +) |
| 68 | + |
| 69 | +model, start, params = solve_model(sam) |
| 70 | +``` |
| 71 | + |
| 72 | +## Common pitfalls |
| 73 | + |
| 74 | +- The SAM must be square and include all labels used in `goods`, `factors`, and |
| 75 | + the special sector labels. |
| 76 | +- The `numeraire_factor_label` must match one of the factor labels. |
| 77 | +- Missing values are replaced by `0`, but missing rows or columns will cause |
| 78 | + indexing errors. |
| 79 | + |
| 80 | +## Tips for larger SAMs |
| 81 | + |
| 82 | +- Keep goods and factors ordered consistently between the CSV and your lists. |
| 83 | +- Start by running `compute_starting_values(sam)` and `compute_calibration_params(sam, start)` |
| 84 | + to catch data issues before solving. |
0 commit comments