estimate_t0: Estimates the intervention time on a given treated unit

Description Usage Arguments Details Value See Also Examples

View source: R/estimate_t0.R

Description

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

Usage

1
2
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 λ_0 to be tested.

end

Final value of λ_0 to be tested.

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.

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

fitArCo

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

gabrielrvsc/ARCO documentation built on Nov. 8, 2017, 6:13 p.m.