# Models For Markets in Equilibrium and Disequilibrium

The diseq package provides tools to estimate and analyze an equilibrium and four disequilibrium models. The equilibrium model can be estimated with either two-stage least squares or with full information maximum likelihood. The methods are asymptotically equivalent. The disequilibrium models are estimated using full information maximum likelihood. The likelihoods can be estimated both with independent and correlated demand and supply shocks and the optimization of the likelihoods can be performed either using analytic expressions or numerical approximations of their gradients.

# A quick model tour

The five models of the package are described by systems of simultaneous equations, with the equilibrium system being the only linear, while the disequilibrium systems being non-linear. All models specify the demand and the supply side of the market by a linear (in parameters) equation. The remaining equations of each model, if any, further specify the structure of the market.

## The equilibrium model

The equilibrium model adds the market-clearing condition to the demand and supply equations of the system. For the system to be identifiable, at least one variable in the demand side must not be present in the supply side and vice versa. This model assumes that the market observations always represent equilibrium points in which the demanded and supplied quantities are equal. The model can be estimated using two-stage least squares (Theil 1953) or full information maximum likelihood (Karapanagiotis, n.d.). Asymptotically, these methods are equivalent (Balestra and Varadharajan-Krishnakumar 1987).

## The basic disequilibrium model

The basic model is the simplest disequilibrium model of the package as it basically imposes no assumption on the structure of the market regarding price movements (Fair and Jaffee 1972; Maddala and Nelson 1974). In contrast with the equilibrium model, the market-clearing condition is replaced by the short-side rule, which stipulates that the minimum between the demanded and supplied quantities is observed. The econometrician does not need to specify whether an observation belongs to the demand or the supply side since the estimation of the model will allocate the observations on the demand or supply side so that the likelihood is maximized.

## The directional disequilibrium model

The directional model attaches an additional equation to the system of the basic model. The added equation is a sample separation condition based on the direction of the price movements (Fair and Jaffee 1972; Maddala and Nelson 1974). When prices increase at a given date, an observation is assumed to belong on the supply side. When prices fall, an observation is assumed to belong in the demand side. In short, this condition separates the sample before the estimation and uses this separation as additional information in the estimation procedure. Although, when appropriate, more information improves estimations, it also, when inaccurate, intensifies misspecification problems. Therefore, the additional structure of the directional model does not guarantee better estimates in comparison with the basic model.

## A disequilibrium model with deterministic price dynamics

The separation rule of the directional model classifies observations on the demand or supply-side based in a binary fashion, which is not always flexible, as observations that correspond to large shortages/surpluses are treated the same with observations that correspond to small shortages/ surpluses. The deterministic adjustment model of the package replaces this binary separation rule with a quantitative one (Fair and Jaffee 1972; Maddala and Nelson 1974). The magnitude of the price movements is analogous to the magnitude of deviations from the market-clearing condition. This model offers a flexible estimation alternative, with one extra degree of freedom in the estimation of price dynamics, that accounts for market forces that are in alignment with standard economic reasoning. By letting () approach zero, the equilibrium model can be obtained as a limiting case of this model.

## A disequilibrium model with stochastic price dynamics

The last model of the package extends the price dynamics of the deterministic adjustment model by adding additional explanatory variables and a stochastic term. The latter term in particular makes the price adjustment mechanism stochastic and, deviating from the structural assumptions of models ((DA)) and ((DM)), abstains from imposing any separation assumption on the sample (Maddala and Nelson 1974; Quandt and Ramsey 1978). The estimation of this model offers the highest degree of freedom, accompanied, however, by a significant increase in estimation complexity, which can hinder the stability of the procedure and the numerical accuracy of the outcomes.

# Installation and documentation

The released version of diseq can be installed from CRAN with:

``install.packages("diseq")``

The source code of the in-development version can be download from GitHub.

After installing it, there is a basic-usage example installed with it. To see it type the command

``vignette('basic_usage')``

Online documentation is available for both the released and in-development versions of the package. The documentation files can also accessed in `R` by typing

``?? diseq``

