This repository contains the accompanying toolkit for "Measurement Error and Counterfactuals in Quantitative Trade and Spatial Models" by Bas Sanders.
The folder General algorithm toolkit implements the high-level approach from Algorithm 1 in the paper.
- The function
GA_toolkit.mtakes as inputs the number of posterior draws to produce, the structural parameter and a vector of noisy data, and outputs the point estimate for gamma and a vector of posterior draws for gamma. It requires auxiliary functionspi_post.mandg.m. - The function
pi_post.mtakes as input a vector of noisy data and outputs a posterior draw of the true data. - The function
g.mtakes as inputs a vector of true data and the structural parameter and outputs a scalar counterfactual prediction.
The folder Default approach toolkit implements the default approach from Algorithm 3 in the paper.
- The function
DA_toolkit.mtakes as inputs the number of posterior draws to produce, the structural parameter, a vector of noisy data, a vector of probabilities of true zeros, a vector of probabilities of spurious zeros, a vector of measurement error variances, a vector of prior means, and a vector of prior variances. It outputs the point estimate for gamma and a vector of posterior draws for gamma. It also outputs a report that compares the normalized residuals histogram with standard normal pdf. It requires the auxiliary function "g.m". - The function
g.mtakes as inputs a vector of true data and the structural parameter and outputs a scalar counterfactual prediction.
The folder Mirror trade toolkit uses the mirror trade dataset of Linsi, Burgoon, and Mügge (2023) and allows the researcher to choose countries and years for which they want to estimate the parameters of the prior and measurement error model.
- The function
MT_toolkit.mtakes as inputs a set of countries, a set of years to use for calibration, and a set of years to produce bootstrap draws for. It outputs a vector of noisy data, a vector of probabilities of true zeros, a vector of probabilities of spurious zeros, a vector of measurement error variances, a vector of prior means, and a vector of prior variances. It also outputs a report that computes the adjusted R-squared of the gravity model for the last year, and plots log flows against log distance after partitioning out fixed effects for the last year. - The script
Example.millustrates the use of the functionMT_toolkit.mfor a small set of countries.