Weighted levels

Q-weighted mean outcome levels for treatment and control groups at each event time — the raw-means view that complements the coefficient event study.

R stack_levels()   ↔︎   Stata stacked levels

Usage

stack_levels(stack_data, outcome_var, weight_var = "q_weight", by_group = FALSE)

Arguments

Argument Description
stack_data A stack from build_stack().
outcome_var Outcome variable name.
weight_var Weight column (default "q_weight"; use "q_weight_ps" for propensity-score weights).
by_group If TRUE, means per timing group, with each cohort’s aggregation weight.

stack_levels() returns the numbers only; use stack_plot_levels() to draw them.

stacked levels depvar [, weightvar(varname) bygroup plot]

Options

Option Description
weightvar(varname) Weight column (default q_weight; use q_weight_ps for propensity-score weights).
bygroup Means per timing group.
plot Also draw the treatment/control level plot.

In Stata a single subcommand both computes and (with plot) draws the levels; in R those are two functions.

R ↔︎ Stata mapping

R Stata
stack_levels(...) stacked levels depvar
weight_var weightvar()
by_group bygroup
stack_plot_levels() stacked levels depvar, plot

Value / Stored results

R returns a wide data.table: event_time, treat_mean_<outcome>, control_mean_<outcome> (outcome name embedded so multiple outcomes merge cleanly). With by_group = TRUE the result is long in sub_exp with a group_weight column.

Stata stores the table in r(levels) (and r(levels_bygroup) with bygroup).

Example

library(stacked)
data(signflip)
stack <- build_stack(signflip, "year", "id", "adopt_year",
                     kappa_pre = 2, kappa_post = 1)

stack_levels(stack, "outcome")
   event_time treat_mean_outcome control_mean_outcome
1:         -2                6.0                    8
2:         -1                6.0                    8
3:          0                8.4                    8
4:          1                8.4                    8
stacked use signflip, clear
stacked build, time(year) unit(id) adopt(adopt_year) kpre(2) kpost(1)
stacked levels outcome
stacked levels outcome, plot

See also