dynsim {dynsim} | R Documentation |
Dynamic simulations of autoregressive relationships
Description
dynsim
dynamic simulations of autoregressive relationships
Usage
dynsim(obj, ldv, scen, n = 10, sig = 0.95, num = 1000, shocks = NULL, ...)
Arguments
obj |
the output object the estimation model. |
ldv |
character. Names the lagged dependent variable |
scen |
data frame or list of data frames. Specifies the values of the
variables used to generate the predicted values when |
n |
numeric. Specifies the number of iterations (or time period) over which the program will generate the predicted value of the dependent variable. The default is 10. |
sig |
numeric. Specifies the level of statistical significance of the confidence intervals. Any value allowed be greater than 0 and cannot be greater than 1. |
num |
numeric. Specifies the number of simulations to compute for each
value of |
shocks |
data frame. Allows the user to choose independent variables,
their values, and times to introduce these values. The first column of the
data frame must be called |
... |
arguments to pass to methods. |
Details
A post-estimation technique for producing dynamic simulations of autoregressive models.
Value
The command returns a data.frame
and dynsim
class
object. This can contain up to columns elements:
scenNumber
: The scenario number.time
: The time points.shock.
: Columns containing the values of the shock variables at each point intime
.ldvMean
: Mean of the simulation distribution.ldvLower
: Lower bound of the simulation distribution's central interval set withsig
.ldvUpper
: Upper bound of the simulation distribution's central interval set withsig
.ldvLower50
: Lower bound of the simulation distribution's central 50 percent interval.ldvUpper50
: Upper bound of the simulation distribution's central 50 percent interval.
The output object is a data frame class object. Do with it as you like.
References
Williams, L. K., & Whitten, G. D. (2011). Dynamic Simulations of Autoregressive Relationships. The Stata Journal, 11(4), 577-588.
Williams, L. K., & Whitten, G. D. (2012). But Wait, There's More! Maximizing Substantive Inferences from TSCS Models. Journal of Politics, 74(03), 685-693.
Examples
# Load package
library(DataCombine)
# Load Grunfeld data
data(grunfeld, package = "dynsim")
# Create lag invest variable
grunfeld <- slide(grunfeld, Var = "invest", GroupVar = "company",
NewVar = "InvestLag")
# Convert company to factor for fixed-effects specification
grunfeld$company <- as.factor(grunfeld$company)
# Estimate basic model
M1 <- lm(invest ~ InvestLag + mvalue + kstock + company, data = grunfeld)
# Estimate model with interaction between mvalue and kstock
M2 <- lm(invest ~ InvestLag + mvalue*kstock + company, data = grunfeld)
# Set up scenarios for company 4
## List version ##
attach(grunfeld)
Scen1 <- data.frame(InvestLag = mean(InvestLag, na.rm = TRUE),
mvalue = quantile(mvalue, 0.05),
kstock = quantile(kstock, 0.05),
company4 = 1)
Scen2 <- data.frame(InvestLag = mean(InvestLag, na.rm = TRUE),
mvalue = mean(mvalue),
kstock = mean(kstock),
company4 = 1)
Scen3 <- data.frame(InvestLag = mean(InvestLag, na.rm = TRUE),
mvalue = quantile(mvalue, 0.95),
kstock = quantile(kstock, 0.95),
company4 = 1)
detach(grunfeld)
## Not run:
## Alternative data frame version of the scenario builder ##
attach(grunfeld)
ScenComb <- data.frame(InvestLag = rep(mean(InvestLag, na.rm = TRUE), 3),
mvalue = c(quantile(mvalue, 0.95), mean(mvalue),
quantile(mvalue, 0.05)),
kstock = c(quantile(kstock, 0.95), mean(kstock),
quantile(kstock, 0.05)),
company4 = rep(1, 3)
)
detach(grunfeld)
## End(Not run)
# Combine into a single list
ScenComb <- list(Scen1, Scen2, Scen3)
## Run dynamic simulations without shocks and no interactions
Sim1 <- dynsim(obj = M1, ldv = "InvestLag", scen = ScenComb, n = 20)
## Run dynamic simulations without shocks and interactions
Sim2 <- dynsim(obj = M2, ldv = "InvestLag", scen = ScenComb, n = 20)
## Run dynamic simulations with shocks
# Create data frame of shock values
mShocks <- data.frame(times = c(5, 10), kstock = c(100, 1000),
mvalue = c(58, 5000))
# Run simulations without interactions
Sim3 <- dynsim(obj = M1, ldv = "InvestLag", scen = ScenComb, n = 20,
shocks = mShocks)
# Run simulations with interactions
Sim4 <- dynsim(obj = M2, ldv = "InvestLag", scen = ScenComb, n = 20,
shocks = mShocks)