Learn R Programming

ArCo (version 0.2)

estimate_t0: Estimates the intervention time on a given treated unity

Description

Estimates the intervention time on a given treated unity based on any model supplied by the user.

Usage

estimate_t0(data, fn, p.fn, start = 0.4, end = 0.9, treated.unity = 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 \(\lambda_0\) to be tested.

end

Final value of \(\lambda_0\) to be tested.

treated.unity

Single number indicating the unity 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.

Value

A list with the following items:

t0

Estimated t0.

delta.norm

The norm of the delta corresponding to t0.

call

The matched call.

Details

This description may be useful to clarify the notation and understand how the arguments must be supplied to the functions.

  • units: Each unity is indexed by a number between \(1,\dots,n\). They are for exemple: countries, states, municipalities, firms, etc.

  • Variables: For each unity and for every time period \(t=1,\dots,T\) we observe \(q_i \ge 1\) variables. They are for example: GDP, inflation, sales, etc.

  • Intervention: The intervention took place only in the treated unity at time \(t_0=\lambda_0*T\), where \(\lambda_0\) is in (0,1).

See Also

fitArCo

Examples

Run this code
# NOT RUN {
#############################
## === Example for q=1 === ##
#############################
data(data.q1) 
# = First unity 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.unity = 1 )


#############################
## === Example for q=2 === ##
#############################

# = First unity 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

## == Detecting lambda0 using the package glmnet via LASSO and crossvalidation == ##

t0b=estimate_t0(data = data.q2,fn = fn, p.fn = p.fn, treated.unity = 1, start=0.4)
# }

Run the code above in your browser using DataLab