The R Package diseq:
Estimation Methods for Markets in Equilibrium and Disequilibrium

Pantelis Karapanagiotis

@pi_kappa_

EBS University Wiesbaden, Leibniz Institute for Financial Research SAFE

Markets in Equilibrium

  • Equilibrium concepts are analytically convenient.
  • Equilibrium models constitute reasonable econometric approximations on many occasions.

Markets in Disequilibrium

  • On others… not so much

Market Clearing vs Short Side Rule

equilibrium_model.png

\begin{align*} Q_{nt} &= D_{nt} = S_{nt} \end{align*}

diseq_basic.png

\begin{align*} Q_{nt} &= \min\{D_{nt},S_{nt}\} \end{align*}

Design goals

  • Simple, approachable, common estimation interface for all market models.
  • Fast estimation routines.
  • Post estimation analytics.

Implementation

  • Simple, approachable, common estimation interface for all market models.
    • Object oriented design architecture. Polymorphic estimation (and other) calls.

  • Fast estimation routines.
    • Estimation using analytic gradient expressions by default.
    • Performance gains are documented by extensive benchmarking estimations with simulated data.

  • Post estimation analytics.
    • Predicted demanded and supplied quantities. Aggregation.
    • Analysis of shortages.
    • Marginal effects.

Architecture overview

design.png

Basic model estimation benchmarks

diseq_basic_obs_benchmark.png
diseq_basic_params_benchmark.png

Model specification

key_columns <- c("ID", "TREND")
quantity_column <- "HS"
price_column <- "RM"
time_column <- "TREND"
demand_specification <- "TREND + W + CSHS + L1RM + L2RM + MONTH"
supply_specification <- "TREND + W + L1RM + MA6DSF + MA3DHF + MONTH"
correlated_shocks <- FALSE
verbose <- 3

Model initialization

equilibrium_mdl <- new(
  "equilibrium_model",
  key_columns, quantity_column, price_column,
  paste(price_column, demand_specification, sep = "+"),
  paste(price_column, supply_specification, sep = "+"),
  house_data,
  correlated_shocks = correlated_shocks, verbose = verbose)
basic_mdl <- new(
  "diseq_basic",
  key_columns, quantity_column, price_column,
  paste(price_column, demand_specification, sep = "+"),
  paste(price_column, supply_specification, sep = "+"),
  house_data,
  correlated_shocks = correlated_shocks, verbose = verbose)
directional_mdl <- new(
  "diseq_directional",
  key_columns, time_column, quantity_column, price_column,
  paste(price_column, demand_specification, sep = "+"),
  supply_specification,
  house_data,
  correlated_shocks = correlated_shocks, verbose = verbose)
deterministic_adjustment_mdl <- new(
  "diseq_deterministic_adjustment",
  key_columns, time_column, quantity_column, price_column,
  paste(price_column, demand_specification, sep = "+"),
  paste(price_column, supply_specification, sep = "+"),
  house_data,
  correlated_shocks = correlated_shocks, verbose = verbose)

Model estimation

optimization_control <- list(maxit = 50000)
equilibrium_est <- estimate(equilibrium_mdl, control = optimization_control)
basic_est <- estimate(basic_mdl, control = optimization_control,
		      start = equilibrium_est@coef)
directional_est <- estimate(directional_mdl, method = "Nelder-Mead",
			    control = optimization_control)
deterministic_adjustment_est <- estimate(deterministic_adjustment_mdl,
					 control = optimization_control)
