Updating raw data
This page describes what to do when a source publishes a new data vintage. The general procedure is the same for every file:
- Download the new file from the source listed in Raw data sources and place it in
data/raw/(or the subfolder named below), keeping the old file until the new run is validated. - Edit the constant at the top of the consuming script that names the file, quoted below for each file.
- Check the structural assumptions listed for that file. The scripts read sheets, header rows and columns by name or position; a new vintage that changes them fails loudly (a missing sheet or column) or, worse, silently (a shifted column read by position).
- Rerun the pipeline (
scripts/run_r_pipeline_unix.sh, the.battwin, orRscript main.Rfromcode/processing/; see Processing pipeline) and go through the checklist at the end of this page.
Files are grouped by source. “Consumed by” names the scripts in code/processing/R/. Year constants that must move together with the vintage are collected in “Moving the analysis period”.
USDA baseline
2025 International Long-Term Projections to 2034.xlsx
- Consumed by:
10_read_baseline_data.R. - Constant:
baseline_data <- "2025 International Long-Term Projections to 2034.xlsx". - To update: drop the new workbook in
data/raw/, editbaseline_data, updateregion_commodity_list_2025.xlsxif the set of regions per commodity changed, rerun. - Assumptions: one sheet per commodity named exactly
Barley,Beef and veal,Corn,Cotton,Pork,Poultry,Rice,Sorghum,Soybeans,Soybean meal,Soybean oil,Wheat. Within a sheet, region tables appear in the order of the region list followed byWorld, each 25 rows apart; the first data block spans rows 9 to 29 for Poultry and rows 7 to 27 for every other commodity, and holds 6 (Poultry, Beef and veal, Pork), 8 (Rice), 9 (Cotton), 10 (Barley, Corn, Sorghum, Wheat, Soybean meal, Soybean oil) or 11 (Soybeans) columns whose meaning is fixed in the script. Missing values are the string--; the year column holds crop years such as2025/26. Any change in the row spacing, the starting row, the column set of a commodity group, or the region order breaks the read silently (values land under the wrong name), so comparedata/interim/baseline_projections_long.csvagainst the workbook for a few regions after the first run.
region_commodity_list_2025.xlsx
- Consumed by:
01_check_region_commodity_coverage.R,10_read_baseline_data.R. - Constant:
input_path_list <- file.path(base_dir, "raw", "region_commodity_list_2025.xlsx")in both scripts. - To update: project-maintained. Rebuild it from the new workbook’s table of contents (one row per region and commodity, in the order the regions appear in each commodity sheet), edit the two constants, rerun.
- Assumptions: sheet
Sheet1with columnsregionandcommodity; region names must match those inmapping.csv(columnregion) and commodity names must match the sheet names of the baseline workbook.
baseline_units.csv
- Consumed by:
12_generate_data_targets.R(declared but not read by24_generate_data_exogenous.R). - Constant:
input_path_units <- file.path(base_dir, "raw", "baseline_units.csv"). - To update: project-maintained; edit in place only if the baseline changes units (for example cotton bales).
- Assumptions: columns
commodity,commodity_name,attribute_description,unit, joined oncommodity(model code) andattribute_description.
Macro and population
Current_GDP_WB_2025.xls and population_WB_2025.xls
- Consumed by:
24_generate_data_exogenous.R. - Constants:
input_path_GDP_WB <- file.path(base_dir, "raw", "Current_GDP_WB_2025.xls")andinput_path_population_WB <- file.path(base_dir, "raw", "population_WB_2025.xls"). - To update: download the World Bank indicator files (
NY.GDP.MKTP.CD,SP.POP.TOTL) in Excel format, drop them indata/raw/, edit the two constants, edit the year filters (filter(year == 2025 ...)for both GDP and population) if the reference year moves, rerun. - Assumptions: sheet
Datawith three title rows above the header (skip = 3); header columnsCountry Name,Country Code,Indicator Name,Indicator Code, then one column per year.WLDis excluded. Myanmar isMMRand is recoded toBUR.
Current_GDP_IMF_WEO_2025.csv and population_IMF_WEO_2025.csv
- Consumed by:
24_generate_data_exogenous.R(Taiwan only, absent from the World Bank series). - Constants:
input_path_GDP_IMF <- file.path(base_dir, "raw", "Current_GDP_IMF_WEO_2025.csv")andinput_path_population_IMF <- file.path(base_dir, "raw", "population_IMF_WEO_2025.csv"). - To update: export the WEO series
NGDPD(GDP, current USD, billions) andLP(population, millions) in the IMF data portal CSV layout, drop them indata/raw/, edit the constants, rerun. - Assumptions: columns
DATASET,SERIES_CODE,OBS_MEASURE,COUNTRY,INDICATOR,FREQUENCY,SCALE, then one column per year; the row is selected withCOUNTRY == "Taiwan Province of China"; GDP is multiplied by 1e9 and population by 1000, so theSCALEmust remain billions and millions.
current_GDP_2014_WB.csv and current_GDPpc_2014_WB.csv
- Consumed by:
23_compute_NTM_ave.R. - Constants:
input_path_GDP <- file.path(base_dir, "raw", "current_GDP_2014_WB.csv")andinput_path_GDPpc <- file.path(base_dir, "raw", "current_GDPpc_2014_WB.csv"). - To update: only if the NTM reference year (2014, tied to the BACI and WITS 2014 files and the NTM AVE dataset) changes; then all 2014 inputs move together. Export the WDI series for the new year, edit the constants and the column name below.
- Assumptions: WDI export layout with columns
Series Name,Series Code,Country Name,Country Code,2014 [YR2014]; the last one is read asX2014..YR2014.afterread.csv. Missing values are...EUUis recoded toEUN,MMRtoBUR.
current_GDP_IMF.xls and current_GDPpc_IMF.xls
- Consumed by:
23_compute_NTM_ave.R(Taiwan only). - Constants:
input_path_GDP_twn <- file.path(base_dir, "raw", "current_GDP_IMF.xls")andinput_path_GDPpc_twn <- file.path(base_dir, "raw", "current_GDPpc_IMF.xls"). - To update: as above, only with the NTM reference year.
- Assumptions: the first sheet’s first column is headed
GDP, current prices (Billions of U.S. dollars)andGDP per capita, current prices\n (U.S. dollars per capita)respectively (the header text, including the line break, is used inrename()), followed by one column per year; the column2014is read; the row isTaiwan Province of China.
Prices and CPI
2026-06-19 IMF Commodity Prices external-data.xlsx
- Consumed by:
20_compute_ag_expenditure_share.R. - Constant:
input_path_imf <- file.path(base_dir, "raw", "2026-06-19 IMF Commodity Prices external-data.xlsx"). - To update: download the IMF Primary Commodity Prices monthly workbook, drop it in
data/raw/, edit the constant, rerun. - Assumptions: sheet
External, read without headers. Row 1 holds the commodity codes; the script selectsPBARL,PWHEAMT,PCOTTIND,PRICENPQ,PMAIZMT,PSORG,PSOYB,PSMEA,PSOIL(tableimf_meta, which also fixes each commodity’s marketing-year start month). Column 1 holds date labelsYYYYMm(for example2025M3); other rows are ignored. Units must stay USD per metric ton, except cotton and sorghum in US cents per pound, because the conversion in20and24is hard-coded per commodity.
2026-06-19 International Prices FAO Meat.xlsx
- Consumed by:
20_compute_ag_expenditure_share.R. - Constant:
input_path_fao <- file.path(base_dir, "raw", "2026-06-19 International Prices FAO Meat.xlsx"). - To update: export the same ten export-price series from the FAO GIEWS FPMA international prices tool, in the same column order, drop the file in
data/raw/, edit the constant, rerun. - Assumptions: sheet
data, read without headers; column 2 holds datesMM/DD/YYYY; the meat averages use fixed column positions (columns 3, 4, 5 for beef: United States, Australia, Brazil; 6, 8, 9 for pork: Brazil, EU, United States; 7 and 10 for poultry: Brazil, United States), so adding, removing or reordering a series in the export changes the averages silently. Prices are USD per tonne.
2026-06-24 CPI_US.xlsx
- Consumed by:
20_compute_ag_expenditure_share.R. - Constant:
input_path_cpi_17 <- file.path(base_dir, "raw", "2026-06-24 CPI_US.xlsx"). - To update: extend the annual-average CPI-U series (BLS or FRED
CPIAUCNS) in the workbook, recomputeCPI_2017as the annual average divided by the 2017 average, edit the constant, rerun. - Assumptions: sheet
Sheet1with columnsyear,AVG_CPI,CPI_2017; joined onyear, and every year with price data must be present (a missing year yields missing deflated prices). The base year 2017 is fixed by the price units of the model (USD Million (prices of 2017)).
Trade barriers
All files live in data/raw/trade_barriers/. Five of them are not distributed with the repository (two for size, three because of UNCTAD TRAINS and WTO terms): tariff_ave_WITS_2023.csv, tariff_ave_2014_WITS.csv, ag_hs_products.csv, ag_tariff_USA_2014.xls and BACI_HS92_Y2014_V202401b.csv. Their derived products are shipped in data/interim/ and reused by main.R when the raw files are absent. A refresh of any of them requires obtaining the file from its source (query settings in Raw data sources; scripts/fetch_large_raw_data.sh reports which are present and downloads the CEPII file), then rerunning scripts 22 and 23, which rewrite the derived files.
tariff_ave_WITS_2023.csv (not distributed)
- Consumed by:
22_compute_tariff_ave.R; its presence is also tested bymain.R, which otherwise reuses the shippeddata/interim/tariff_ave_region.csvandexport_taxes_comm_reg.csv. - Constant:
input_path_tariff <- file.path(base_dir, "raw", "trade_barriers/tariff_ave_WITS_2023.csv"), and the file name inmain.R(tariff_raw) and in the fetch scripts. - To update: obtain the file from WITS (Advanced Query, TRAINS, all reporters, all partners, all HS6 products, the new year, AVE of applied tariff, CSV export), drop it in the folder, edit the constant, and edit the string
year = "2023 (or last observed)"written to the output; rerun. Script 22 then rewrites the two derived files indata/interim/, which are tracked in git. - Assumptions: WITS export columns
Reporter(numeric code),Product(HS code, leading zero dropped),DutyType,Simple Average,Tariff Year(read asSimple.Average,Tariff.Year). OnlyDutyType == "MFN"rows are used. Product codes of 3 or 5 digits get a leading zero; the commodity mapping uses fixed HS4 and HS6 lists, so a nomenclature revision that moves the modeled products to other headings requires editing that mapping. The EU must be reported as one reporter (EUNincountry_code_WITS.xlsx).
country_code_WITS.xlsx
- Consumed by:
22_compute_tariff_ave.R,23_compute_NTM_ave.R. - Constant:
input_path_code(22) andinput_path_WITS_code(23), bothfile.path(base_dir, "raw", "trade_barriers/country_code_WITS.xlsx"). - To update: only if WITS adds reporters; append rows.
- Assumptions: first sheet with columns
country,ISO3,Reporter(the numeric WITS reporter code).MMRis recoded toBUR.
ave_hs_importer.csv
- Consumed by:
23_compute_NTM_ave.R. - Constant:
input_path_NTM <- file.path(base_dir, "raw", "trade_barriers/ave_hs_importer.csv"). - To update: the World Bank NTM AVE dataset is a one-off release (2014 reference); if a new release appears, all 2014 inputs of the NTM step should move together.
- Assumptions: columns
importer(ISO3),hs2code(HS6 code despite the name, leading zero dropped),ave1C,ave2C; the AVE is the row sum of the last two.
BACI_HS92_Y2014_V202401b.csv (not distributed)
- Consumed by:
23_compute_NTM_ave.R; its presence is also tested bymain.R, which otherwise reuses the shippeddata/interim/NTM_IMP_ave_region.csvandNTM_EXP_ave_region.csv. - Constant:
input_path_trade <- file.path(base_dir, "raw", "trade_barriers/BACI_HS92_Y2014_V202401b.csv"), and the file name inmain.R(ntm_raw) and inscripts/fetch_large_raw_data.shand.bat(BACI_FILE). - To update:
scripts/fetch_large_raw_data.sh --downloadfetches release 202401b and extracts the 2014 file. For a newer BACI release, change the URL and file name in the fetch scripts, inmain.R, and in the constant, and updatecountry_codes_V202401b.csvto the matching release. Rerun script 23, which rewrites the NTM derived files indata/interim/. - Assumptions: BACI columns
t,i,j,k,v,q(year, exporter code, importer code, HS6 product, value, quantity); HS codes lose their leading zero and get it back in the script. Taiwan is BACI code 490 and Myanmar 104.
country_codes_V202401b.csv
- Consumed by:
23_compute_NTM_ave.R. - Constant:
input_path_BACI_code <- file.path(base_dir, "raw", "trade_barriers/country_codes_V202401b.csv"). - To update: together with the BACI release.
- Assumptions: columns
country_code,country_name,country_iso2,country_iso3.
ag_hs_products.csv (not distributed)
- Consumed by:
23_compute_NTM_ave.R; its presence is also tested bymain.R. - Constant:
input_path_ag_goods <- file.path(base_dir, "raw", "trade_barriers/ag_hs_products.csv"), plusmain.R(ntm_raw) and the fetch scripts. - To update: obtain the WITS product group
WTO_HS_Aggriexported as CSV; rarely changes. Rerun script 23, which rewrites the NTM derived files indata/interim/. - Assumptions: WITS layout with a
Productcolumn; the rowWTO_HS_Aggriis dropped; only the distinct product codes are used.
ag_tariff_USA_2014.xls (not distributed)
- Consumed by:
23_compute_NTM_ave.R(source of the HS6 codes that belong to the twelve commodities). When the file is absent the script reads the shippeddata/interim/commodity_hs6_mapping.csv(67 HS6 codes) instead; when present it rebuilds and rewrites that mapping. - Constant:
input_path_hs6 <- file.path(base_dir, "raw", "trade_barriers/ag_tariff_USA_2014.xls"). - To update: rarely; obtain the WTO Tariff and Trade Data export of the United States applied MFN schedule for 2014 (or any HS6 schedule with the modeled products, if the sheet and column below are kept) and rerun script 23.
- Assumptions: sheet
Applied_MFN, column E from row 6 holds HS codes; 6-digit codes are kept and classified by their HS4 prefix using the same fixed lists as script 22.
tariff_ave_2014_WITS.csv (not distributed)
- Consumed by:
23_compute_NTM_ave.R; its presence is also tested bymain.R. - Constant:
input_path_tariff <- file.path(base_dir, "raw", "trade_barriers/tariff_ave_2014_WITS.csv"), plusmain.R(ntm_raw) and the fetch scripts (WITS_FILE). - To update: obtain it manually from WITS (see
scripts/fetch_large_raw_data.shfor the query); only with the NTM reference year. Rerun script 23, which rewrites the NTM derived files indata/interim/. - Assumptions: same WITS export layout as
tariff_ave_WITS_2023.csv;DutyType == "MFN"rows;Reporter,Product,Simple.Average.
country_region_WB.xlsx
- Consumed by:
23_compute_NTM_ave.R(geographic region fixed effects). - Constant:
input_path_region <- file.path(base_dir, "raw", "trade_barriers/country_region_WB.xlsx"). - To update: download the World Bank country and lending groups workbook, drop it in the folder, edit the constant; check the row range.
- Assumptions: sheet
List of economies, rows 1 to 219, columns 2 and 3 headedCodeandRegion. RegionsEurope & Central AsiaandMiddle East & North Africaare merged intoEuro-MENA,East Asia & PacificandSouth AsiaintoAsia-Pacific; renamed regions break the merge silently (they become their own fixed-effect group).
Land cost and livestock
AgTFPInternational2023.xlsx
- Consumed by:
21_compute_land_cost_share.R. - Constant:
input_path_land_share <- file.path(base_dir, "raw", "AgTFPInternational2023.xlsx"). - To update: download the new USDA International Agricultural Productivity workbook, drop it in
data/raw/, edit the constant, then check the read:sheet = "Cost Shares", rows = 3:182, cols = c(3, 33)andrename(land_share_r =2021-2030). - Assumptions: sheet
Cost Shares; column 3 is headedISO3on row 3 and column 33 is the land cost share for the latest decade, headed2021-2030on row 3 (row 2 carries the block labelLAND); rows 4 to 182 are countries. A new vintage will add a decade column and shift the position, and will rename the header, so both the column index and the name must be edited.MMRis recoded toBUR; the EUR share is hard-coded at 0.113 in the script.
variable_costs_2025/ (five workbooks)
U.S. Feed Grains projections to 2035.xlsx, U.S. Rice projections to 2035.xlsx, U.S. Soybeans and products projections to 2035.xlsx, U.S. Upland Cotton projections to 2035.xlsx, U.S. Wheat Projections to 2035.xlsx.
- Consumed by:
21_compute_land_cost_share.R. - Constants:
input_path_vc_dir <- file.path(base_dir, "raw", "variable_costs_2025")andvc_pattern <- "to 2035"(every file in the folder whose name matches the pattern is read). - To update: create a new folder (for example
variable_costs_2026), drop the new USDA Agricultural Projections commodity tables in it, editinput_path_vc_dirandvc_pattern, rerun. Also editfilter(year >= 2024 ...)if the projection start moves. - Assumptions: parsed by labels in column 1 of every sheet: a
Table ... U.S. <crop>title (the crop is recognized from the words corn, sorghum, barley, rice, soybean, cotton, wheat; oats are skipped), anItemrow whose remaining cells are crop years such as2025/26, a row startingVariable costs of production, and the next row labeledPer acreholding the values. A retitled table or a renamed row drops the crop silently; checkdata/interim/variable_costs_us_2025.csvhas all seven crops and all years.
FAOSTAT_total_livestock_value_constant_IntlD.csv and FAOSTAT_each_livestock_value_constant_IntlD.csv
- Consumed by:
11_compute_feed_use_decomposition.R. - Constants:
input_path_total_value,input_path_each_value, eachfile.path(base_dir, "raw", "<file>"). - To update: FAOSTAT QV (Value of Agricultural Production, constant 2014-2016 international dollars). Export the 2015
Livestockaggregate for all countries, and the 2015 values of the five indigenous meat items for all countries; drop the files indata/raw/, edit the constants. - Assumptions: FAOSTAT CSV with columns
Area Code (ISO3)(read asArea.Code..ISO3.),Item,Year,Value. Item labels must be exactlyMeat of cattle with the bone, fresh or chilled (indigenous),Meat of buffalo, fresh or chilled (indigenous),Meat of pig with the bone, fresh or chilled (indigenous),Meat of chickens, fresh or chilled (indigenous),Meat of turkeys, fresh or chilled (indigenous)and, in the total file,Livestock. FAOSTAT renames items between releases; a renamed item silently drops out of the shares. The total and each-item files must contain a single year.
FAOSTAT_Livestock_Inventory_2024.csv and FAOSTAT_Slaughtered Livestock_2024.csv
- Consumed by:
24_generate_data_exogenous.R. - Constants:
input_path_liv_inv <- file.path(base_dir, "raw", "FAOSTAT_Livestock_Inventory_2024.csv")andinput_path_liv_slg <- file.path(base_dir, "raw", "FAOSTAT_Slaughtered Livestock_2024.csv"). - To update: FAOSTAT QCL, elements
StocksandProducing Animals/Slaughteredfor the new year, all countries; drop the files indata/raw/, edit the constants, and edit the two occurrences ofmutate(Year = 2024)andyear = 2024in the script. - Assumptions: FAOSTAT CSV with columns
Area Code (ISO3),Item,Year,Unit,Value. Inventory itemsBuffalo,Cattle,Chickens,Ducks,Geese,Other birds,Swine / pigs,Turkeys; slaughter itemsMeat of buffalo, fresh or chilled,Meat of cattle with the bone, fresh or chilled,Meat of chickens, fresh or chilled,Meat of ducks, fresh or chilled,Meat of geese, fresh or chilled,Meat of pigeons and other birds n.e.c., fresh, chilled or frozen,Meat of turkeys, fresh or chilled,Meat of pig with the bone, fresh or chilled. Cattle and pigs are reported in head and poultry in 1,000 head; the script divides the former by 1,000, so the FAOSTAT units must not change.
Identifiers and parameters
mapping.csv
- Consumed by:
11,12,20,21,22,23,24,30(constantinput_path_mapping <- file.path(base_dir, "raw", "mapping.csv")in each). - To update: project-maintained. Edit in place when a country changes region or the baseline adds a region; then provide the new region’s parameters in
exogenous_data.csv. - Assumptions: columns
group,region_code,region,region_name,country_code,country.regionmust match the USDA baseline region names used inregion_commodity_list_2025.xlsx;country_codeis ISO3 with Myanmar asBUR; groupAmarks the 42 model regions (B and C are aggregated intoROWin the NTM step). Scripts 11, 22 and 23 drop the two former Yemen rows and 22 and 23 replace the EU members by a singleEUNreporter.
exogenous_data.csv
- Consumed by:
24_generate_data_exogenous.R. - Constant:
input_path_exo_params <- file.path(base_dir, "raw", "exogenous_data.csv"). - To update: project-maintained (calibrated elasticities
sigma_t,sigma_u,epsilon_l,epsilon_q,omega_c,omega_qand the per-region, per-commodity productivity and land parameters). Edit in place; the file is appended todata_exogenous.csvas is. - Assumptions: already in the model schema (
region, year, nest, commodity, input, attribute, value, unit, attribute_type, attribute_description, region_name, nest_name, commodity_name). The attributeLand Unavailabilityis renamed with a trailing space by the script to match the model.
Moving the analysis period
When the USDA baseline advances a year, the following year constants must move together (all in code/processing/R/):
12_generate_data_targets.R:lst_obsv_yr <- 2025.30_generate_data_shocks.R:first_yr <- 2025,last_yr <- 2034.11_compute_feed_use_decomposition.R:filter(year >= 2025).20_compute_ag_expenditure_share.R:years <- 2025:2034, the GDP level and growth columns (see the GDP shares file above),filter(year == 2025)for the expenditure and the exported share.21_compute_land_cost_share.R:filter(year >= 2024 ...)andfilter(year>=2025).24_generate_data_exogenous.R:marketing_year == 2025for prices,year == 2025for population and GDP,Year = 2024andyear = 2024for livestock.- The model run:
scripts/run_model_unix.shand.batdefault to2025:2034, andcode/model/test/runtests.jlpins the same period for the baseline package.
The package name written by 60_build_input_package.R follows the first year of data_targets.csv automatically.
Checklist for a full refresh
- Place the new raw files in
data/raw/and edit the file name constants and year constants listed above. Keep the previousdata/processed/anddata/packages/copies for comparison (they are tracked in git, sogit diffandgit stashwork). - Decide whether scripts 22 and 23 run or are skipped. They run only when their raw inputs that are not distributed are under
data/raw/trade_barriers/(scripts/fetch_large_raw_data.shreports which of the five are present); otherwisemain.Rreuses the derived files shipped indata/interim/. A refresh of the trade-barrier sources requires the raw files, and the rerun rewrites the tracked derived files. - Run the pipeline:
scripts/run_r_pipeline_unix.shorscripts\run_r_pipeline_windows.bat(orRscript main.Rfromcode/processing/). It must end withmain.R ... ALL DONE. Read the console for the50_harmonize_targets:summary line and any warning about unmatched names. - Inspect
data/interim/harmonization_log.csv. Expect rows withdelta1 or 2 and statusadjusted, on both checks; a status containingoutsideor a residual larger than 2 points to a broken read in script 10 or a changed baseline layout. - Spot-check the intermediates against the sources:
baseline_projections_long.csvfor two or three regions,variable_costs_us_2025.csvfor all seven crops,international_prices_annual.csvfor the last marketing year, andag_expenditure_shares.csvfor plausible shares. - Diff the new
data/processed/*.csvagainst the previous vintage (row counts per attribute, new or missing region-commodity pairs) before accepting them. - Run the model on the new package:
scripts/run_model_unix.sh data/packages/baseline_<year>_Input.zip output/baseline_Output.zip <first>:<last>(or the.battwin). Every year should report a solved status in the solver log. - Check that the neutral run reproduces the new targets: upload the output package to the dashboard (Dashboard). With neutral shocks every ratio of solution to baseline is 1, so “Top # Regional Changes” shows zero percent change for every attribute and year. A nonzero change in yields or extraction rates points at script 50 (derived series); a nonzero change elsewhere points at the harmonization log.
- Once validated, refresh the regression reference:
code/model/test/expected/baseline_<year>_Input.sha256and the fixture path incode/model/test/runtests.jl, thenjulia --project=code/model code/model/test/runtests.jl. - Update Raw data sources (file names and vintage dates), this page, and Processing pipeline if any script header changed.