local_lm: Local Linear Regression to Estimate Local ATE

Description Usage Arguments Examples

View source: R/discRD-local-lm.r

Description

Estimate the local ATE at the treatment assignment threshold by the local linear regression.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
local_lm(
  basemod,
  data,
  subset,
  weights,
  cluster,
  submod,
  order = c(1, 2),
  cutoff,
  assign,
  se = "HC0",
  cholesky = TRUE,
  bw,
  kernel,
  point = 0
)

Arguments

basemod

baseline formula. outcome ~ running variable.

data

data.frame which you want to use.

subset

subset condition.

weights

weight variable.

cluster

cluster variable.

submod

numeric vector. Which baseline model you want to use.

order

numeric vector of polynomial orders.

cutoff

numeric of cutoff points If missing, try to find getOption("discRD.cutoff").

assign

assignment rule of treatment. If "greater", treated whose running variable is greater than or equal to cutoff. If "smaller", treated whose running variable is less than or equal to cutoff. If missing, try to find getOption("discRD.assign").

se

character. How to calculate robust variance-covariance matrix ("HC0", "HC1", "HC2", "HCj", "HC3", and "HC4")

cholesky

logical (default is TRUE). When solving normal equation, use cholesky decomposition.

bw

bandwidth.

kernel

character of kernel density ("uniform" or "triangular")

point

value of the running variable that the kernel weights weigh the most

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
running <- sample(1:100, size = 1000, replace = TRUE)
cov1 <- rnorm(1000, sd = 2); cov2 <- rnorm(1000, mean = -1)
y0 <- running + cov1 + cov2 + rnorm(1000, sd = 10)
y1 <- 2 + 1.5 * running + cov1 + cov2 + rnorm(1000, sd = 10)
y <- ifelse(running <= 50, y1, y0)
bin <- ifelse(y > mean(y), 1, 0)
w <- sample(c(1, 0.5), size = 1000, replace = TRUE)
raw <- data.frame(y, bin, running, cov1, cov2, w)

set_optDiscRD(
  y + bin ~ running,
  covmod = list(~cov1, ~ cov1 + cov2),
  discRD.cutoff = 50,
  discRD.assign = "smaller"
)

local <- local_lm(data = raw, bw = 3, kernel = "uniform")
str(local_lm(submod = 1, data = raw, bw = 3, kernel = "uniform"))
str(local_lm(submod = 1, order = 3, data = raw, bw = 3, kernel = "uniform"))
str(local_lm(data = raw, cutoff = 30, bw = 3, kernel = "uniform"))
est2 <- local_lm(
  data = raw, se = "HC1", weights = w, bw = 3, kernel = "uniform"
)

KatoPachi/discreteRD documentation built on Feb. 24, 2022, 12:32 a.m.