Coefficients D_RM D_CONST D_TREND D_W D_CSHS D_L1RM D_L2RM S_RM S_CONST S_TREND S_W S_L1RM S_MA6DSF S_MA3DHF RM_DIFF D_VARIANCE S_VARIANCE
equilibrium_est -5.8707 (0.00) -3.5384 (0.00) -2.2583 (0.00) 3.2213 (0.01) 0.0211 (0.00) 7.8750 (0.00) -1.9786 (0.00) 0.9617 (0.00) -57.8048 (0.00) -0.1787 (0.00) 2.9853 (0.00) -0.9008 (0.00) 0.0510 (0.00) 0.0408 (0.00) NA (NA) 805.1174 (0.00) 116.1149 (0.00)
basic_est -8.1205 (0.00) -3.3352 (0.00) -34.7577 (0.00) -32.2648 (0.00) 0.2031 (0.00) 14.7104 (0.00) -3.1749 (0.33) 0.4015 (0.06) -77.7746 (0.00) -0.1416 (0.00) 3.2784 (0.00) -0.3259 (0.13) 0.0522 (0.00) 0.0393 (0.00) NA (NA) 786.2419 (0.00) 99.5034 (0.00)
directional_est 0.9294 (0.00) 104.2485 (0.00) 3.4024 (0.00) 5.4002 (0.00) -0.0259 (0.00) 0.3572 (0.41) -1.5413 (0.00) NA (NA) -39.5322 (0.00) -0.0714 (0.00) 3.7903 (0.00) 0.0223 (0.02) 0.0388 (0.00) 0.0258 (0.00) NA (NA) 44.1599 (0.00) 25.2621 (0.00)
deterministic_adjustment_est -4.5422 (0.00) 13.6044 (0.00) -2.6245 (0.00) 2.5180 (0.04) 0.0244 (0.00) 6.2722 (0.00) -1.6969 (0.00) 0.6201 (0.00) -63.6607 (0.00) -0.1706 (0.00) 2.9240 (0.00) -0.5449 (0.01) 0.0494 (0.00) 0.0343 (0.00) 1.6103 (0.01) 810.0375 (0.00) 110.5647 (0.00)
Coefficients D_RM D_CONST D_TREND D_W D_CSHS D_L1RM D_L2RM S_RM S_CONST S_TREND S_W S_L1RM S_MA6DSF S_MA3DHF RM_DIFF D_VARIANCE S_VARIANCE
equilibrium_est -5.8707 (0.00) -3.5384 (0.00) -2.2583 (0.00) 3.2213 (0.01) 0.0211 (0.00) 7.8750 (0.00) -1.9786 (0.00) 0.9617 (0.00) -57.8048 (0.00) -0.1787 (0.00) 2.9853 (0.00) -0.9008 (0.00) 0.0510 (0.00) 0.0408 (0.00) NA (NA) 805.1174 (0.00) 116.1149 (0.00)
basic_est -8.1205 (0.00) -3.3352 (0.00) -34.7577 (0.00) -32.2648 (0.00) 0.2031 (0.00) 14.7104 (0.00) -3.1749 (0.33) 0.4015 (0.06) -77.7746 (0.00) -0.1416 (0.00) 3.2784 (0.00) -0.3259 (0.13) 0.0522 (0.00) 0.0393 (0.00) NA (NA) 786.2419 (0.00) 99.5034 (0.00)
directional_est 0.9294 (0.00) 104.2485 (0.00) 3.4024 (0.00) 5.4002 (0.00) -0.0259 (0.00) 0.3572 (0.41) -1.5413 (0.00) NA (NA) -39.5322 (0.00) -0.0714 (0.00) 3.7903 (0.00) 0.0223 (0.02) 0.0388 (0.00) 0.0258 (0.00) NA (NA) 44.1599 (0.00) 25.2621 (0.00)
deterministic_adjustment_est -4.5422 (0.00) 13.6044 (0.00) -2.6245 (0.00) 2.5180 (0.04) 0.0244 (0.00) 6.2722 (0.00) -1.6969 (0.00) 0.6201 (0.00) -63.6607 (0.00) -0.1706 (0.00) 2.9240 (0.00) -0.5449 (0.01) 0.0494 (0.00) 0.0343 (0.00) 1.6103 (0.01) 810.0375 (0.00) 110.5647 (0.00)
Coefficients D_RM D_CONST D_TREND D_W D_CSHS D_L1RM D_L2RM S_RM S_CONST S_TREND S_W S_L1RM S_MA6DSF S_MA3DHF RM_DIFF D_VARIANCE S_VARIANCE
equilibrium_est -5.8707 (0.00) -3.5384 (0.00) -2.2583 (0.00) 3.2213 (0.01) 0.0211 (0.00) 7.8750 (0.00) -1.9786 (0.00) 0.9617 (0.00) -57.8048 (0.00) -0.1787 (0.00) 2.9853 (0.00) -0.9008 (0.00) 0.0510 (0.00) 0.0408 (0.00) NA (NA) 805.1174 (0.00) 116.1149 (0.00)
basic_est -8.1205 (0.00) -3.3352 (0.00) -34.7577 (0.00) -32.2648 (0.00) 0.2031 (0.00) 14.7104 (0.00) -3.1749 (0.33) 0.4015 (0.06) -77.7746 (0.00) -0.1416 (0.00) 3.2784 (0.00) -0.3259 (0.13) 0.0522 (0.00) 0.0393 (0.00) NA (NA) 786.2419 (0.00) 99.5034 (0.00)
directional_est 0.9294 (0.00) 104.2485 (0.00) 3.4024 (0.00) 5.4002 (0.00) -0.0259 (0.00) 0.3572 (0.41) -1.5413 (0.00) NA (NA) -39.5322 (0.00) -0.0714 (0.00) 3.7903 (0.00) 0.0223 (0.02) 0.0388 (0.00) 0.0258 (0.00) NA (NA) 44.1599 (0.00) 25.2621 (0.00)
deterministic_adjustment_est -4.5422 (0.00) 13.6044 (0.00) -2.6245 (0.00) 2.5180 (0.04) 0.0244 (0.00) 6.2722 (0.00) -1.6969 (0.00) 0.6201 (0.00) -63.6607 (0.00) -0.1706 (0.00) 2.9240 (0.00) -0.5449 (0.01) 0.0494 (0.00) 0.0343 (0.00) 1.6103 (0.01) 810.0375 (0.00) 110.5647 (0.00)
Coefficients D_RM D_CONST D_TREND D_W D_CSHS D_L1RM D_L2RM S_RM S_CONST S_TREND S_W S_L1RM S_MA6DSF S_MA3DHF RM_DIFF D_VARIANCE S_VARIANCE
equilibrium_est -5.8707 (0.00) -3.5384 (0.00) -2.2583 (0.00) 3.2213 (0.01) 0.0211 (0.00) 7.8750 (0.00) -1.9786 (0.00) 0.9617 (0.00) -57.8048 (0.00) -0.1787 (0.00) 2.9853 (0.00) -0.9008 (0.00) 0.0510 (0.00) 0.0408 (0.00) NA (NA) 805.1174 (0.00) 116.1149 (0.00)
basic_est -8.1205 (0.00) -3.3352 (0.00) -34.7577 (0.00) -32.2648 (0.00) 0.2031 (0.00) 14.7104 (0.00) -3.1749 (0.33) 0.4015 (0.06) -77.7746 (0.00) -0.1416 (0.00) 3.2784 (0.00) -0.3259 (0.13) 0.0522 (0.00) 0.0393 (0.00) NA (NA) 786.2419 (0.00) 99.5034 (0.00)
directional_est 0.9294 (0.00) 104.2485 (0.00) 3.4024 (0.00) 5.4002 (0.00) -0.0259 (0.00) 0.3572 (0.41) -1.5413 (0.00) NA (NA) -39.5322 (0.00) -0.0714 (0.00) 3.7903 (0.00) 0.0223 (0.02) 0.0388 (0.00) 0.0258 (0.00) NA (NA) 44.1599 (0.00) 25.2621 (0.00)
deterministic_adjustment_est -4.5422 (0.00) 13.6044 (0.00) -2.6245 (0.00) 2.5180 (0.04) 0.0244 (0.00) 6.2722 (0.00) -1.6969 (0.00) 0.6201 (0.00) -63.6607 (0.00) -0.1706 (0.00) 2.9240 (0.00) -0.5449 (0.01) 0.0494 (0.00) 0.0343 (0.00) 1.6103 (0.01) 810.0375 (0.00) 110.5647 (0.00)

