ols: Ordinary Least Squares (OLS)

View source: R/ols.R

olsR Documentation

Ordinary Least Squares (OLS)

Description

ols estimates gravity models in their traditional form via Ordinary Least Squares (ols). It does not consider Multilateral Resistance terms.

Usage

ols(
  dependent_variable,
  distance,
  additional_regressors = NULL,
  income_origin,
  income_destination,
  code_origin,
  code_destination,
  uie = FALSE,
  robust = FALSE,
  data,
  ...
)

Arguments

dependent_variable

(Type: character) name of the dependent variable.

If uie = TRUE the dependent variable is divided by the product of unilateral incomes (e.g. income_origin and income_destination) and logged afterwards.

If uie=FALSE the dependent variable is logged directly. The transformed variable is then used as the dependent variable and the logged income variables are used as independent variables in the estimation.

distance

(Type: character) name of the distance variable that should be taken as the key independent variable in the estimation. The distance is logged automatically when the function is executed.

additional_regressors

(Type: character) names of the additional regressors to include in the model (e.g. a dummy variable to indicate contiguity). Unilateral metric variables such as GDPs can be added but those variables have to be logged first. Interaction terms can be added.

Write this argument as c(contiguity, common currency, ...). By default this is set to NULL.

income_origin

(Type: character) origin income variable (e.g. GDP) in the dataset.

income_destination

(Type: character) destination income variable (e.g. GDP) in the dataset.

code_origin

(Type: character) country of origin variable (e.g. ISO-3 country codes). The variables are grouped using this parameter.

code_destination

(Type: character) country of destination variable (e.g. country ISO-3 codes). The variables are grouped using this parameter.

uie

(Type: logical) Dtermines whether the parameters are to be estimated assuming unitary income elasticities. The default value is set to FALSE.

robust

(Type: logical) whether robust fitting should be used. By default this is set to FALSE.

data

(Type: data.frame) the dataset to be used.

...

Additional arguments to be passed to the function.

Details

ols estimates gravity models in their traditional, additive, form via Ordinary Least Squares using the lm function. Multilateral Resistance terms are not considered by this function.

As the coefficients for the country's incomes were often found to be close to unitary and unitary income elasticities are in line with some theoretical foundations on international trade, it is sometimes assumed that the income elasticities are equal to unity.

In order to allow for the estimation with and without the assumption of unitary income elasticities, the option uie is built into ols with the default set to FALSE.

ols estimation can be used for both, cross-sectional and panel data. Nonetheless, the function is designed to be consistent with the Stata code for cross-sectional data provided at the website Gravity Equations: Workhorse, Toolkit, and Cookbook when choosing robust estimation.

The function ols was therefore tested for cross-sectional data. For the use with panel data no tests were performed. Therefore, it is up to the user to ensure that the functions can be applied to panel data.

Depending on the panel dataset and the variables - specifically the type of fixed effects - included in the model, it may easily occur that the model is not computable. Also, note that by including bilateral fixed effects such as country-pair effects, the coefficients of time-invariant observables such as distance can no longer be estimated.

Depending on the specific model, the code of the respective function may has to be changed in order to exclude the distance variable from the estimation.

At the very least, the user should take special care with respect to the meaning of the estimated coefficients and variances as well as the decision about which effects to include in the estimation. When using panel data, the parameter and variance estimation of the models may have to be changed accordingly.

For a comprehensive overview of gravity models for panel data see \insertCiteEgger2003;textualgravity, \insertCiteGomez-Herrera2013;textualgravity and \insertCiteHead2010;textualgravity as well as the references therein.

Value

The function returns the summary of the estimated gravity model as an lm-object.

References

For more information on gravity models, theoretical foundations and estimation methods in general see

\insertRef

Anderson1979gravity

\insertRef

Anderson2001gravity

\insertRef

Anderson2010gravity

\insertRef

Baier2009gravity

\insertRef

Baier2010gravity

\insertRef

Feenstra2002gravity

\insertRef

Head2010gravity

\insertRef

Head2014gravity

\insertRef

Santos2006gravity

and the citations therein.

See Gravity Equations: Workhorse, Toolkit, and Cookbook for gravity datasets and Stata code for estimating gravity models.

For estimating gravity equations using panel data see

\insertRef

Egger2003gravity

\insertRef

Gomez-Herrera2013gravity

and the references therein.

See Also

lm, coeftest, vcovHC

Examples

# Example for CRAN checks:
# Executable in < 5 sec
library(dplyr)
data("gravity_no_zeros")

# Choose 5 countries for testing
countries_chosen <- c("AUS", "CHN", "GBR", "BRA", "CAN")
grav_small <- filter(gravity_no_zeros, iso_o %in% countries_chosen)

fit <- ols(
  dependent_variable = "flow",
  distance = "distw",
  additional_regressors = c("rta", "contig", "comcur"),
  income_origin = "gdp_o",
  income_destination = "gdp_d",
  code_origin = "iso_o",
  code_destination = "iso_d",
  uie = FALSE,
  robust = FALSE,
  data = grav_small
)

gravity documentation built on May 2, 2023, 9:13 a.m.