An overview of the package’s functionality was presented in the session Trends, Markets, Models of the useR!2021 conference. The recording of the session, including the talk for this package, can be found in the video that follows. The presentation slides of the talk are also available here.

# A practical example

This is a basic example that illustrates how a model of the package can be estimated. The package is loaded in the standard way.

``library(diseq)``

The example uses simulated data. The diseq package offers a function to simulate data from data generating processes that correspond to the models that the package provides.

``````model_tbl <- simulate_data(
"diseq_basic", 10000, 5,
-1.9, 12.9, c(2.1, -0.7), c(3.5, 6.25),
2.8, 10.2, c(0.65), c(1.15, 4.2),
NA, NA, c(NA),
seed = 42
)``````

Models are initialized by a constructor. In this example, a basic disequilibrium model is estimated. There are also other models available (see Design and functionality). The constructor sets the model’s parameters and performs the necessary initialization processes. The following variables specify this example’s parameterization.

• The models can be estimated both with panel and time series data. The constructor expects both a subject and a time identifier in order to perform the necessary initialization operations (these are respectively given by `id` and `date` in the simulated data of this example). The observation identification of the data is automatically generated by composing the subject and time identifiers. The resulting composite key is the combination of columns that uniquely identify a record of the dataset.

• The observable traded quantity variable (given by `Q` in this example’s simulated data). The demanded and supplied quantities are not observable and they identified either based on the market clearing condition or the short side rule.

• The price variable, which is named after `P` in the simulated data.

• The right hand side specifications of the demand and supply equations. The expressions are specified similarly to the expressions of formulas of linear models. Indicator variables and interactions are created automatically by the constructor.

• The verbosity level controls the level of messaging. The object displays

• error: always,
• warning: ≥ 1,
• info: ≥ 2,
• verbose: ≥ 3 and
• debug: ≥ 4.
``verbose <- 0``
• Should the model estimation allow for correlated demand and supply shocks?
``correlated_shocks <- TRUE``

The model is estimated with default options by a simple call. See the documentation of `estimate` for more details and options.

``````fit <- diseq_basic(
Q | P | id | date ~ P + Xd1 + Xd2 + X1 + X2 | P + Xs1 + X1 + X2,
model_tbl, correlated_shocks = correlated_shocks, verbose = verbose
)``````

The results can be inspected in the usual fashion via `summary`.

``summary(fit)``
``````## Basic Model for Markets in Disequilibrium
##   Demand RHS        : D_P + D_Xd1 + D_Xd2 + D_X1 + D_X2
##   Supply RHS        : S_P + S_Xs1 + S_X1 + S_X2
##   Short Side Rule   : Q = min(D_Q, S_Q)
##   Shocks            : Correlated
##   Nobs              : 50000
##   Sample Separation : Not Separated
##   Quantity Var      : Q
##   Price Var         : P
##   Key Var(s)        : id, date
##   Time Var          : date
##
## Maximum likelihood estimation
##   Method              : BFGS
##   Convergence Status  : success
##   Starting Values     :
##        D_P    D_CONST      D_Xd1      D_Xd2       D_X1       D_X2        S_P
##    2.20197   11.23889    0.27090   -0.08668    1.44062    4.46769    2.19995
##    S_CONST      S_Xs1       S_X1       S_X2 D_VARIANCE S_VARIANCE        RHO
##   10.22189    0.59623    1.43858    4.46673    1.00000    1.00000    0.00000
##
## Coefficients
##            Estimate Std. Error  z value      Pr(z)
## D_P        -1.92778   0.064387 -29.9405 5.849e-197
## D_CONST    12.71875   0.166572  76.3557  0.000e+00
## D_Xd1       2.10418   0.038621  54.4831  0.000e+00
## D_Xd2      -0.63963   0.029376 -21.7742 4.076e-105
## D_X1        3.49023   0.039875  87.5300  0.000e+00
## D_X2        6.29355   0.038586 163.1028  0.000e+00
## S_P         2.80653   0.012009 233.7023  0.000e+00
## S_CONST    10.16444   0.049438 205.5993  0.000e+00
## S_Xs1       0.67821   0.009762  69.4737  0.000e+00
## S_X1        1.12951   0.010447 108.1137  0.000e+00
## S_X2        4.19819   0.010354 405.4635  0.000e+00
## D_VARIANCE  1.01778   0.030312  33.5767 3.669e-247
## S_VARIANCE  1.00263   0.007420 135.1273  0.000e+00
## RHO        -0.02388   0.037672  -0.6338  5.262e-01
##
## -2 log L: 138110``````

