This repository contains the code and supporting data to estimate the ad valorem equivalent (AVE) of non-tariff measures (NTMs) for goods trade, using a gravity-model approach with instrumental variables.
For questions, please open an Issue. If you wish to make edits, please submit a PR.
NTM_Estimation/
├── Goods/
│ └── Model (2000 Bootstrap).R # Main estimation script
├── DATA/
│ ├── BACI/
│ │ ├── BACI.R # Cleans raw BACI trade data
│ │ └── BACI_HS12_V202501/
│ ├── MAcMap-HS6/
│ │ ├── MAcMap.R # Cleans raw MAcMap tariff data
│ │ ├── HS6 TO GTAP UPDATED.xlsx # HS6 → GTAP sector crosswalk
│ │ └── Tariffs_2001_2019/
│ ├── NTM/
│ │ ├── NTM Cleaning.R # Cleans raw Global Trade Alert data
│ │ └── interventions (Download from Global Trade Alert).csv
│ ├── Three_Clostest_Countries/
│ │ └── three_closest_countries.R # Builds IV: neighbour-average NTM & tariff
│ ├── gravity_variables (needs to be updated for year of interest).csv
│ ├── common border cleaned.csv
│ └── landlock.xlsx
└── Sectors and Regions for NTM.xlsx # Sector & region aggregation crosswalk
Working directory: Set your R working directory to the project root (
NTM_Estimation/) before running any script. In RStudio: Session → Set Working Directory → To Project Directory.
- Source: Global Trade Alert Data Center
- File:
DATA/NTM/interventions (Download from Global Trade Alert).csv - Contains bilateral NTM interventions (Red/Amber evaluations) with product-level HS6 codes and implementing/affected jurisdictions.
- Cleaning script:
DATA/NTM/NTM Cleaning.R— filters out Green evaluations and export-related/tariff measures, maps HS6 codes to GTAP sectors, and maps country names to ISO3 codes.
- Source: BACI — International Trade Database at the Product Level
- Files:
DATA/BACI/BACI_HS12_V202501/BACI_HS12_Y[YEAR]_V202501.csv - Provides harmonised bilateral trade flows at the HS6 product level for all available years.
- Cleaning script:
DATA/BACI/BACI.R— maps HS6 codes to GTAP sectors and numeric country codes to ISO3.
- Source: MAcMap-HS6 — Applied Tariffs Database
- Files:
DATA/MAcMap-HS6/Tariffs_2001_2019/Tariffs_2001_2019/mmhs6_[YEAR].csv - Provides applied bilateral tariff rates (ad valorem equivalents) at the HS6 product level.
- Cleaning script:
DATA/MAcMap-HS6/MAcMap.R— maps HS6 codes to GTAP sectors and computes simple averages within sector-pair cells.
- File:
DATA/gravity_variables (needs to be updated for year of interest).csv - Contains bilateral gravity covariates: bilateral distance (
dist), importer and exporter GDP (gdp_importer,gdp_exporter), and other standard gravity controls. Update this file for the year of interest.
- Landlock status:
DATA/landlock.xlsx— binary indicator for landlocked countries. - Common border:
DATA/common border cleaned.csv— binary indicator for country pairs sharing a land border. - Sector/Region crosswalk:
Sectors and Regions for NTM.xlsx— maps HS6/GTAP sector codes and country codes to the aggregation used in the final output.
The estimation follows a two-stage IV-PPML gravity model to recover the ad valorem equivalent (AVE) of NTMs:
DATA/Three_Clostest_Countries/three_closest_countries.R builds bilateral instruments by computing, for each importer–exporter–product triplet, the average NTM count and tariff rate applied by the three geographically closest neighbours of the importer. These neighbour averages serve as instruments for the importer's own NTM and tariff policies.
-
Data assembly: Merges BACI trade flows, MAcMap tariffs, NTM counts, gravity variables, landlock, common border, and the neighbour instruments into a single estimation dataset.
-
First stage (OLS): Regresses observed tariffs and NTM counts on their respective neighbour-average instruments plus standard gravity controls (
log distance,log GDP). Predicted values are used in the second stage. Separate first stages are run for the level and two trade-share-weighted versions (importer-share and exporter-share weighted) of each policy variable, following a heterogeneous-coefficient framework. -
Second stage (PPML): Estimates a Poisson pseudo-maximum-likelihood gravity equation for bilateral trade quantities, using the fitted policy values from the first stage:
- AVE computation: The AVE of NTMs for each bilateral–product cell is:
-
Bootstrap standard errors: 2,000 stratified balanced bootstrap replications (stratified by HS6 sector) are used to compute standard errors for the six structural coefficients.
-
Aggregation: AVEs are trimmed to the 1st–99th percentile, trade-weighted within each importer–exporter–sector cell, and then mapped to the final sector and region aggregation using the crosswalk in
Sectors and Regions for NTM.xlsx.
Run scripts in the following order:
DATA/BACI/BACI.R— producesDATA/BACI/BACI_CLEANED.csvDATA/MAcMap-HS6/MAcMap.R— producesDATA/MAcMap-HS6/mmhs6_2019_CLEANED_SimpleAverage.csvDATA/NTM/NTM Cleaning.R— producesDATA/NTM/NTM_CLEANED.csvDATA/Three_Clostest_Countries/three_closest_countries.R— producesDATA/Three_Clostest_Countries/Three_closest_countries (for stage 1 reg).csvGoods/Model (2000 Bootstrap).R— producesOutput/AVE_codeNew_collapsed.xlsx
readxl, dplyr, fixest, openxlsx, stringr, combinat, boot, writexl, readr, tidyr
Install all at once:
install.packages(c("readxl", "dplyr", "fixest", "openxlsx", "stringr",
"combinat", "boot", "writexl", "readr", "tidyr"))