Learn R Programming

dynsim (version 0.2.4)

dynsim: 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,
  forecast = NULL)

Arguments

obj
the output object from zelig.
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 $t = 0$. If only one scenario is desired then scen should be a data frame. If more than one scenario is desired then t
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 n. The default is 1000.
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 times this will contain the times in n to use the shock val
forecast
Reserved argument for future version. Any value given to forecast will be ignored.

Value

  • The command returns a dynsim class object. This can contain up to seven elements:
    • scenNumber:
    {The scenario number.}
  • time:The time points.
  • shock.:Columns containing the values of the shock variables at each point in time.
  • ldvMean:Mean of the simulation distribution.
  • ldvLower:Lower bound of the simulation distribution's central interval set with sig.
  • ldvUpper:Upper bound of the simulation distribution's central interval set with sig.
  • ldvLower50:Lower bound of the simulation distribution's central 50 percent interval.
  • ldvUpper50:Upper bound of the simulation distribution's central 50 percent interval.

code

class(dynOut) <- "data.frame"

Details

A post-estimation technique for producing dynamic simulations of autoregressive models estimated with Zelig.

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

Run this code
# Load packages
library(Zelig)
library(DataCombine)

# Load Grunfeld data
data(grunfeld, package = "dynsim")

# Create lag invest variable
grunfeld <- slide(grunfeld, Var = "invest", GroupVar = "company",
               NewVar = "InvestLag")

# Estimate basic model
M1 <- zelig(invest ~ InvestLag + mvalue + kstock,
            model = "ls", data = grunfeld, cite = FALSE)

# Estimate model with interaction between mvalue and kstock
M2 <- zelig(invest ~ InvestLag + mvalue*kstock,
            model = "ls", data = grunfeld, cite = FALSE)

# Set up scenarios
attach(grunfeld)
Scen1 <- data.frame(InvestLag = mean(InvestLag, na.rm = TRUE),
                    mvalue = quantile(mvalue, 0.05),
                    kstock = quantile(kstock, 0.05))
Scen2 <- data.frame(InvestLag = mean(InvestLag, na.rm = TRUE),
                    mvalue = mean(mvalue),
                    kstock = mean(kstock))
Scen3 <- data.frame(InvestLag = mean(InvestLag, na.rm = TRUE),
                    mvalue = quantile(mvalue, 0.95),
                    kstock = quantile(kstock, 0.95))
detach(grunfeld)

# 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)

Run the code above in your browser using DataLab