# Design and functionality

The equilibrium model can be estimated either using two-stage least squares or full information maximum likelihood. The two methods are asymptotically equivalent. The class for which both of these estimation methods are implemented is

• `equilibrium_model`.

In total, there are four disequilibrium models, which are all estimated using full information maximum likelihood. By default, the estimations use analytically calculated gradient expressions, but the user has the ability to override this behavior. The classes that implement the four disequilibrium models are

• `diseq_basic`,
• `diseq_directional`,
• `diseq_deterministic_adjustment`, and
• `diseq_stochastic_adjustment`.

The package organizes these classes in a simple object oriented hierarchy.

Concerning post estimation analysis, the package offers functionality to calculate

• shortage probabilities,
• marginal effects on shortage probabilities,
• point estimates of normalized shortages,
• point estimates of relative shortages,
• aggregate demand and supply,
• post-estimation classification of observations in demand and supply,
• heteroscedasticity-adjusted (Huber-White) standard errors, and
• clustered standard errors.

# Alternative packages

The estimation of the basic model is also supported by the package Disequilibrium. By default the Disequilibrium package numerically approximates the gradient when optimizing the likelihood. In contrast, diseq uses analytically calculated expressions for the likelihood, which can reduce the duration of estimating the model. In addition, it allows the user to override this behavior and use the numerically approximated gradient. There is no alternative package that supports the out-of-the-box estimation of the other three disequilibrium models of diseq.

# Planned extensions

The package is planned to be expanded in the following ways:

1. The package should become more inclusive by adding additional market models.
2. Single-command functionality for the market-clearing tests (e.g. (Karapanagiotis, n.d.; Hwang 1980; Quandt 1978)) should be included in the package.
3. Alternative estimation methods (e.g (Zilinskas and Bogle 2006; Quandt and Ramsey 1978)) could also be implemented.

# Contributors

Pantelis Karapanagiotis

Feel free to join, share, contribute, distribute.

# References

Balestra, Pietro, and Jayalakshmi Varadharajan-Krishnakumar. 1987. “Full information estimations of a system of simultaneous equations with error component structure.” Econometric Theory 3 (2): 223–46. https://doi.org/10.1017/S0266466600010318.

Fair, Ray C., and Dwight M. Jaffee. 1972. “Methods of Estimation for Markets in Disequilibrium.” Econometrica 40 (3): 497. https://doi.org/10.2307/1913181.

Hwang, Hae-shin. 1980. “A test of a disequilibrium model.” Journal of Econometrics 12 (3): 319–33. https://doi.org/10.1016/0304-4076(80)90059-7.

Karapanagiotis, Pantelis. n.d. “The Assessment of Market-Clearing as a Model Selection Problem.” Working Paper. https://doi.org/10.2139/ssrn.3525622.

Maddala, G. S., and Forrest D. Nelson. 1974. “Maximum Likelihood Methods for Models of Markets in Disequilibrium.” Econometrica 42 (6): 1013. https://doi.org/10.2307/1914215.

Quandt, Richard E. 1978. “Tests of the Equilibrium vs. Disequilibrium Hypotheses.” International Economic Review 19 (2): 435. https://doi.org/10.2307/2526311.

Quandt, Richard E., and James B. Ramsey. 1978. “Estimating mixtures of normal distributions and switching regressions.” Journal of the American Statistical Association 73 (364): 730–38. https://doi.org/10.1080/01621459.1978.10480085.

Theil, H. 1953. “Repeated least squares applied to complete equation systems.” The Hague: Central Planning Bureau, 2–5.

Zilinskas, Julius, and Ian David Lockhart Bogle. 2006. “Balanced random interval arithmetic in market model estimation.” European Journal of Operational Research 175 (3): 1367–78. https://doi.org/10.1016/j.ejor.2005.02.013.