R/ge_gravity.R
ge_gravity.Rd
ge_gravity
solves for general equilibrium effects of changes in trade policies
using a one sector Armington-CES trade model. It uses a simple fixed point
algorithm that allows for fast computation that makes this program
ideal for bootstrapping confidence intervals for general equilibrium simulations
based on prior gravity estimates of FTAs or other similar variables.
Examples of references that conduct general equilibrium analysis based on FTA estimates in this way include Egger, Larch, Staub, & Winkelmann (2011), Anderson & Yotov (2016), and Baier, Yotov, & Zylkin (2019). Yotov, Piermartini, Monteiro, & Larch (2016) provide a detailed survey and introduction to the topic.
ge_gravity(exp_id, imp_id, flows, beta, theta = 1, mult = FALSE, data = list())
String representation of the exporter/origin country associated with each observation. This is arbitrary and for organization purposes only, i.e. AUS, Australia
String representation of the importer/destination country associated with each observation. This is arbitrary and for organization purposes only, i.e. AUS, Australia
Observed trade flows in the data for the year being used as the baseline for the counterfactual.
An input reflecting the "partial" change in trade, typically obtained as a coefficient from a prior gravity estimation.
Overall trade elasticity
If true, assume that national expenditure is a fixed multiple of national output, as in Anderson & Yotov (2016). Otherwise (and by default), handle unbalances in the data by treating the trade balance as an additive component of national expenditure (see below).
A list to which we should add the new values. By default, this is an empty list. Note that this will be converted to a named dataframe on output.
A dataframe element containing resulting estimations of impacts. Specifically, it returns results for general equilibrium changes in trade flows, welfare, and real wages as a result of the change in trade frictions. If `data` is specified, the results will be added as columns.
This data will include the following:
new_trade
: The new level of trade for each pair of countries.
welfare
: The exporter's change in welfare (new/old level of welfare)
real_wage
: The exporter's change in real wage (new/old real wage).
Note: this is generally different from the change in welfare
unless either trade is balanced or the "multiplicative" option is chosen.
nom_wage
: The exporter's change in nominal wage (new/old nom wage).
price_index
: The exporter's change in price index (new/old price index)
Please see browseVignettes("GEGravity")
for additional details.
Please see browseVignettes("GEGravity")
for information on references and sources.
The vignettes allow you to access very explanatory RMD files to augment documentation. Please check them out!
# For a detailed explanation, check out the vignettes (see \code{browseVignettes("GEGravity")})
# Foreign trade subset
f_trade <- TradeData0014[TradeData0014$exporter != TradeData0014$importer,]
# Normalize trade data to unit interval
f_trade$trade <- f_trade$trade / max(f_trade$trade)
# classify FEs for components to be absorbed (finding variable interactions)
f_trade$exp_year <- interaction(f_trade$expcode, f_trade$year)
f_trade$imp_year <- interaction(f_trade$impcode, f_trade$year)
f_trade$pair <- interaction(f_trade$impcode, f_trade$expcode)
# Fit generalized linear model based on specifications
partials <- alpaca::feglm(
formula = trade ~ eu_enlargement + other_fta | exp_year + imp_year + pair,
data = f_trade,
family = poisson()
)$coefficient # We just need the coefficients for computation
# Sort trade matrix to make it easier to find imp/exp pairs
t_trade <- TradeData0014[order(
TradeData0014$exporter,
TradeData0014$importer,
TradeData0014$year
),]
t_trade$eu_effect <- NA # Column for the partial effect of EU membership for new EU pairs
i <- 1
# Effect of EU entrance on country based on partial, if entry happened
invisible(by(t_trade, list(t_trade$expcode, t_trade$impcode), function(row) {
# Was a new EU pair created within time span?
t_trade[i:(i+nrow(row)-1), "eu_effect"] <<- diff(row$eu_enlargement, lag=nrow(row)-1)
i <<- i + nrow(row)
}))
# If added to EU, give it the computed partial eu_enlargement coefficient as the effect
t_trade$eu_effect = t_trade$eu_effect * partials[1]
# Data to be finally fed to the function
data <- t_trade[t_trade$year == 2000,]
## Running Actual Computations
## Difference between w_mult and w_o_mult is how trade balance is considered
## mult = TRUE assumes multiplicative trade balances; false assumes additive
w_mult <- ge_gravity(
exp_id = data$expcode, # Origin country associated with each observation
imp_id = data$impcode, # Destination country associated with each observation
flows = data$trade, # Observed trade flows for the baseline year
beta = data$eu_effect, # "Partial" trade change; coefficient from gravity estimation
theta = 4, # Trade elasticity
mult = TRUE, # Assume national expenditure is fixed multiple of nat. output
data = data
)
w_o_mult <- ge_gravity(
data$expcode, # Origin country associated with each observation
data$impcode, # Destination country associated with each observation
data$trade, # Observed trade flows for the baseline year
data$eu_effect, # "Partial" change in trade; coefficient from gravity estimation
4, # Trade elasticity
FALSE, # Assume trade balance is additive component of nat. expenditure
data
)