The R Package diseq:
Estimation Methods for Markets in Equilibrium and Disequilibrium

Pantelis Karapanagiotis

References

  • [mayer2015] Mayer, Madden, Jin & Tran, Modelling OECD broadband subscriptions in disequilibrium, Technological Forecasting and Social Change, 90(PB), 476-486 (2015). doi.
  • [loberto2016] Loberto & Zollino, Housing and Credit Markets in Italy in Times of Crisis, Bank of Italy, (2018).
  • [quandt1978estimating] Quandt & Ramsey, Estimating mixtures of normal distributions and switching regressions, Journal of the American Statistical Association, 73(364), 730-738 (1978). doi.
  • [zilinskas2006] Zilinskas & Bogle, Balanced random interval arithmetic in market model estimation, European Journal of Operational Research, 175(3), 1367-1378 (2006). doi.
  • [quandt1978tests] Quandt, Tests of the Equilibrium vs. Disequilibrium Hypotheses, International Economic Review, 19(2), 435 (1978). doi.
  • [hwang1980] Hwang, A test of a disequilibrium model, Journal of Econometrics, 12(3), 319-333 (1980). doi.
  • [blpestimator2019] BLPestimatoR, BLP Demand Estimation, By Brunner D., Weiser C. & Romahn A. Distributed by CRAN, (2019).
  • [miceconaids2017] MicEconAids, Demand analysis with the almost ideal demand system, By Henningsen A. Distributed by CRAN, (2017).
  • [disequilibrium2020] Disequilibrium, Disequilibrium Models, By Latshaw N. & Guggisberg M. Distributed by CRAN, (2020).
  • [henningsen2007] Henningsen & Hamann, systemfit : A Package for Estimating Systems of Simultaneous Equations in R, Journal of Statistical Software, 23(4), 1-40 (2007). link. doi.
  • [bbmle2020] Bbmle, Tools for General Maximum Likelihood Estimation, By Bolker B, R Development Core Team & Giné-Vázquez I. Distributed by CRAN, (2020).
  • [zellner1962] Zellner & Theil, Three-Stage Least Squares: Simultaneous Estimation of Simultaneous Equations, Econometrica, 30(1), 54 (1962). doi.
  • [balestra1987] Balestra & Varadharajan-Krishnakumar, Full information estimations of a system of simultaneous equations with error component structure, Econometric Theory, 3(2), 223-246 (1987). doi.
  • [fair1972] Fair & Jaffee, Methods of Estimation for Markets in Disequilibrium, Econometrica, 40(3), 497 (1972). doi.
  • [amemiya1974] Amemiya, A Note on a Fair and Jaffee Model, Econometrica, 42(4), 759 (1974). doi.
  • [maddala1974] Maddala & Nelson, Maximum Likelihood Methods for Models of Markets in Disequilibrium, Econometrica, 42(6), 1013 (1974). doi.
  • [maddala1986] Maddala, Disequilibrium, self-selection, and switching models, , 3, in: Handbook of Econometrics (1986).
  • [userp] Economic Report of the President, President and Council of Economic Advisers (U.S.), (1947).
  • [fair1971] Fair, A short-run forecasting model of the United States economy, Heath Lexington Books (1971).
  • [usfrb] Federal Reserve Bulletin, Board of Governors of the Federal Reserve System (U.S.), 1935- and Federal Reserve Board, (1914).

