dynsim: Dynamic simulations of autoregressive relationships

Description Usage Arguments Details Value References Examples

View source: R/dynsim.R

Description

dynsim dynamic simulations of autoregressive relationships

Usage

1
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 t = 0. If only one scenario is desired then scen should be a data frame. If more than one scenario is desired then the t = 0 values should be in data frames contained in a list.

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 values. The following columns' names must match the names of the variables whose values you wish to alter. You do not need to specify values for variables that you want to remain the same as in scen. In times n where shock values are not specified, non-ldv variable values will revert to those in scen. If * is used to create interactions, interaction terms will be fitted appropriately.

...

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:

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

 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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)

dynsim documentation built on June 20, 2021, 5:06 p.m.