Skip to contents

[Experimental]

Usage

set_panel(data, unit, time)

get_panel(data)

has_panel(data)

pull_panel_unit(data)

pull_panel_time(data)

Arguments

data

a data frame or causal_tbl

unit

the column indexing treatment units (tidy-selected)

time

the column indexing treatment time (tidy-selected)

Value

A causal_tbl

For get_panel() a list with the column names of the unit and time variables

For has_panel(), TRUE if there is panel data structure

For pull_panel_unit() and pull_panel_time(), the vector of the corresponding panel variable.

Examples

data <- data.frame(
  id = c("a", "a", "a", "a", "b", "b", "b", "b"),
  year = rep(2015:2018, 2),
  trt = c(0, 0, 0, 0, 0, 0, 1, 1),
  y = c(1, 3, 2, 3, 2, 4, 4, 5)
) |>
  set_panel(unit=id, time=year)
print(data) # a causal_tbl
#> # A <causal_tbl> [8 × 4]
#>   [unit] [time]            
#>   id       year   trt     y
#>   <chr>   <int> <dbl> <dbl>
#> 1 a        2015     0     1
#> 2 a        2016     0     3
#> 3 a        2017     0     2
#> 4 a        2018     0     3
#> 5 b        2015     0     2
#> 6 b        2016     0     4
#> 7 b        2017     1     4
#> 8 b        2018     1     5
get_panel(data)
#> $unit
#> [1] "id"
#> 
#> $time
#> [1] "year"
#>