Appendix

Previous research and related software

Market models

The equilibrium model

\begin{align} \begin{aligned} D_{nt} &= X_{d,nt}'\beta_{d} + P_{nt}\alpha_{d} + u_{d,nt}, \\ S_{nt} &= X_{s,nt}'\beta_{s} + P_{nt}\alpha_{s} + u_{s,nt}, \\ Q_{nt} &= D_{nt} = S_{nt} . \end{aligned} \tag{E} \label{eq:model:equilibrium} \end{align}

equilibrium_model.png

  • Assumes that market clearing always holds.
  • Estimated with 2SLS, 3SLS, and FIML. The last two methods are asymptotically equivalent.

The basic model

\begin{align} \begin{aligned} D_{nt} &= X_{d,nt}'\beta_{d} + u_{d,nt}, \\ S_{nt} &= X_{s,nt}'\beta_{s} + u_{s,nt}, \\ Q_{nt} &= \min\{D_{nt},S_{nt}\} . \end{aligned} \tag{B} \label{eq:model:basic} \end{align}

diseq_basic.png

  • Instead of market clearing, the short side rule governs the market. No price dynamics.

The directional model

\begin{align} \begin{aligned} D_{nt} &= X_{d,nt}'\beta_{d} + u_{d,nt}, \\ S_{nt} &= X_{s,nt}'\beta_{s} + u_{s,nt}, \\ Q_{nt} &= \min\{D_{nt},S_{nt}\}, \\ \Delta P_{nt} &\ge 0 \implies D_{nt} \ge S_{nt}. \end{aligned} \tag{D} \label{eq:model:directional} \end{align}

