Skip to content

Problem with unbalanced panel #1

@yang-yuchuan

Description

@yang-yuchuan

Hi, thanks for providing the fantastic package!

I've found some weird problems with unbalanced panel. As an illustrative example, I use the job_displacement_data datasets within the package:

# produce unbalanced panel by randomly removing observations
set.seed(10)
test <- ife::job_displacement_data %>% slice(-sample(1:2000, 100))

# the first id that has missing periods is 14
test %>% count(id) %>% filter(n<6) %>% pull(id) %>% min()
#> 14

ife::ife(yname="earn",
         gname="first.displaced",
         tname="year",
         idname="id",
         data=test,
         nife=1,
         xformla=~EDUC + race + gender,
         zformla=~EDUC + race + gender + afqt,
         anticipation=1,
         cband=FALSE,
         cl=10)
#> Error in `dplyr::mutate()`:
#> ℹ In argument: `dY_base = (Y - Y[period == base.period])`.
#> ℹ In group 3: `id = 14`.
#> Caused by error:
#> ! `dY_base` must be size 2 or 1, not 0.

After debugging, the error seems to occur in the internal function compute.pte, which invokes ife_attgt as an argument attgt_fun: In line 7 in ife_attgt, it generates a new variable dY_base = (Y - Y[period == base.period]) defined as the deviation from base period outcome. However, the line 4 base.period <- min(gt_data$period) define an overall minimum period, which may be missing for some ids in case of unbalanced panel.

I tried to fix it by replacing the above part of line 7 with dY_base = (Y - Y[period == min(period, na.rm = T)]). This indeed enables compute.pte to work, but another error occurs: When using did::aggte to compute overall att and dynamic results, a non-comparable matrix addition in the internal function get_agg_inf_func aborts the process. In my example, the row number of inffunc1 and wif is not equal, causing this error.

Is there anyway to solve this issue and produce meaningful results? I'm not that good at theory, so I'am not sure whether the use of unbalanced panel is illegal in this estimator.

I thank you in advance for your time and help!
Yuchuan

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions