================================================================================
  input_data/  —  MODEL INPUTS for Denmark        (netRecon reconstruction pipeline)
================================================================================
  Generated 2026-06-27 by make_consistent_dataset.py.  DERIVED from ../raw_data/ —
  do not hand-edit; regenerate (see bottom).

WHAT IS IN THIS FOLDER
----------------------
These are the files the reconstruction model actually reads:

  census.npz            firm-level census with SCALED sizes  m'_i  (inter-firm sizes)
  sector_io_table.csv   the balanced inter-firm flow matrix  F*  (sector x sector)
  input_files/IOT1.xlsx F* in the stage-1 input format (rows = sellers, cols = buyers)
  flow_target_F.txt     F* as a dense matrix — the stage-2 dollar-flow target (`mew`)
  lambda.npz            fitted sector-pair link intensities (a DERIVED artifact; re-fit
                        whenever the inputs or the model change)
  meta.json / recon_config.json   sector labels, firm count, alpha, provenance

  ../raw_data/ holds the ORIGINALS this was built from:
    census.npz          firm census with TOTAL receipts per firm (unscaled)
    sector_io_table.csv / input_files   the raw national IO table (intermediate-only,
                        column-normalised input mix), as collected.

WHY WE ADJUST THE RAW DATA
--------------------------
The reconstruction is a CLOSED inter-firm economy: every firm respends all of its
revenue on inputs from other firms (m_{t+1} = W^T m_t), so a firm's network "size"
m_i is at once its inter-firm SALES and its inter-firm PURCHASES.  The two raw
sources disagree about sector magnitudes and cannot both hold under that closure:

  * the firm census (receipts) counts TOTAL sales, INCLUDING sales to FINAL DEMAND
    — households (PCE), investment, government, exports;
  * the IO table is INTERMEDIATE-ONLY (final demand already stripped).

So consumer-facing sectors (retail, health, accommodation, ...) carry huge census
receipts but little inter-firm flow, and a few sectors invert.  Left unadjusted the
census sector totals and the IO column totals differ by ~40%, and no weighting can
make realised dollar flow match the IO.  The adjustment strips final demand out of
the firm sizes and rebalances the IO so the two are mutually consistent.

HOW input_data IS DERIVED FROM raw_data   (make_consistent_dataset.py)
----------------------------------------------------------------------
 (A) inter-firm share  phi_l  per sector  ( = 1 - final-demand share ), from
     interfirm_shares_nace.csv
       [ NACE-section final-demand shares (Eurostat/OECD supply-use) ].
 (B) rescale every firm to its inter-firm magnitude:
         m'_i = size_i * phi_{sector(i)}
     (uniform within a sector, so the within-sector Pareto tail is preserved).
     New sector totals  M_l = sum_{i in l} m'_i.
 (C) balance the IO into a flow target F*: RAS / iterative-proportional-fit the IO
     input-mix (the real who-buys-from-whom structure) onto EQUAL row = col margins M
     (closure: each sector's inter-firm sales = its inter-firm purchases).  F* keeps
     the IO pattern but forces the totals to the firm-size margins, so the stage-1
     network structure and the stage-2 dollar flow become a feasible matched-margin fit.

THIS COUNTRY (Denmark)
--------------------
  sectors ............ 19
  firms .............. 363,487
  total receipts ..... 3.613e+11     (../raw_data, sum of firm sizes)
  inter-firm total ... 1.691e+11     (this folder, sum of m'_i)
  retained ........... 46.8%  of receipts are inter-firm; the remaining
                       53.2% was sales to final demand, removed by phi.
  phi source ......... interfirm_shares_nace.csv

REGENERATE
----------
  cd code_generation
  ./.venv/bin/python make_consistent_dataset.py Denmark --phi interfirm_shares_nace.csv
      (reads ../raw_data, writes here)
  ./.venv/bin/python estimate_alpha.py Denmark_interfirm
      (re-fit lambda.npz on the new inputs)

See make_consistent_dataset.py (module docstring) and recon_bundle.py for the full
bundle contract.