diseq_directional.png

  • Sample separation based on price changes (One directional assumption however).

The deterministic adjustment model

\begin{align} \begin{aligned} D_{nt} &= X_{d,nt}'\beta_{d} + P_{nt}\alpha_{d} + u_{d,nt}, \\ S_{nt} &= X_{s,nt}'\beta_{s} + P_{nt}\alpha_{s} + u_{s,nt}, \\ Q_{nt} &= \min\{D_{nt},S_{nt}\}, \\ \Delta P_{nt} &= \frac{1}{\gamma} \left( D_{nt} - S_{nt} \right). \end{aligned} \tag{DA} \label{eq:model:deterministic_adjustment} \end{align}

diseq_deterministic_adjustment.png

  • Sample separation based on price movements, but this time in a quantitative nature. Price changes are analogous to shortages/surpluses.

The stochastic adjustment model

\begin{align} \begin{aligned} D_{nt} &= X_{d,nt}'\beta_{d} + P_{nt}\alpha_{d} + u_{d,nt}, \\ S_{nt} &= X_{s,nt}'\beta_{s} + P_{nt}\alpha_{s} + u_{s,nt}, \\ Q_{nt} &= \min\{D_{nt},S_{nt}\}, \\ \Delta P_{nt} &= \frac{1}{\gamma} \left( D_{nt} - S_{nt} \right) + X_{p,nt}'\beta_{p} + u_{p,nt}. \end{aligned} \tag{SA} \label{eq:model:stochastic_adjustment} \end{align}

diseq_stochastic_adjustment.png

  • No sample separation. Price dynamics are stochastic.

Package design

Comparison of equilibrium estimation methods and tools

seed <- 25
parameters <- list(
  nobs = 4000, tobs = 5,
  alpha_d = -0.7, beta_d0 = 28.9, beta_d = c(0.3, -0.2), eta_d = c(-0.03, -0.01),
  alpha_s = 0.6, beta_s0 = 10.2, beta_s = c(0.3), eta_s = c(0.5, 0.02),
  sigma_d = 2.0, sigma_s = 3.0, rho_ds = -0.3)
equilibrium_mdl <- simulate_model("equilibrium_model", parameters, seed, verbose)
fiml_optim_est <- estimate(equilibrium_mdl, control = optimization_control)
fiml_gsl_est <- maximize_log_likelihood(
  equilibrium_mdl, step = .01, objective_tolerance = .01, gradient_tolerance = .01)
