Description Usage Arguments Details Examples
Create simulations for long-term effects from error correction models (ECM)
1 2 3 4 | ecm_builder(obj, baseline_df, lag_dv, lag_iv, d_iv, iv_shock, lag_iv_2, d_iv_2,
lag_iv_lag_iv2_interaction, d_iv_d_iv2_interaction, lag_iv_d_iv2_interaction,
d_iv_lag_iv2_interaction, iv_2_shock, shock_duration, t_extent = 5,
nsim = 1000, ci = 0.95, slim = TRUE, qi_d_dv = TRUE, mu, Sigma)
|
obj |
a fitted model object from an ECM model estimated with
|
baseline_df |
a data frame with fitted values for the baseline scenario
before the shock to |
lag_dv |
charachter string identifying the name of the lagged dependent
variable in |
lag_iv |
charachter string identifying the name of the lagged
independent variable in |
d_iv |
charachter string identifying the name of the change in
|
iv_shock |
numeric shock to |
lag_iv_2 |
character string identifying variable name of the second
lagged independent variable in an interaction with |
d_iv_2 |
character string identifying variable name of the second
shocked independent variable in an interaction with |
lag_iv_lag_iv2_interaction |
character string identifying the interaction
term for |
d_iv_d_iv2_interaction |
character string identifying the interaction
term for |
lag_iv_d_iv2_interaction |
character string identifying the interaction
term for |
d_iv_lag_iv2_interaction |
character string identifying the interaction
term for |
iv_2_shock |
numeric shock to |
shock_duration |
numeric specifying how many time periods over which the shock occurs. |
t_extent |
numeric specifying the time points from the shock to simulate the long-term effects of the shock for. The default is 5 time points. |
nsim |
numeric. Number of simulations to draw. |
ci |
the proportion of the central interval of the simulations to
return. Must be in (0, 1] or equivalently (0, 100]. Note: if |
slim |
logical indicating whether to (if |
qi_d_dv |
logical specifying if the quantity of interest should be the simulated change in the dependent variable or its level. |
mu |
an optional vector giving the means of the variables estimated
from an ECM model. If |
Sigma |
an optional positive-definite symmetric matrix estimated
from an ECM model. The matrix specifies the covariance matrix of the
variables. If |
If an interaction with the shocked variable is included, the function assumes a "general model" setup as discussed in Warner (2016).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # Simulated data to estimate the model from
iv <- rnorm(10)
lag_iv <- c(NA, iv[-length(iv)])
d_iv <- iv - lag_iv
b0 = 2
b1 = -0.2
b2 = 1.1
b3 = 2.2
starting_d_dv <- -4.1
eps <- rnorm(iv, sd = 0.2)
dv <- vector()
d_dv <- vector()
lag_dv <- vector()
for (i in 2:length(lag_iv)) {
if (i == 2) {
dv_start <- b0 + b2*lag_iv[i] + b3*d_iv[i] + eps[i]
lag_dv[3] <- dv_start + starting_d_dv
}
else if (i == 3) {
d_dv[i] <- b0 + b1*lag_dv[i] + b2*lag_iv[i] + b3*d_iv[i] + eps[i]
}
else if (i > 3) {
lag_dv[i] <- lag_dv[i-1] + d_dv[i-1]
d_dv[i] <- b0 + b1*lag_dv[i] + b2*lag_iv[i] + b3*d_iv[i] + eps[i]
}
}
# Estimate error correction model
m1 <- lm(d_dv ~ lag_dv + lag_iv + d_iv)
# Create baseline scenario
baseline_scen <- data.frame(lag_dv = mean(lag_dv, na.rm = TRUE),
lag_iv = mean(lag_iv, na.rm = TRUE))
# Simulate effects of a 1 standard deviation shock to the IV over 20 time
## periods
m1_sims <- ecm_builder(obj = m1, lag_iv = 'lag_iv', d_iv = 'd_iv',
iv_shock = sd(d_iv, na.rm = TRUE),
baseline_df = baseline_scen, t_extent = 20)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.