get.cohort: Obatin the Cohort Index

View source: R/getcohort.R

get.cohortR Documentation

Obatin the Cohort Index

Description

Obtain the cohort index based on the provided panel data.

Usage

  get.cohort(data, D, index, 
                  varname = NULL, 
                  start0 = FALSE,
                  entry.time = NULL,
                  drop.always.treat = FALSE)

Arguments

data

a data frame, can be a balanced or unbalanced panel data.

D

the treatment indicator. The treatment should be binary (0 and 1).

index

a two-element string vector specifying the unit and time indicators. Must be of length 2. Every observation should be uniquely defined by the pair of the unit and time indicator.

varname

a vector of strings that specifies the variable names for the cohort index and relative periods to be generated.

start0

a logical flag that indicates whether period 0 is the first post-treatment period. By default, it is set to FALSE, meaning that period 1 is considered the initial post-treatment period.

entry.time

a list of intervals representing the initial calendar time of treatment for each cohort. Units that received treatment within each specified interval are categorized as belonging to a single cohort.

drop.always.treat

a logical flag that indicates whether to drop all always-treated units.

Details

get.cohort function preprocesses the data and generates the cohort index for different groups. If not specified in varname, the function automatically creates four new variables: 'FirstTreat' stores the initial calendar time when a unit is first treated, 'Cohort' stores the cohort time, 'Time_to_Treatment' tracks the period relative to the treatment, and 'Time_to_Exit' tracks the period relative to the treatment exit. Users have the option to specify custom names for these newly generated variables using the varname parameter. By default, the function sets start0=FALSE, where the relative period 1 corresponds to the first post-treatment/post-exit-treatment period. If start0=TRUE, period 0 becomes the first post-treatment/post-exit-treatment period. Additionally, users can categorize units into specific cohorts using the entry.time parameter. For instance, if entry.time=list(c(1,5),c(6,10)), units that receive their first treatment within the calendar intervals c(1,5) and c(6,10) are grouped into two distinct cohorts. Units that have never been treated are always categorized as the "control cohort".

Value

data

a new data frame containing the cohort index.

Author(s)

Licheng Liu; Yiqing Xu, Ziyi Liu; Zhongyu Yin


xuyiqing/fect documentation built on April 12, 2025, 9:50 p.m.