*! version 1.0.1 24aug2016

Title

ppml_panel_sg -- Fast PPML panel structural gravity estimation.

Syntax

ppml_panel_sg
depvar [indepvars]
[if] [in], exporter(exp_id) importer(imp_id) year(time_id) [options]

exp_id, imp_id, and time_id are variables that respectively identify
the origin, destination, and time period associated with each observation.

Description

ppml_panel_sg enables faster computation of the many fixed effects required for panel PPML structural gravity
estimation. In particular, it addresses the large number of “pair-wise” FEs needed to consistently identify the
effects of time-varying trade policies such as regional trade agreements (see, e.g., Baier & Bergstrand, 2007; Dai,
Yotov, & Zylkin, 2014). It also simultaneously absorbs the origin-by-time and destination-by-time FEs implied
by theory.

Some options and features of interest:

1. Programmed to run in Mata, making it much faster than existing Stata Poisson commands for estimating the
effects of trade policies.

2. Can store the estimated fixed effects in Stata’s memory (but as a single column each, rather than as a large
matrix with many zeroes).

3. In addition to the pair fixed effects, also readily allows for specifications with additional pair-specific linear
time trends.

4. Supports multi-way clustering of standard errors.

5. All fixed effects are also allowed to vary by industry, in case you wish to examine industry-level variation
in trade flows.

6. Can be used with strictly cross-sectional regressions (i.e., without pair fixed effects).

7. Performs Santos Silva & Tenreyro (2010)'s recommended check for possible non-existence
of estimates.

Main Options

nopair Use origin-time and destination-time fixed effects only (do not include pair fixed effects).

trend Add linear, pair-specific time trends.

symmetric Assume pair fixed effects apply symmetrically to flows in both directions, as in, e.g., Anderson
& Yotov (2016). Time trends, if specified, will also be symmetric.

industry(ind_id) ind_id is a varname identifying the industry associated with each observation. When an ind_id
is provided, the origin-time fixed effects become origin-industry-time effects, the destination-time
fixed effects become destination-industry-time effects, and pair-specific terms become
origin-destination-industry-specific.

offset(varname) Include varname as a regressor with coefficient constrained to be equal to 1.

cluster(clus_id) Specifies clustered standard errors, clustered by clus_id. The default is clustering by
exp_id-imp_id, unless nopair is enabled. For multi-way clustering, clus_id may be a varlist (max length is 4.)

robust Use robust standard errors. This is the default if nopair is enabled.

dropsingletons Drop “singletons” beforehad à la reghdfe.

multiway Automatic three-way clustering by exp_id, imp_id,
and time_id.

nosterr Do not compute standard errors (saves time if you only care about point estimates).

