Abstract
Abstract.
In this article, we describe an algorithm for computing counterfactual trade flows, prices, output, and welfare in a large class of general equilibrium trade models. We introduce a command called
Keywords
Introduction
In economics, the use of simulation models to analyze the impact of trade policies on trade flows is of great importance to policymakers and researchers alike. An early way of simulating structural gravity models in Stata was an ingenious procedure known as GEPPML, which was proposed by Anderson, Larch, and Yotov (2018), who repurposed a Poisson pseudo-maximum-likelihood estimator to conduct general equilibrium simulations. Zylkin (2019) later developed
The
The
As stated by Allen, Arkolakis, and Takahashi (2020), a model belongs to the class of universal gravity models if an aggregate good is traded across locations and if it satisfies six specific economic conditions or properties: 1) bilateral trade frictions of the “iceberg” type, 2) constant elasticity of substitution in aggregate demand, 3) constant elasticity of substitution in aggregate supply, 4) market clearing, 5) exogenous trade deficits, and 6) a choice of numeraire. These six conditions provide sufficient structure to fully describe all general equilibrium interactions of trade flows, incomes, and real output prices in terms of the elasticity of aggregate demand and supply.
The universal gravity framework encompasses a wide variety of models, including those of Armington (1969), Anderson (1979), Anderson and van Wincoop (2003), Krug- man (1980), Eaton and Kortum (2002), Melitz (2003), di Giovanni and Levchenko (2013), Allen and Arkolakis (2014), Redding (2016), and Redding and Sturm (2008). On the other hand, many prominent models do not fall into the category of universal gravity models. These typically include models where there are multiple factors of production with varying intensities, where trade deficits evolve endogenously, or where demand and supply elasticities are not constant. In addition, models that include additional sources of revenue, such as tariffs, generally do not fit into the universal gravity framework except in special circumstances.
The article is organized as follows. In section 2, we present a prototypical trade model with positive supply elasticity that serves as an example of the kind of models that can be simulated using the
In section 3, we present the syntax of the
Section 4 demonstrates the use of the command through three examples. The first example demonstrates the basic use of the command by showing how to perform an ex ante analysis of the effects of a trade agreement. The second example demonstrates the use of the command with the by prefix by going through an example inspired by Campos, Reggio, and Timini (2023) that calculates the evolution of welfare costs associated with trade policies in Spain during the Franco regime. The third example shows how the command can be used to simulate a scenario in which trade costs remain unchanged but a country’s productivity increases, which in general equilibrium affects welfare and other economic variables for all countries in the world.
We conclude in section 5 and show how to install the command in section 7. In the online appendix, we derive various results that are used in the article but are too long to include in the main text.
Economic theory and methods
A prototypical trade model with a positive supply elasticity
There are N locations, denoted by the subscript i or j. Sending goods from i to j incurs an iceberg trade cost, denoted by τ
ij
≥ 1. Goods are produced by combining immobile labor with intermediate inputs. As in the model of Eaton and Kortum (2002), the production function is a Cobb-Douglas function with constant returns to scale, where ζ denotes the share of labor (Li) in costs, 1 — ζ denotes the share of intermediate inputs (Mi), and Ai > 0 denotes labor productivity:
Intermediates are assumed to be the same bundle of goods as those entering final consumption so that the price index for intermediates for each firm is the price index taken over all goods. 1 We denote this price index by Pi.
Assuming perfect competition, the price of output at location i is given by
Because of arbitrage in the goods markets, the price paid at a destination j for a good that is shipped from the origin i is
The amount of goods that reach the destination j after subtracting the iceberg cost is denoted by qij. The expenditure on this good, valued at prices at the destination, is
Equilibrium requires that output markets clear, that is, that prices and quantities adjust so that output Qi at each location equals the aggregate demand from all locations, including iceberg costs:
At each location, there is a representative consumer who supplies labor inelastically and whose entire income comes from labor income. This consumer values varieties of goods according to a constant elasticity of substitution (CES) function that aggregates goods from all origins, as in the models of Armington (1969), Anderson (1979), and Anderson and van Wincoop (2003). The elasticity of substitution is denoted by σ > 1. The optimization problem of the consumer leads to the well-known result that expenditure on goods from different origins can be expressed as
Trade deficits are exogenous. Expenditure at any location i is expressed as a multiple of the value of output as
The parameter ξ
i
> 0 is location specific, and the parameter Ξ is common to all locations. This way of specifying trade deficits ensures that the sum of exports from all locations always equals the sum of imports from all locations. In the special case where ξ
i
= 1 for all i (which also implies Ξ = 1), the trade deficits of all locations are exactly 0. On the other hand, if some ξ
i
≠ 1, then trade is not balanced at all locations. The trade deficit at location i can then be expressed as
In this model, output (Qi), income (Yi), and welfare (Wi) are proportional to real output prices pi/Pi raised to powers of the supply elasticity, which is defined as
The first of these results shows why
The prototypical model described in this section falls into the more general class of models that Allen, Arkolakis, and Takahashi (2020) define as the universal gravity framework. We now turn to the characterization of this more general framework and how it can be used to solve for the price ratio pi/Pi, which—together with the supply elasticity ψ—is a sufficient statistic for real wages and ultimately welfare in the prototypical trade model.
Models that are part of the universal gravity framework satisfy six properties. We list them briefly and refer the reader to the article by Allen, Arkolakis, and Takahashi (2020) for a more detailed discussion.
Because of Shephard’s lemma, property 2 implies that the value of trade flows, defined as Xij = pijqij (where qij is the real value of goods arriving at location j and pij is their price at location j), can be written as a function of prices and expenditure as follows:
The consumption side of the prototypical trade model, which gives rise to the gravity equation in (3), satisfies property 2. The production side, which implies the proportionality in (5), satisfies property 3 with
Allen, Arkolakis, and Takahashi (2020) show that various other models also satisfy the six properties of the universal gravity framework, among them the models by Arm- ington (1969), Anderson (1979), Anderson and van Wincoop (2003), Krugman (1980), Eaton and Kortum (2002), Melitz (2003), di Giovanni and Levchenko (2013), Allen and Arkolakis (2014), Redding (2016), and Redding and Sturm (2008).
Comparative statics
Allen, Arkolakis, and Takahashi (2020) show that the response of prices to a change in the trade cost matrix can be obtained by solving a system of equations that is the same for all models in the universal gravity framework that have the same trade elasticity θ and supply elasticity ψ. In this section, we present a slightly more general version of the system of equations that allows for unbalanced trade, changes in trade deficits, and changes in supply shifters.
We use the “hat algebra” notation introduced by Dekle, Eaton, and Kortum (2008). For each variable, its hat version is defined as the ratio of the value of the variable in a counterfactual equilibrium relative to the value in a baseline equilibrium; if x is the value in the baseline equilibrium and x′ is the value in the counterfactual equilibrium, then
The comparative statics exercise we consider allows for a change in the matrix of bilateral trade costs with elements
As shown in the online appendix, if prices and quantities in the baseline and the counterfactual are part of an equilibrium that satisfies the six properties of the universal gravity framework, then the changes in price vectors
Once this system is solved, other quantities can be derived from the resulting price vectors. For example, in the case of the prototypical trade model, because of the proportionality relationships shown earlier, the comparative statics for output and income can be obtained immediately as
Comparative statics for expenditure are determined by
The comparative statics derived for welfare and output are specific to the prototypical model presented in this article. Other models may yield different results, especially for welfare. However, the comparative statics for some of the variables are quite general in that they are common to all models in the universal gravity framework. This holds for prices and, conditional on the price normalization, also for the value bilateral trade flows, expenditure, and income.
Algorithm to solve for prices (universal option)
We first present the most general version of the algorithm, which is used when the
The matrix
The second key input is a matrix that encodes the partial equilibrium effects of changes in trade costs. We will call this matrix
The remaining two required inputs are the trade elasticity θ and the supply elasticity ψ. In addition to the required inputs, there are two additional input vectors that can be optionally provided to the algorithm: the vector
Algorithm to solve for prices with constant trade deficits (default option)
The algorithm just described is the one used when the user runs the
To derive the algorithm, we start from (4):
Solving this equation for ξ
i
leads to
The change in the endogenous variable
The modifications with respect to the previous algorithm consist of initializing
Running the
Algorithm to solve for prices with multiplicative trade deficits (multiplicative option)
The
In
Running the
Comparison with the universal option. The results that are obtained with the multiplicative option will generally not match those obtained with the universal option, even when
Remaining calculations
Once price changes have been obtained, other variables follow in order. We maintain the convention that all operations except the Kronecker product are performed element by element. The change in income is obtained directly from the price changes as
For the prototypical trade model, the change in real prices also translates directly into changes in real output, which is obtained as
The changes of real and nominal wages in the prototypical trade model also depend on the distinction between
Reporting comparative statics for the prototypical trade model
The normalization in property 6 determines the scale of nominal quantities in all universal gravity models. Because the prototypical trade model determines only real variables, we said earlier that property 6 does not conflict with the model. However, there is a subtle point that needs to be clarified. The use of normalization in property 6 is harmless for equilibrium objects in the baseline economy and in the counterfactual economy when considered in isolation. However, when doing comparative statics, using the same normalization in both models introduces an additional assumption. In this case, the assumption is that global nominal income is the same in the baseline and the counter- factual. This assumption may not be consistent with the intended use of the model. Researchers should therefore be cautious when reporting comparative static calculations for nominal quantities. Thus, the default results table generated by the command shows growth rates only for real variables.
The default calculation reports the vector relative changes of real (nondomestic) exports for all locations, which is calculated as
Similarly, the vector of real relative changes of imports is calculated as
The relative change in total trade is obtained as the weighted average of the relative changes of exports and imports, where the weights are given by exports and imports in the baseline economy. The change in domestic trade is calculated from the diagonal elements of the bilateral trade matrix
Finally, the relative change of real output and welfare is computed as
All of these relative changes are expressed in percentage points. They are to be interpreted as the impact of moving from the baseline situation to the counterfactual situation, not as growth rates of variables over time.
The matrix of partial equilibrium effects
The matrix
Users of the
Partial equilibrium effects are frequently obtained from a prior gravity estimation that imposes
The parameter β has the interpretation of a partial equilibrium semielasticity; it measures the relative change in trade flows associated with switching the dummy variable zijt from 0 to 1, holding all other variables constant. The fixed effects that are usually included in the regression absorb any general equilibrium effects (for example, changes in country-specific output prices
The change from a situation without a trade agreement to one with a trade agreement implies the following change in bilateral trade costs:
This behavior replicates the behavior of the prior command ge_gravity. The examples in section 4 show how to construct the variable that contains the partial equilibrium effects for various different exercises.
The ge_gravity2 command
Syntax
Required variables
Options
Elasticities
New variables (universal gravity)
New variables (prototypical model)
Other options
results prints a table with percent changes for exports, imports, total trade, domestic trade, real output, and welfare.
universal solves the model with universal trade deficits and allows the user to set the
Stored results
Examples
All three examples use
A simulation of the ex ante effect of a trade agreement
In a first example, we simulate the effect of a free trade agreement. Suppose that we want to compute the expected effects of the North American Free Trade Agreement, a trade agreement signed by Canada, Mexico, and the United States that entered into force in 1994. Also, suppose that we expect the partial equilibrium effect of this trade agreement to be 0.5, meaning that countries that are part of this trade agreement are expected to increase their trade flows with other members by exp(0.5) ‒ 1 ≈ 65% if nothing else changes. The general equilibrium impact of this agreement can then be computed issuing the following commands in Stata:
After running this code, the command will print out a table that exhibits the change in trade flows, output, and welfare for all countries in the sample. We show only an excerpt from the table showing the first three lines and the countries involved in the trade agreement.
Because we specified the option
In this example, we have used a trade elasticity of 5.03, taken from the handbook chapter by Head and Mayer (2014). Values of 4 or 5 are common in policy studies quantifying the effects of free trade agreements. There is less consensus on the value of supply elasticity. Alvarez and Lucas (2007) suggest using a supply elasticity of 1, and Eaton and Kortum (2002) suggest a value of 3.76. In this example, we have taken the value of 1.24 from a calculation by Campos et al. (2023), who chose the supply elasticity as the midpoint of the supply elasticities implied by the 10th and 90th percentiles of the distribution of the range of intermediate goods shares for the sample of countries in the KLEMS database, as reported by Huo, Levchenko, and Pandalai-Nayar (2025).
The command in this example was run using the default algorithm. This means that the trade deficits in the counterfactual are assumed to be the same (in nominal terms) as in the baseline economy. This is not the only option. The
A quantification of the impact of time-varying border effects on welfare
We now turn to a more complicated example using several years of data. In this example, we use estimates of Spain’s “border thickness” by Campos, Reggio, and Timini (2023). In their article, they measure the border thickness (a measure of how difficult it is to trade internationally) of Spain during the Franco regime and compare it with the border thickness of a synthetic control for Spain that is calculated as an average of other countries. They report estimates of the welfare loss implied by Spain’s differential border thickness and interpret this welfare loss as the effect of the economic policies pursued by Spain in the postwar period until 1975.
In this example, we use the same database as before and calculate the welfare gain that Spain would have experienced if it had the border thickness of its synthetically constructed counterfactual. We do the calculation for several years. We use a trade elasticity of 4 and three different supply elasticity values: 0, 1, and 2. A trade elasticity of 4 and a supply elasticity of 0 correspond to the original simulations of Campos, Reggio, and Timini (2023).
To avoid having to use a loop to simulate the model for each year, we take advantage of the fact that the
The results in this last listing show how the welfare calculations depend on different values of the supply elasticity. Because we used the command with the by prefix, it is not possible to generate a results table. The values for variables other than welfare can be obtained using the options that begin with the
A simulation of a change in productivity
The command
We show only an excerpt from the resulting table showing the first three lines and the line for China.
Conclusions
This article introduced the
The
Looking ahead, we identify three promising directions for future development. First, the current version is limited to a single-sector framework. Extending the command to incorporate sectoral heterogeneity and input-output linkages, following the structure of Caliendo and Parro (2015), would enable more granular analysis of sector-specific policies such as tariffs, nontariff measures, and industrial policies.
Second,
Third, there is increasing academic and policy interest in understanding the interaction between trade and environmental regulation. Extending
Supplemental Material
sj-dta-1-stj-10.1177_1536867X251398335 - Supplemental material for ge_gravity2: A command for solving universal gravity models
Supplemental material, sj-dta-1-stj-10.1177_1536867X251398335 for ge_gravity2: A command for solving universal gravity models Rodolfo G. Campos, Iliana Reggio and Jacopo Timini by in The Stata Journal
Supplemental Material
sj-pdf-2-stj-10.1177_1536867X251398335 - Supplemental material for ge_gravity2: A command for solving universal gravity models
Supplemental material, sj-pdf-2-stj-10.1177_1536867X251398335 for ge_gravity2: A command for solving universal gravity models by Rodolfo G. Campos, Iliana Reggio and Jacopo Timini in The Stata Journal
Supplemental Material
sj-txt-1-stj-10.1177_1536867X251398335 - Supplemental material for ge_gravity2: A command for solving universal gravity models
Supplemental material, sj-txt-1-stj-10.1177_1536867X251398335 for ge_gravity2: A command for solving universal gravity models by Rodolfo G. Campos, Iliana Reggio and Jacopo Timini in The Stata Journal
Footnotes
6
We have greatly benefited from comments by Tom Zylkin. The views expressed in this article are those of the authors and therefore do not necessarily reflect those of the Banco de Espana or the Eurosystem.
Iliana Reggio acknowledges funding by Ministerio de Ciencia, Innovaci0n y Univer- sidades, grant number PID2024-161540NB-I00.
7
To install the software files as they existed at the time of publication of this article, type
A more recent version of the command may be available from the Statistical Software Components Archive by typing
Notes
About the authors
Rodolfo Campos is a senior economist at Banco de España. His current research interests include macroeconomics, social insurance, and international economics.
Iliana Reggio is an associate professor of economics at Universidad Autónoma de Madrid. Her current research interests include labor economics, international economics, and applied microeconomics.
Jacopo Timini is a senior economist at Banco de España. His current research interests include international economics and economic history.
References
Supplementary Material
Please find the following supplemental material available below.
For Open Access articles published under a Creative Commons License, all supplemental material carries the same license as the article it is associated with.
For non-Open Access articles published, all supplemental material carries a non-exclusive license, and permission requests for re-use of supplemental material or any part of supplemental material shall be sent directly to the copyright owner as specified in the copyright notice associated with the article.