ls_est <- estimate(equilibrium_mdl, method = "2SLS")
Coefficients D_P D_CONST D_Xd1 D_Xd2 D_X1 D_X2 S_P S_CONST S_Xs1 S_X1 S_X2 D_VARIANCE S_VARIANCE RHO
sim -0.70 28.90 0.30 -0.20 -0.03 -0.01 0.60 10.20 0.30 0.50 0.02 4.00 9.00 -0.30
fiml_optim -0.57 (0.13) 27.45 (1.45) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.56 (0.04) 10.53 (0.33) 0.36 (0.06) 0.50 (0.00) 0.02 (0.00) 2.96 (1.04) 8.34 (0.66) -0.12 (0.18)
fiml_gsl -0.57 (0.13) 27.43 (1.47) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.53 (0.07) 10.99 (0.79) 0.35 (0.05) 0.49 (0.01) 0.02 (0.00) 2.95 (1.05) 7.87 (1.13) -0.10 (0.20)
2sls -0.57 (0.13) 27.42 (1.48) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.56 (0.04) 10.50 (0.30) 0.36 (0.06) 0.50 (0.00) 0.02 (0.00) 2.95 (1.05) 8.38 (0.62) -0.12 (0.18)
Coefficients D_P D_CONST D_Xd1 D_Xd2 D_X1 D_X2 S_P S_CONST S_Xs1 S_X1 S_X2 D_VARIANCE S_VARIANCE RHO
sim -0.70 28.90 0.30 -0.20 -0.03 -0.01 0.60 10.20 0.30 0.50 0.02 4.00 9.00 -0.30
fiml_optim -0.57 (0.13) 27.45 (1.45) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.56 (0.04) 10.53 (0.33) 0.36 (0.06) 0.50 (0.00) 0.02 (0.00) 2.96 (1.04) 8.34 (0.66) -0.12 (0.18)
fiml_gsl -0.57 (0.13) 27.43 (1.47) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.53 (0.07) 10.99 (0.79) 0.35 (0.05) 0.49 (0.01) 0.02 (0.00) 2.95 (1.05) 7.87 (1.13) -0.10 (0.20)
2sls -0.57 (0.13) 27.42 (1.48) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.56 (0.04) 10.50 (0.30) 0.36 (0.06) 0.50 (0.00) 0.02 (0.00) 2.95 (1.05) 8.38 (0.62) -0.12 (0.18)
Coefficients D_P D_CONST D_Xd1 D_Xd2 D_X1 D_X2 S_P S_CONST S_Xs1 S_X1 S_X2 D_VARIANCE S_VARIANCE RHO
sim -0.70 28.90 0.30 -0.20 -0.03 -0.01 0.60 10.20 0.30 0.50 0.02 4.00 9.00 -0.30
fiml_optim -0.57 (0.13) 27.45 (1.45) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.56 (0.04) 10.53 (0.33) 0.36 (0.06) 0.50 (0.00) 0.02 (0.00) 2.96 (1.04) 8.34 (0.66) -0.12 (0.18)
fiml_gsl -0.57 (0.13) 27.43 (1.47) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.53 (0.07) 10.99 (0.79) 0.35 (0.05) 0.49 (0.01) 0.02 (0.00) 2.95 (1.05) 7.87 (1.13) -0.10 (0.20)
2sls -0.57 (0.13) 27.42 (1.48) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.56 (0.04) 10.50 (0.30) 0.36 (0.06) 0.50 (0.00) 0.02 (0.00) 2.95 (1.05) 8.38 (0.62) -0.12 (0.18)
Coefficients D_P D_CONST D_Xd1 D_Xd2 D_X1 D_X2 S_P S_CONST S_Xs1 S_X1 S_X2 D_VARIANCE S_VARIANCE RHO
sim -0.70 28.90 0.30 -0.20 -0.03 -0.01 0.60 10.20 0.30 0.50 0.02 4.00 9.00 -0.30
fiml_optim -0.57 (0.13) 27.45 (1.45) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.56 (0.04) 10.53 (0.33) 0.36 (0.06) 0.50 (0.00) 0.02 (0.00) 2.96 (1.04) 8.34 (0.66) -0.12 (0.18)
fiml_gsl -0.57 (0.13) 27.43 (1.47) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.53 (0.07) 10.99 (0.79) 0.35 (0.05) 0.49 (0.01) 0.02 (0.00) 2.95 (1.05) 7.87 (1.13) -0.10 (0.20)
2sls -0.57 (0.13) 27.42 (1.48) 0.26 (0.04) -0.24 (0.04) 0.02 (0.05) -0.07 (0.06) 0.56 (0.04) 10.50 (0.30) 0.36 (0.06) 0.50 (0.00) 0.02 (0.00) 2.95 (1.05) 8.38 (0.62) -0.12 (0.18)