tolerance(#) The default tolerance is 1e-12.

maxiter(#) The default maximum number of iterations is 10,000.

noaccel Do not use “acceleration” when computing estimates.

verbose(#) Show iterative output for every #th iteration. Default is 0 (no output).

Guessing and Storing Values

These options allow you to store results for fixed effects in memory as well as use information from memory to
set up initial guesses. You may also utilize the “multilateral resistances” of Anderson & van Wincoop (2003).

olsguess Use reghdfe to initialize guesses for coefficient values.

guessB(str) Supply the name of a row vector with guesses for coefficient values.

guessD(varname) Guess initial values for the (exponentiated) set of pair fixed effects. Default is all 1s.

guessS(varname) Guess initial values for the (exponentiated) set of origin-time fixed effects. Default is the
share of depvar within each [ind_id-]time-id associated with each exp-id.

guessM(varname) Guess initial values for the (exponentiated) set of destination-time fixed effects. Default is the
share of depvar within each [ind_id-]time-id associated with each imp-id.

guessO(varname) Guess initial values for the set of “outward” multilateral resistances. Default is all 1s. Overrides
genS.

guessI(varname) Guess initial values for the set of “inward” multilateral resistances. Default is all 1s. Overrides genM.

guessTT(varname) Guess initial values for pair time trends. These are not exponentiated. Default is all 0s.

genD(newvar), genS(newvar), genM(newvar), genO(newvar), genI(newvar), and genTT(newvar):
These options store fixed effects and/or time trend parameters in memory as new variables.

To store predicted values, use predict(varname).

Check for Existence

As with ppml, ppml_panel_sg checks your specification beforehand to ensure that valid estimates will indeed exist.
These options affect how this check is performed.

nocheck Do not check for existence.

strict Applies a more conservative set of exclusion conditions when checking whether each
regressor may be including; mimics “strict” option from ppml.

keep Keeps observations that are perfectly predicted by excluded regressors; mimics “keep”
option from ppml.

Background

As a typical application, consider the following PPML regression:

X_ijt = exp[ln S_it + ln M_jt + ln D_ij + b×RTA_ijt] + e_ijt. (1)

X_ijt are international trade flows. i, j, and t are indices for origin, destination, and time. The goal is to consistently
estimate the average effect of RTA, a dummy variable for the presence of a regional trade agreement on trade
flows, using a “structural gravity” specification. The origin-time and destination-time fixed effects—S_it and M_jt—ensure
the theoretical restrictions implied by structural gravity are satisfied. The pair fixed effect—D ij—then
absorbs all time-invariant pair characteristics that may be correlated with the likelihood of forming an RTA.

Computationally, the biggest obstacle to estimating (1) is the pair fixed effect term D_ij. Because a unique D_ij must
be computed for each pair, the number of D_ij’s increases rapidly with the number of locations. For a balanced
international trade data set with 75 countries trading with each other over 10 years (not an especially large sample
for trade data), there will be on the order of 75^2 = 5,625 pair fixed effects that must be computed. In addition
(ignoring collinearity), we will also require 75×2×10 = 1,500 origin-time and destination-time effects. The
total number of parameters needed to estimate (1) (around 7,000) would normally require a long computing time
in Stata, likely several hours at least. If we push the number of locations and/or years further, we will quickly
approach Stata’s matsize limits, beyond which estimation becomes infeasible.

To date, this is the only available Stata command that will perform “fast” estimation of specifications such as (1)
using PPML. It works by manipulating the first order conditions of the Poisson to produce analytical expressions
for each of the fixed effects that can be computed via simple iteration. In this way, it both adapts and extends
existing procedures described in Guimarães & Portugal (2010) and Figueiredo, Guimarães, & Woodward (2015)
for estimating Poisson models with high dimensional fixed effects. These works and others are recommended
below for further reading.

Examples

To perform a basic panel estimation such as (1):

ppml_panel_sg trade rta, ex(iso_o) im(iso_d) y(year)

To add pair-specific time trends, i.e.,

X_ijt = exp[ln S_it + ln M_jt + ln D_ij + a_ij×t + b×RTA_ijt] + e_ijt, (2)

you would input:

ppml_panel_sg trade rta, ex(iso_o) im(iso_d) y(year) trend

If you want your pair fixed effects to be symmetric (i.e., D_ij = D_ji),
the syntax is:

ppml_panel_sg trade rta, ex(iso_o) im(iso_d) y(year) sym

To estimate coefficients of more traditional, time-invariant gravity variables, such as bilateral distance, use the
nopair option:

ppml_panel_sg trade ln_dist colony language contiguity rta, ex(iso_o) im(iso_d) y(year) nopair

Unlike the regressions with pair fixed effects, however, obtaining estimates for time-invariant regressors may not
be noticeably faster than existing methods (e.g., [R] glm, ppml) unless the number of origin-time and destination-time
effects is sufficiently large. You may also exclude the year ID in this last specification if your data includes only 1 year. An example data set and .do file is available from the the repec page for this command.

Advisory

This estimation command is strictly intended for settings where the dependent variable is spatial flows from one
set of locations to another (such as international trade or migration flows). It is not a generalized Poisson fixed
effects command. For more general problems that require Poisson estimation, you may try: [R] poisson, [R] glm, [R] xtpoisson,
ppml,
xtpqml, and/or poi2hdfe. For
an OLS command that can compute similar “gravity” specifications using
OLS, I recommend reghdfe.

As noted above, a useful feature of this command is that it will automatically drop any of your main covariates which
do not satisfy the condition for guaranteeing the existence of estimates in Santos Silva & Tenreyro (2010). This should
ensure convergence in most cases. However, you may still encounter convergence issues in cases where linear time trends are
specified and when the data contains many zeroes. Future versions will seek to address this latter issue.

This is version 1.1 of this command. If you believe you have found an error that can be replicated, or have other
suggestions for improvements, please feel free to contact the author.

Author

Thomas Zylkin

Department of Economics, Robins School of Business

University of Richmond

Email: tomzylkin@gmail.com

Suggested Citation

If you are using this command in your research I would appreciate if you would cite

• Larch, Mario, Wanner, Joschka, Yotov, Yoto V., Zylkin Thomas (2018), “Currency Unions and Trade: A
PPML Re-assessment with High-dimensional Fixed Effects”, Oxford Bulletin of Economics and Statistics (forthcoming).

The appendix of this paper provides a technical companion for those interested in understanding how the command works. Note that it replaces an older working paper from 2017 entitled “The Currency Union Effect: A PPML Re-assessment with High-dimensional Fixed Effects”.

Acknowledgements

I have adapted parts of my code from several other related commands. These include: poi2hdfe, by Paulo
Guimarães, SILS, by Keith Head and Thierry Mayer, and reghdfe by Sergio Correia. I give the utmost credit to
each of these authors for creating these programs and making their code available. The inclusion of multi-way clustering
in more recent versions of ppml_panel_sg (from v.1.1 onward) is thanks to contributions by Joschka Wanner and Mario Larch.

I also thank Yoto Yotov, Davin Chor, Sergio Correia, Paulo Guimarães, and João Santos Silva for kindly taking the time to
offer feedback and suggest improvements.

Further Reading

• Structural gravity: Anderson & van Wincoop (2003); Head & Mayer (2014)

• On the use of PPML to estimate gravity equations: Santos Silva & Tenreyro (2006); Fally (2015)

• Possible non-existence of Poisson MLE estimates: Santos Silva & Tenreyro (2010)

• Consistently estimating the effects of trade policies: Baier & Bergstrand (2007); Dai, Yotov, & Zylkin
(2014); Anderson & Yotov (2016); Piermartini & Yotov (2016)

• Estimating models with high dimensional fixed effects: Guimarães & Portugal (2010);
Figueiredo, Guimarães, & Woodward (2015); Correia (2016)

• Multi-way clustering: Cameron, Gelbach, & Miller (2011); Egger & Tarlea (2015)

• Singletons: Correia (2015)

References

Anderson, J. E. & van Wincoop, E. (2003),
"Gravity with Gravitas: A Solution to the Border Puzzle",
American Economic Review 93(1), 170-192.

Anderson, J. E. & Yotov, Y. V. (2016), “Terms of Trade and Global Efficiency Effects of Free Trade Agreements,
1990-2002”, Journal of International Economics 99(1), 279-298.

Baier, S. L. & Bergstrand, J. H. (2007), “Do free trade agreements actually increase members’ international
trade?”, Journal of International Economics 71(1), 72-95.

Cameron, A. C., Gelbach, J. B., & Miller, D. L. (2011), “Robust Inference With Multiway Clustering”,
Journal of Business & Economic Statistics 29(2), 238–249.

Correia, S. (2015), “Singletons, Cluster-Robust Standard Errors and Fixed Effects: A Bad Mix”.

Correia, S. (2016), “A Feasible Estimator for Linear Models with
Multi-Way Fixed Effects”.

Dai, M., Yotov, Y. V., & Zylkin, T. (2014), “On the trade-diversion effects of free trade agreements”,
Economics Letters 122(2), 321-325.

Egger, P.H., & Tarlea, F. (2015), “Multi-way clustering of standard errors in gravity models”,
Economics Letters 134, 144-147.

Fally, T. (2015), “Structural gravity and fixed effects”, Journal of International Economics 97(1), 76-85.

Figueiredo, O., Guimarães, P., & Woodward, D. (2015), “Industry localization, distance decay, and knowledge
spillovers: Following the patent paper trail”, Journal of Urban Economics 89(C), 21-31

Guimarães, P. & Portugal, P. (2010), “A simple feasible procedure to fit models with high-dimensional fixed
effects”, Stata Journal 10(4), 628-649.

Head, K. & Mayer, T. (2014), “Gravity equations: Workhorse, toolkit, and cookbook”,
Handbook of International Economics 4, 131-196.

Piermartini, R. & Yotov, Y. (2016), “Estimating Trade Policy Effects with Structural Gravity”, WTO Working Paper ERSD-2016-10.

Santos Silva, J. M. C. & Tenreyro, S. (2006), “The Log of Gravity”, Review of Economics and Statistics 88(4),
641–658.

Santos Silva, J. M. C. & Tenreyro, S. (2010), “On the existence of the maximum likelihood estimates in Poisson
regression”, Economics Letters 107(2), 310–312.