fitArCo {ArCo} | R Documentation |
Estimates the ArCo using the model selected by the user
Description
Estimates the Artificial Counterfactual unsing any model supplied by the user, calculates the most relevant statistics and allows for the counterfactual confidence intervals to be estimated by block bootstrap.
The model must be supplied by the user through the arguments fn and p.fn. The first determines which function will be used to estimate the model and the second determines the forecasting function. For more details see the examples and the description on the arguments.
Usage
fitArCo(data, fn = NULL, p.fn = NULL, treated.unit, t0, lag = 0,
Xreg = NULL, alpha = 0.05, boot.cf = FALSE, R = 100, l = 3,
VCOV.type = c("iid", "var", "nw", "varhac"), VCOV.lag = 1,
bandwidth.kernel = NULL, kernel.type = c("QuadraticSpectral", "Truncated",
"Bartlett", "Parzen", "TukeyHanning"), VHAC.max.lag = 5,
prewhitening.kernel = FALSE, ...)
Arguments
data |
A list of matrixes or data frames of length q. Each matrix is T X n and it contains observations of a single variable for all units and all periods of time. Even in the case of a single variable (q=1), the matrix must be inside a list. |
fn |
The function used to estimate the first stage model. This function must receive only two arguments in the following order: X (independent variables), y (dependent variable). If the model requires additional arguments they must be supplied inside the function fn. If not supplied the default is the lm function. |
p.fn |
The forecasting function used to estimate the counterfactual using the first stage model (normally a predict funtion). This function also must receive only two arguments in the following order: model (model estimated in the first stage), newdata (out of sample data to estimate the second stage). If the prediction requires additional arguments they must be supplied inside the function p.fn. |
treated.unit |
Single number indicating the unit where the intervention took place. |
t0 |
Single number indicating the intervention period. |
lag |
Number of lags in the first stage model. Default is 0, i.e. only contemporaneous variables are used. |
Xreg |
Exogenous controls. |
alpha |
Significance level for the delta confidence bands. |
boot.cf |
Should bootstrap confidence intervals for the counterfactual be calculated (default=FALSE). |
R |
Number of bootstrap replications in case boot.cf=TRUE. |
l |
Block length for the block bootstrap. |
VCOV.type |
Type of covariance matrix for the delta. "iid" for standard covariance matrix, "var" or "varhac" to use prewhitened covariance matrix using VAR models, "varhac" selects the order of the VAR automaticaly and "nw" for Newey West. In the last case the user may select the kernel type and combine the kernel with the VAR prewhitening. For more details see Andrews and Monahan (1992). |
VCOV.lag |
Lag used on the robust covariance matrix if VCOV.type is different from "iid". |
bandwidth.kernel |
Kernel bandwidth. If NULL the bandwidth is automatically calculated. |
kernel.type |
Kernel to be used for VCOV.type="nw". |
VHAC.max.lag |
Maximum lag of the VAR in case VCOV.type="varhac". |
prewhitening.kernel |
If TRUE and VCOV.type="nw", the covariance matrix is calculated with prewhitening (default=FALSE). |
... |
Additional arguments used in the function fn. |
Details
This description may be useful to clarify the notation and understand how the arguments must be supplied to the functions.
units: Each unit is indexed by a number between
1,\dots,n
. They are for exemple: countries, states, municipalities, firms, etc.Variables: For each unit and for every time period
t=1,\dots,T
we observeq_i \ge 1
variables. They are for example: GDP, inflation, sales, etc.Intervention: The intervention took place only in the treated unit at time
t_0=\lambda_0*T
, where\lambda_0
is in (0,1).
Value
An object with S3 class fitArCo.
cf |
estimated counterfactual |
fitted.values |
In sample fitted values for the pre-treatment period. |
model |
A list with q estimated models, one for each variable. Each element in the list is the output of the fn function. |
delta |
The delta statistics and its confidence interval. |
p.value |
ArCo p-value. |
data |
The data used. |
t0 |
The intervention period used. |
treated.unit |
The treated unit used. |
omega |
Residual standard deviation. |
residuals |
model residuals. |
boot.cf |
A list with the bootstrap result (boot.cf=TRUE) or logical FALSE (boot.cf=FALSE). In the first case, each element in the list refers to one bootstrap replication of the counterfactual, i. e. the list length is R. |
call |
The matched call. |
References
Carvalho, C., Masini, R., Medeiros, M. (2016) "ArCo: An Artificial Counterfactual Approach For High-Dimensional Panel Time-Series Data.".
Andrews, D. W., & Monahan, J. C. (1992). An improved heteroskedasticity and autocorrelation consistent covariance matrix estimator. Econometrica: Journal of the Econometric Society, 953-966.
See Also
plot
, estimate_t0
, panel_to_ArCo_list
Examples
#############################
## === Example for q=1 === ##
#############################
data(data.q1)
# = First unit was treated on t=51 by adding
# a constant equal to one standard deviation
data=list(data.q1) # = Even if q=1 the data must be in a list
## == Fitting the ArCo using linear regression == ##
# = creating fn and p.fn function = #
fn=function(X,y){
return(lm(y~X))
}
p.fn=function(model,newdata){
b=coef(model)
return(cbind(1,newdata) %*% b)
}
ArCo=fitArCo(data = data,fn = fn, p.fn = p.fn, treated.unit = 1 , t0 = 51)
#############################
## === Example for q=2 === ##
#############################
# = First unit was treated on t=51 by adding constants of one standard deviation
# for the first and second variables
data(data.q2) # data is already a list
## == Fitting the ArCo using the package glmnet == ##
## == Quadratic Spectral kernel weights for two lags == ##
## == Fitting the ArCo using the package glmnet == ##
## == Bartlett kernel weights for two lags == ##
require(glmnet)
set.seed(123)
ArCo2=fitArCo(data = data.q2,fn = cv.glmnet, p.fn = predict,treated.unit = 1 , t0 = 51,
VCOV.type = "nw",kernel.type = "QuadraticSpectral",VCOV.lag = 2)