Market classes' design

implementation.png

Remaining models' estimation benchmarks

Equilibrium model

equilibrium_model_obs_benchmark.png
equilibrium_model_params_benchmark.png

Directional model

diseq_directional_obs_benchmark.png
diseq_directional_params_benchmark.png

Deterministic adjustment model

diseq_deterministic_adjustment_obs_benchmark.png
diseq_deterministic_adjustment_params_benchmark.png

Stochastic adjustment model

diseq_stochastic_adjustment_obs_benchmark.png
diseq_stochastic_adjustment_params_benchmark.png

Example

Houses data

data(houses)
DATE The date of the record.  
HS Private non-farm housing starts in thousands of units (not seasonally adjusted). Economic Report of the President (1947)
RM FHA Mortgage Rate series on new homes in units of 100 (beginning-of-month Data). Fair (1971)
DSLA Savings capital (deposits) of savings and loan associations in millions of dollars. Federal Reserve Bulletin (1914)
DMSB Deposits of mutual savings banks in millions of dollars. Federal Reserve Bulletin (1914)
DHLB Advances of the federal home loan bank to savings and loan associations in million of dollars. Federal Reserve Bulletin (1914)
W Number of working days in month. Manually collected

Houses data

house_data <- fair_houses()
DATE The date of the record.  
HS Private non-farm housing starts in thousands of units (not seasonally adjusted). Economic Report of the President (1947)
RM FHA Mortgage Rate series on new homes in units of 100 (beginning-of-month Data). Fair (1971)
DSLA Savings capital (deposits) of savings and loan associations in millions of dollars. Federal Reserve Bulletin (1914)
DMSB Deposits of mutual savings banks in millions of dollars. Federal Reserve Bulletin (1914)
DHLB Advances of the federal home loan bank to savings and loan associations in million of dollars. Federal Reserve Bulletin (1914)
W Number of working days in month. Manually collected
ID Dummy entity id  
DSF \(DSLA_{t} + DMSB_t - (DSLA_{t-1} + DMSB_{t-1})\)  
DHF \(DHLB_{t} - DHLB_{t-1}\)  
MONTH Month of the date  
L2RM \(RM_{t-2}\)  
L1RM \(RM_{t-1}\)  
L1HS \(HS_{t-1}\)  
CSHS \(\sum_{s=1}^{t-1} HS_{s}\)  
MA6DSF Moving average of order six of DSF  
MA3DHF Moving average of order 3 of DHF  

Post estimation options

  1. Demanded, supplied quantities, and aggregation
  2. Analysis of shortages
  3. Marginal effects

Demanded, supplied quantities, and aggregation

demanded_quantities(model, est@coef)
supplied_quantities(model, est@coef)
aggregate_demand(model, est@coef)
aggregate_supply(model, est@coef)

Analysis of shortages

