pred: Predictor Specification for SCM

View source: R/utils.R

predR Documentation

Predictor Specification for SCM

Description

Creates a single predictor specification for use in scm_fit() with method = "scm". Pass a list() of pred() calls as the predictors argument to define the full covariate matrix.

Usage

pred(vars, times, op = "mean")

Arguments

vars

Character vector of variable names. All variables share the same times window and op operator. Use separate pred() calls for variables with different time windows.

times

Numeric/integer vector of time values to aggregate over. Values are matched against the time index of the panel passed to scm_fit(), and are expected to be pre-treatment: a window naming times the panel does not carry silently aggregates the overlap only, and one reaching past the treatment date aggregates values the treatment has already moved, so scm_fit() warns about both.

op

Aggregation operator applied to each variable over times. One of "mean" (default), "median", or "sum".

Value

A pred_spec object (a named list with class "pred_spec").

See Also

scm_fit() for the predictors argument that consumes a list() of pred_spec objects.

Examples

# Three variables averaged over the same window
pred(c("lnincome", "retprice", "age15to24"), 1980:1988)

# Single variable at a specific year
pred("cigsale", 1975)

# Single variable averaged over a range
pred("beer", 1984:1988)

# Abadie, Diamond & Hainmueller (2010) California Prop 99 style: combine
# several covariates aggregated over different windows plus three outcome
# lags at specific years. The resulting list is passed to
# scm_fit(..., predictors = predictors).
predictors <- list(
  pred(c("lnincome", "retprice", "age15to24"), 1980:1988),
  pred("beer",    1984:1988),
  pred("cigsale", 1988),
  pred("cigsale", 1980),
  pred("cigsale", 1975)
)
predictors

coresynth documentation built on Aug. 28, 2026, 1:06 a.m.