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
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)
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) |
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) |
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 |
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 |
demanded_quantities(model, est@coef)
supplied_quantities(model, est@coef)
aggregate_demand(model, est@coef)
aggregate_supply(model, est@coef)
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)
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
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
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"
est <- estimate(model, control = list(maxit = 1e+5, reltol = 1e-4),
standard_errors = c("W"))