*! version 1.0 25Mar2024
help ge_gravity2

Title

ge_gravity2 -- Solves a gravity model within the universal gravity class (with a positive supply elasticity).

Syntax

ge_gravity2
exp_id imp_id flows partial
[if] [in], theta(#) [psi(#) gen_options other_options]

Required variables

exp_id identifies the origin

imp_id identifies the destination

flows contains bilateral trade flows

partial contains the "partial" estimate of the effect

Elasticities

theta(#) sets the trade elasticity, which must be strictly positive

psi(#) sets the aggregate supply elasticity, which must be nonnegative; optional, default is psi(0)

Generate variables

Universal gravity

gen_X(varname) generates counterfactual trade flows

gen_rp(varname) generates the change in real prices (p_hat/P_hat)

gen_y(varname) generates the change in income (Y_hat)

gen_x(varname) generates the change in trade flows (X_hat)

gen_p(varname) generates the change in output prices (p_hat)

gen_P(varname) generates the change in price indices (P_hat)

Prototypical trade model

gen_w(varname) generates the change in welfare (W_hat)

gen_q(varname) generates the change in real output (Q_hat)

gen_rw(varname) generates the change in real wages (w_hat/P_hat)

gen_nw(varname) generates the change in nominal wages (w_hat)

Other options

results prints a table with results

universal assumes universal trade deficits

multiplicative assumes trade deficits that imply E_hat = Y_hat

c_hat(matrix) changes supply shifters

a_hat(matrix) changes productivity

l_hat(matrix) changes the labor force

xi_hat(matrix) changes trade deficits

tol(#) sets the tolerance level to verify convergence of the price vector; must be a strictly positive real number; default is tol(1e-12)

max_iter(#) sets the maximum number of iterations to solve for the price vector; default is max_iter(1000000)

by is allowed; see prefix

Description

ge_gravity2 solves and simulates a gravity model with a positive supply elasticity, as decribed in the article by Campos, Reggio, and Timini (2024).
This new command can be used to simulate any model within the universal gravity framework defined by Allen et al (2020).
The ge_gravity2 command extends a pre-existing command with the name ge_gravity (Baier et al 2019; Zylkin, 2019).

Required variables, settings, and options

Required variables

exp_id specifies the variable that identifies the location of origin, for example ISO codes or names of countries. This variable can be a string variable or numeric. This variable cannot contain missing values.

imp_id specifies the variable that identifies the location of destination, for example ISO codes or names of countries. This variable a string variable or numeric. This variable cannot contain missing values.

flows contains bilateral trade flows. This variable contains the flow from the location identified as exp_id to the location identified as imp_id. This variable cannot contain missing values, but can contain zeros.

partial contains the "partial" estimate of the effect, typically obtained as a coefficient from a prior gravity estimation. This variable cannot contain missing values.

Elasticities

theta(#) sets the trade elasticity, which must be strictly positive.

psi(#) sets the aggregate supply elasticity, which must be nonnegative. If the option psi() is not specified, then the default is psi(0).

New variables (universal gravity)

gen_X(varname) generates counterfactual trade flows and places the result in a new variable called varname or overwrites this variable if it already exists.

gen_rp(varname) generates the change in real prices (p_hat/P_hat in the model) and places the result in a new variable called varname or overwrites this variable if it already exists.

gen_y(varname) generates the change in income (Y_hat in the model) and places the result in a new variable called varname or overwrites this variable if it already exists.

gen_x(varname) generates the change in trade flows (X_hat in the model) and places the result in a new variable called varname or overwrites this variable if it already exists.

gen_p(varname) generates the change in output prices (p_hat in the model) and places the result in a new variable called varname or overwrites this variable if it already exists.

gen_P(varname) generates the change in price indices (P_hat in the model) and places the result in a new variable called varname or overwrites this variable if it already exists.

New variables (prototypical model)

gen_w(varname) generates the change in welfare (W_hat in the model) and places the result in a new variable called varname or overwrites this variable if it already exists.

gen_q(varname) generates the change in real output (Q_hat in the model) and places the result in a new variable called varname or overwrites this variable if it already exists.

gen_rw(varname) generates the change in real wages (w_hat/P_hat in the model) and places the result in a new variable called varname or overwrites this variable if it already exists.

gen_nw(varname) generates the change in nominal wages (w_hat in the model) and places the result in a new variable called varname or overwrites this variable if it already exists.

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 option xi_hat.

multiplicative solves the model for trade deficits that imply E_hat = Y_hat (for backward compatibility with the multiplicative option of the ge_gravity command).

c_hat(matrix) changes supply shifters (c_hat in the model). Welfare will not be calculated if this option is used. This option may not be combined with the options a_hat or l_hat.
The default is that all elements of c_hat are set to one.

a_hat(matrix) changes productivity (A_hat in the prototypical trade model). This option may not be combined with the option c_hat.
The default is that all elements of a_hat are set to one.

l_hat(matrix) changes the labor force (L_hat in the prototypical trade model). This option may not be combined with the option c_hat.
The default is that all elements of l_hat are set to one.

xi_hat(matrix) changes trade deficits (xi_hat in the model). This option must be used in combination with the universal option.
If the universal option is selected and the xi_hat option is not used, then the command defaults to setting all elements of xi_hat to one.

tol(#) sets the tolerance level to verify convergence of the vector of output price changes. The tolerance level must be a strictly positive real number.
The default is tol(1e-12)

max_iter(#) sets the maximum number of iterations to solve for the vector of output price changes. The maximum number of iterations must be a positive integer.
The default is max_iter(1000000)

Remarks

The data must be a square database (i.e., the number of exporters must be the same as the numbers importers and their identities must coincide).
The data set must contain a string of numeric variable that identifies exporters and an additional variable of the same kind to identify importers.
Bilateral trade values must be nonnegative.

The command allows the use of the by prefix. If data are not sorted, then it is necessary to use the prefix bysort instead of by.

ge_gravity2 is an e-class ado. To view the list of stored elements issue the command ereturn list.
If ge_gravity2 is run with the by prefix, then only the elements e(theta) and e(psi) will be generated and stored.

Example

Load the example data:

use https://github.com/rolf-campos/ge_gravity2/raw/main/examples/ge_gravity2_example_data.dta, clear

describe

The variable iso_o identifies the exporter; the variable iso_d identifies the importer; the variable trade identifies trade flows from the exporter to the importer; and the variable year identifies the year in which a trade flow occurs.

Assume that a free trade agreement is expected to have a partial equilbrium effect of 0.5. Generate a variable with this value.

gen beta = 0.5

Generate a dummy variable for countries in the North American Free Trade Agreement (NAFTA).

gen nafta = (iso_o == "CAN" & (iso_d == "MEX" | iso_d == "USA")) | (iso_o == "MEX" & (iso_d == "CAN" | iso_d == "USA")) | iso_o == "USA" & (iso_d == "CAN" | iso_d == "MEX")

The partial equilibrium effect of NAFTA can be calculated as follows:

gen partial_effect = beta * nafta

Simulate the model with a trade elasticity of 5.03 and supply elasticity of 1.24 using data for the year 1990 and report the general equilibrium effects for all countries.

ge_gravity2 iso_o iso_d flow partial_effect if year==1990, theta(5.03) psi(1.24) results

Saved results

ge_gravity2 saves the following in e():

Scalars

e(theta) trade elasticity

e(psi) supply elasticity

e(N) number of locations

e(crit) convergence criterion achieved

e(n_iter) number of iterations performed

e(Xi_hat) scalar to ensure that trade deficits sum to zero

Macros

e(names) identifiers of locations

Matrices

e(results) N x 6 matrix of relative changes for key variables

e(X) N x N matrix of trade flows (baseline)

e(X_hat) N x N matrix of X_hat = X_prime / X

e(X_prime) N x N matrix of trade flows (counterfactual)

e(E) N x 1 matrix of expenditure (baseline)

e(Y) N x 1 matrix of income (baseline)

e(rp) N x 1 matrix of the change in real prices (p_hat / P_hat)

e(p_hat) N x 1 matrix of the change in output prices (p_hat)

e(P_hat) N x 1 matrix of the change in price indices (P_hat)

e(E_hat) N x 1 matrix of the E_hat = E_prime / E

e(Y_hat) N x 1 matrix of the Y_hat = Y_prime / Y

e(W_hat) N x 1 matrix of the W_hat = W_prime / W

e(Q_hat) N x 1 matrix of the Q_hat = Q_prime / Q

e(E_prime) N x 1 matrix of expenditure (counterfactual)

e(Y_prime) N x 1 matrix of income (counterfactual)

Authors

Rodolfo G. Campos & Iliana Reggio & Jacopo Timini

Banco de España and Universidad Autónoma de Madrid

Madrid, Spain

References

Allen, T., C. Arkolakis, and Y. Takahashi. 2020. Universal Gravity. Journal of Political Economy 128(2): 393-433.

Campos, R. G., I. Reggio, and J. Timini. 2024. ge_gravity2: a command for solving universal gravity models, arXiv:2404.09180 [econ.GN].

Baier, S. L., Y. V. Yotov, and T. Zylkin. 2019. On the widely differing effects of free trade agreements: Lessons from twenty years of trade integration. Journal of International Economics 116: 206–226.

Zylkin, T. 2019. GE_GRAVITY: Stata module to solve a simple general equilibrium one sector Armington-CES trade model. Statistical Software Components, Boston College Department of Economics. https://ideas.repec.org/c/boc/bocode/s458678.html.

Update: April - 2024