feat(trade): extend Trade FBS/overlay to 2018–2024; export 1:m uses Detail_Supply T007 - #730
Merged
Merged
Conversation
bl-young
marked this pull request as ready for review
August 26, 2026 21:21
WesIngwersen
self-requested a review
August 26, 2026 21:25
WesIngwersen
approved these changes
Aug 26, 2026
WesIngwersen
force-pushed
the
by_trade_time_series
branch
from
August 26, 2026 22:58
9a65243 to
4b05615
Compare
Add common + per-year Trade_Exports/Imports methods, lift MDTY/MADJ year guards, and wire F040/MCIF/MDTY/MADJ for TRADE_OVERLAY_YEARS. Attribution stays on frozen 2017 F040/MCIF.
Cache Detail_Supply_<year> in Trade_Exports stubs and collapse to commodity T007 before proportional attribution (#729). Imports stay on frozen 2017 MCIF.
WesIngwersen
force-pushed
the
by_trade_time_series
branch
from
August 26, 2026 23:12
4b05615 to
3563780
Compare
WesIngwersen
added a commit
that referenced
this pull request
Aug 27, 2026
Docs only. The plan and progress report predated #733/#734 and were describing a Supply bridge that no longer exists. Supply column table, corrected against a live coverage run rather than from memory: eight of the twelve columns now run 2017-2024, and only TRADE, TRANS and therefore T014/T016 stop at 2023. MCIF, MADJ and MDTY were still listed as "2017 candidate" and have been annual since #730. TRANS was "2017-2022" and now reaches 2023 from AIES. TOP's residual is no longer frozen, which the plan asserted in two places. The purchaser-price base did not have to wait for Step 5 as the plan predicted - it is assembled from the bridge's own components, and is not circular because TOP sits in T015 and is excluded from its own base. Recorded with what it buys (S00402's 174,312 base, the 0.939-1.008 rescale) and what it costs: TOP now depends on margin coverage, so 2024 holds 2023's shares. Step 1: F04000 was described as all-zero for 2018-2024 and has been annual since #730 (2,211bn to 3,139bn). F03000 really is still 2017-only, so the two are now stated separately instead of together. Numbers re-measured rather than edited by hand. Steps 1 and 4 re-run, and the embedded images regenerated with them: supply bridge coverage 99.0% to 99.2%, accuracy 61.8% to 62.1%, grand total error 0.092% to 0.048%. That improvement is not Step 4a - it is the Trade FBSs rebuilt on the NAICS-2022 goods Crosswalk, which moved MCIF (misses 27 to 22) and carried through T013 and T016. Per-column table updated with it. Step 3 is unchanged and was not re-run.⚠️ The 2017 trade scorecard moved in two directions at once and the README now says so rather than reporting the half that flatters it: the export national error roughly halved, +12.20% to +6.16%, while Pearson fell 0.96 to 0.92, top-20 Jaccard 0.67 to 0.60 and n_miss rose 39 to 43. The extra mass lands closer to the published total but spread over more Detail codes. The prior row is kept for comparison.⚠️ The stored per-commodity trade baseline was deliberately NOT refreshed. score_2017_trade_detail flags a handful of expected status changes against it; --update-baseline is a judgement call and has not been made. Step 2's plan entries are not touched here - they belong to #735. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cc:
Closes: #727
Related: #729
What changed? Why?
Nowcast years 2018-2024 use the same Trade FBS + overlay path as 2017. Extract YAMLs already declare
Census_USATrade/BEA_IEAthrough 2024; methods, MDTY/MADJ helpers, and nowcast gates were 2017-only.Export 1:m Crosswalk splits use same-year domestic commodity output
T007: eachTrade_Exports_<year>cachesDetail_Supply_<year>and runstrade.attribution.collapse_detail_supply_to_t007before proportional attribution (#729). Imports stay on frozen 2017 SupplyMCIF.Methods
Trade_Exports_common.yaml/Trade_Imports_common.yamlhold shared bodies; thinTrade_{Exports,Imports}_{2017..2024}.yamlstubs setyear.Detail_Supply_<year>withclean_fbs: collapse_detail_supply_to_t007and use that cache key asattribution_source.FlowName, IEA Crosswalk, attribution column).Helpers + nowcast wire
mdty_detail_usd/madj_detail_usdwork for every overlay year (noyear != 2017guard).MADJ; later years ->’ that year's mappedGEN_CHA_YRmagnitude with the published SupplyMADJsign. Destination shares stay frozen 2017 SupplyMADJ.TRADE_OVERLAY_YEARS = range(2017, 2025)ineeio/nowcast.pyforF04000/MCIF/MDTY/MADJ. Inventories stay 2017-only.S00900/F04000identity keeps frozen 2017 SupplyT016[S00900]for every trade-overlay year.bedrock/transform/trade/README.mddocuments the multi-year layout and attribution rule.score_2017_trade_detail_baseline.csvis advanced for T007 export-attribution leaf moves (49 commodities; no Crosswalk change).GCS extract inputs (staged; not in git)
Raw Census / IEA dumps for 2018-2024 are on
gs://cornerstone-default/extract/input-data/:Census_USATrade/{2018..2024}/Census_USATrade_<year>_{exports,imports}.csvBEA_IEA/{2018..2024}/BEA_IEA_<year>_{Exports,Imports}.csvDetail_Supply_{2018..2024}FBS parquets live undergs://cornerstone-default/transform/output_data/(notflowsa/FlowBySector/-> download locally before generate). Withextract_data_from_raw_sources: False, FBA generation loads Census/IEA viagcs_fxnwithout API keys.Outstanding: Census NAICS 2022+ -> Detail Crosswalk
Sector_Crosswalk_Census_USATradeis still a 2017-vintage Activity list. Smoke vsCensus_USATradeFBAs:98000011211X->1121XX; OK to ship336110) drop; FBS Detail row count 305->290This PR does not extend the Crosswalk. Follow-on under #670 / goods-allocation: inventory orphan Activities by year -> concordance to BEA 2017 Detail -> append Crosswalk rows (keep
980000omitted) -> regenTrade_*_{2022..2024}. Cheap first cut: alias1121XXto the same Detail targets as11211X(~0.5 B exports).Out of scope
Testing
Regenerated
Trade_Exports/Imports_{2017..2024}locally (Census/IEA FBAs local;Detail_Supply_{2018..2024}pulled from GCStransform/output_data/).Results (local):
2017 scorecard (after T007; baseline updated): F040 national +12.20%, MCIF +1.14%; Pearson non-special 0.92 / 0.85; no regressions vs prior baseline (49 leaf moves). Re-run without
--update-baselineshould report no changes.