shortages(model, est@coef)
shortage_indicators(model, est@coef)
shortage_standard_deviation(model, est@coef)
normalized_shortages(model, est@coef)
relative_shortages(model, est@coef)
shortage_probabilities(model, est@coef)
\begin{align*} \hat{XD} = \hat D - \hat S \end{align*}
\begin{align*} \mathbb{1}_{\{\hat{XD} \ge 0\}} \end{align*}
\begin{align*} \hat{\mathrm{Var}}(\hat{XD}) = \sqrt{\hat \sigma_{d}^{2} + \hat \sigma_{s}^{2} - 2 \hat \rho \hat \sigma_{d} \hat \sigma_{s}} \end{align*}
\begin{align*} \hat{XD}_{n} = \frac{\hat{XD}}{\hat{\mathrm{Var}}(\hat{XD})} \end{align*}
\begin{align*} \hat{XD}_{r} = \frac{\hat{XD}}{\hat{S}} \end{align*}
\begin{align*} \hat{\pi_{D}} = \Phi(\hat{XD}_{n}) \end{align*}

Marginal effects

summary(model)
Stochastic Adjustment Model for Markets in Disequilibrium
  Demand Equation   : D_HS ~ D_RM + D_W + D_TREND + D_CSHS + D_MONTH
  Supply Equation   : S_HS ~ S_RM + S_W + S_TREND + S_MA6DSF + S_MA3DHF + S_MONTH
  Price Equation    : RM_DIFF ~ (D_HS - S_HS) + TREND + L2RM + L3RM
  Shocks            : Independent
  Nobs              : 128
  Sample Separation : Not Separated
  Quantity Var      : HS
  Price Var         : RM
  Key Var(s)        : ID, TREND
  Time Var          : TREND
shortage_probability_marginal(model, est@coef, "RM")
shortage_probability_marginal(model, est@coef, "CSHS", aggregate = "at_the_mean")
shortage_marginal(model, est@coef, "MA3DHF")
>     B_RM
-0.0008854701
>     D_CSHS
0.02019373
>     S_MA3DHF
-0.001261552
>     B_RM
-0.0008854701
>     D_CSHS
0.02019373
>     S_MA3DHF
-0.001261552
>     B_RM
-0.0008854701
>     D_CSHS
0.02019373
>     S_MA3DHF
-0.001261552

More on functionality

Initialization

model <- new(
  "diseq_stochastic_adjustment",
  c("ID", "TREND"), "TREND", "HS", "RM",
  "RM + TREND + W  + CSHS + MONTH",
  "RM + TREND + W  + MA6DSF + MA3DHF + MONTH",
  "TREND + L2RM + L3RM  + L4RM",
  fair_houses() %>% dplyr::mutate(
    HS = log(HS),
    L1HS = dplyr::lag(HS),
    CSHS = cumsum(ifelse(is.na(L1HS), 0, L1HS)),
    L3RM = dplyr::lag(RM, 3), L4RM = dplyr::lag(RM, 4)),
  correlated_shocks = FALSE)
summary(model)
Stochastic Adjustment Model for Markets in Disequilibrium
  Demand Equation   : D_HS ~ D_RM + D_W + D_TREND + D_CSHS + D_MONTH
  Supply Equation   : S_HS ~ S_RM + S_W + S_TREND + S_MA6DSF + S_MA3DHF + S_MONTH
  Price Equation    : RM_DIFF ~ (D_HS - S_HS) + TREND + L2RM + L3RM
  Shocks            : Independent
  Nobs              : 128
  Sample Separation : Not Separated
  Quantity Var      : HS
  Price Var         : RM
  Key Var(s)        : ID, TREND
  Time Var          : TREND

Estimation options

  • Keyword options:
gradient %in% c("numerical", "calculated")                         # default: "calculated"

hessian %in% c("numerical", "calculated", "skip")                  # default: if not "calculated" then "numerical"

standard_errors %in% c("homoscedastic", "heteroscedastic") ||
  standard_errors %in% names(object_to_be_estimated@model_tibble)  # default: "homoscedastic"
  • Example:
est <- estimate(model, control = list(maxit = 1e+5, reltol = 1e-4),
		standard_errors = c("W"))