Replication materials for: Anderson, J. E., Larch, M., & Yotov, Y. V. (2018). "GEPPML: General equilibrium analysis with PPML" The World Economy, 41(10), 2750-2782.
π Quick Start β’ π Documentation β’ π¬ Methodology β’ β Validation β’ π§ Contact
This repository provides a complete R implementation of the General Equilibrium Poisson Pseudo-Maximum Likelihood (GEPPML) methodology developed by Anderson, Larch, and Yotov (2018).
Why this package?
- π― Makes GEPPML accessible to R users who may not have Stata licenses
- β‘ Uses modern, high-performance R packages (
data.table,fixest) - β Produces results identical to the original Stata implementation
- π Fully documented with comprehensive examples
- π Open source (MIT License) for maximum reproducibility
Reference:
Anderson, J. E., Larch, M., & Yotov, Y. V. (2018). GEPPML: General equilibrium analysis with PPML. The World Economy, 41(10), 2750-2782. https://doi.org/10.1111/twec.12664
|
Jamiu Olamilekan Badmus
|
GEPPML is a methodology for conducting general equilibrium (GE) analysis in international trade using the Poisson Pseudo-Maximum Likelihood (PPML) estimator. It extends the structural gravity model to analyze counterfactual trade policy scenarios by accounting for:
|
Current trade patterns and trade costs |
Direct policy effects |
Complete equilibrium |
Applications:
- π€ Regional Trade Agreements (RTAs)
- π Trade liberalization policies
- πͺπΊ Brexit and other trade shocks
- π€οΈ Infrastructure improvements affecting trade costs
| Feature | Description |
|---|---|
| β Exact Replication | Validated against original Stata code (see VALIDATION.md) |
| π Modern R Packages | Uses data.table (fast data manipulation) and fixest (high-performance PPML) |
| π Full Documentation | Comprehensive comments, logging, and user guides |
| π Publication-Ready | Generates country-level indexes and welfare effects for academic research |
| π Open Source | MIT licensed for maximum accessibility and reproducibility |
| π¬ Stata Comparison | Includes original Stata code in GEPPML_stata/ folder for easy comparison |
This package requires R version 4.0+ and the following R packages:
# Install required packages
install.packages(c("data.table", "fixest", "haven", "dplyr"))| Package | Purpose |
|---|---|
data.table |
Fast data manipulation and aggregation |
fixest |
High-performance PPML estimation with fixed effects |
haven |
Reading Stata .dta files |
dplyr |
Additional data manipulation tools |
git clone https://github.com/jamiubadmusng/GEPPML-R.git
cd GEPPML-R-
Set up your working directory:
setwd("path/to/GEPPML_R") -
Run the main script:
source("geppml.R")
The script will:
- Load and prepare the data
- Estimate the baseline gravity model
- Compute conditional GE effects
- Iterate to convergence for full GE effects
- Save all results to the
output/folder - Generate a detailed log file
The package uses the original dataset from Anderson et al. (2018):
Data File: data/ge_ppml_data_orig.dta
Format: Stata .dta file
Structure: Bilateral trade flows with gravity variables
| Variable | Description |
|---|---|
exporter |
Exporting country code (ISO3) |
importer |
Importing country code (ISO3) |
trade |
Bilateral trade flows (US dollars) |
LN_DIST |
Log of bilateral distance (km) |
CNTG |
Contiguity dummy (1 if countries share border) |
BRDR |
Border dummy (1 for international trade, 0 for domestic) |
The script generates several output files in the output/ folder:
| File | Description |
|---|---|
all_indexes_geppml.csv |
β Main results: Country-level GE indexes (CSV format) |
all_indexes_geppml.rds |
Country-level GE indexes (R binary format) |
full_static_all.rds |
Complete dataset with all GE variables |
imrs_all.rds |
Inward Multilateral Resistance (IMR) indexes |
geppml.log |
Detailed execution log |
|
Welfare Effects:
Trade Effects:
|
Multilateral Resistance Terms:
Other Variables:
|
Estimates the current trade patterns using a structural gravity equation:
where
Computes trade effects holding output and expenditure constant, but allowing multilateral resistance terms to adjust:
where
Iteratively solves for the complete general equilibrium by allowing:
- Factory-gate prices to adjust
- Output and expenditure to change endogenously
- All multilateral resistance terms to reach equilibrium
The algorithm iterates until convergence (typically
Outward Multilateral Resistance (OMR):
Inward Multilateral Resistance (IMR):
Real GDP:
where
| Feature | Stata (ppml) |
R (fixest) |
|---|---|---|
| Fixed effects | Manual creation required | Built-in functionality |
| Estimation | ppml command |
feglm with Poisson family |
| Speed | Moderate | Very fast (C++ backend) |
| Syntax | Stata-specific | Standard R |
| Flexibility | Limited | Highly flexible |
The R implementation produces identical results to the original Stata code while being more accessible and easier to modify.
To analyze different trade policy scenarios, modify the trade cost specification:
|
Example 1: Full Trade Liberalization # Remove all international borders
dt[, t_ij_ctrf := exp(
DIST_est * LN_DIST +
CNTG_est * CNTG +
BRDR_est * 0
)] |
Example 2: Regional Trade Agreement # Create RTA effect
dt[, t_ij_ctrf := exp(
DIST_est * LN_DIST +
CNTG_est * CNTG +
BRDR_est * BRDR -
0.5 * RTA
)] |
|
Example 3: Reduce Distance Friction # Reduce distance effect by 50% (e.g., infrastructure improvement)
dt[, t_ij_ctrf := exp(DIST_est * LN_DIST * 0.5 + CNTG_est * CNTG + BRDR_est * BRDR)] |
|
The default reference country is Germany (DEU). To use a different country:
# Change "DEU" to your desired country code (e.g., "USA" for United States)
dt[exporter == "USA", exporter := "ZZZ"]
dt[importer == "USA", importer := "ZZZ"]The default trade elasticity is
sigma <- 5 # Or any other value based on your researchThis R implementation has been rigorously validated against the original Stata code. See VALIDATION.md for detailed comparison.
|
1. Run Stata Version cd "GEPPML_stata"
do geppml.doOutputs: |
2. Run R Version source("geppml.R")Outputs: |
| Metric | Result |
|---|---|
| Gravity Coefficients | β Identical (6+ decimal places) |
| Welfare Effects | β Max difference: 0.014 percentage points |
| Convergence | β Same iterations (~18-20) |
| All Countries | β Consistent results across 41 countries |
| Relative Error | β < 0.2% (within floating-point precision) |
Conclusion: Results are practically identical and suitable for academic publication. Small differences (< 0.02 pp) are within numerical precision tolerance.
If you use this R implementation in your research, please cite both:
@article{anderson2018geppml,
title={GEPPML: General equilibrium
analysis with PPML},
author={Anderson, James E and
Larch, Mario and
Yotov, Yoto V},
journal={The World Economy},
volume={41},
number={10},
pages={2750--2782},
year={2018},
doi={10.1111/twec.12664}
} |
@software{badmus2026geppml,
author={Badmus, Jamiu Olamilekan},
title={GEPPML-R: General Equilibrium
Analysis with PPML in R},
year={2026},
url={https://github.com/jamiubadmusng/
GEPPML-R}
} |
- π Stata Comparison: See
GEPPML_stata/folder in this repository
π¦ Package 'fixest' not found
install.packages("fixest")π Convergence not achieved
# Increase maximum iterations (default is 100)
max_iterations <- 200πΎ Memory errors with large datasets
# Increase memory limit (Windows)
memory.limit(size = 16000) # 16GBπ Results differ slightly from Stata
- This is expected due to numerical precision differences
- Differences should be very small (< 0.02 percentage points)
- Ensure you're using the same data and parameter values
- See VALIDATION.md for detailed comparison
Contributions are welcome! Please feel free to:
- π Report bugs or issues
- π‘ Suggest enhancements
- π§ Submit pull requests
- π Share your applications of the code
See CONTRIBUTING.md for guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- James E. Anderson, Mario Larch, and Yoto V. Yotov for developing and sharing the GEPPML methodology
- Laurent BergΓ© for the excellent
fixestpackage