Propensity-score weights

Fold user-supplied propensity scores into the Q-weights, combining inverse propensity weighting with the standard Q-weight formula (paper Appendix A4).

R add_pscore_weights()   ↔︎   Stata stacked pscore

Usage

add_pscore_weights(
  stack_data, pscore_var,
  weight_var = NULL,
  data_type = c("panel", "repeated_cross_section"),
  output_col = "q_weight_ps"
)

Arguments

Argument Description
stack_data A stack from build_stack().
pscore_var Column of estimated propensity scores, strictly in (0, 1). Trim first — the function errors on 0/1 boundaries.
weight_var Survey sampling-weight column (micro-data).
data_type "panel" (default) or "repeated_cross_section".
output_col Name of the new weight column (default "q_weight_ps").

Estimate the propensity scores yourself (e.g. a logit per sub_exp × event_time cell) before calling. The function recomputes Q-weights from IPW-weighted counts on the current rows, so trimming before the call is respected.

stacked pscore, pscore(varname) [weightvar(varname) datatype(str) ///
    generate(name) replace]

Options

Option Description
pscore(varname) Estimated propensity scores, strictly in (0, 1); trim before calling.
weightvar(varname) Survey/sampling weights.
datatype(str) panel (default) or repeated_cross_section/rcs.
generate(name) Name of the output weight variable (default q_weight_ps).
replace Overwrite an existing output variable.

R ↔︎ Stata mapping

R Stata
pscore_var pscore()
weight_var weightvar()
data_type datatype()
output_col generate()
(new column; copy not applicable) replace

Value / Stored results

R returns the input data.table with the new output_col (default q_weight_ps); the original q_weight is preserved. The final weight is \(w_{final} = w_{ATT} \times Q^{w_{ATT}}\), where \(w_{ATT}=1\) for treated and \(p/(1-p)\) for controls.

Stata adds the generate() variable in memory and stores r(sum), r(mean) of the new weights.

Pass the new weight into the regression via the weight column — in R, re-weight the stack (stackreg reads q_weight), or in either language use it in the levels/plot calls with weight_var = "q_weight_ps".

Example

library(stacked)
library(data.table)
data(medicaid)
stack <- build_stack(medicaid, "year", "state", "adopt_year",
                     kappa_pre = 3, kappa_post = 2)

# estimate a propensity score, then fold it into the Q-weights
fit <- glm(treat ~ uninsured, family = binomial, data = stack)
stack[, phat := predict(fit, type = "response")]
stack <- add_pscore_weights(stack, pscore_var = "phat")

stack[, .(mean_q = mean(q_weight), mean_q_ps = mean(q_weight_ps))]
   mean_q mean_q_ps
1:      1 0.6579622
* pscore_stack ships a stack with an estimated score `phat`
stacked use pscore_stack, clear
stacked pscore, pscore(phat)
summarize q_weight_ps

See also