estimate_t0 {ArCo} | R Documentation |
Estimates the intervention time on a given treated unit
Description
Estimates the intervention time on a given treated unit based on any model supplied by the user.
Usage
estimate_t0(data, fn = NULL, p.fn = NULL, start = 0.4, end = 0.9,
treated.unit = 1, lag = 0, Xreg = NULL, ...)
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. |
start |
Initial value of |
end |
Final value of |
treated.unit |
Single number indicating the unit where the intervention took place. |
lag |
Number of lags in the first stage model. Default is 0, i.e. only contemporaneous variables are used. |
Xreg |
Exogenous controls. |
... |
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
A list with the following items:
t0 |
Estimated t0. |
delta.norm |
The norm of the delta corresponding to t0. |
call |
The matched call. |
See Also
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)
}
t0a=estimate_t0(data = data,fn = fn, p.fn = p.fn, treated.unit = 1 )
#############################
## === 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
t0b=estimate_t0(data = data.q2,fn = fn, p.fn = p.fn, treated.unit = 1, start=0.4)