MatthieuStigler / multiDiff

Multi-period diff and diff
Other
3 stars 0 forks source link

DD: reg_out column showing up? #4

Closed MatthieuStigler closed 4 years ago

MatthieuStigler commented 4 years ago

Happens when for one period there's no single regression to run!!

Fix: a conditional check for that column

library(multiDiff)
library(tidyverse, warn.conflicts=FALSE)
data <- sim_dat(N=100)
data2 <- data %>% 
  mutate(tr = if_else(Time %in% c(1,2), 0L, tr))
DD_out <- DD(data=data2)
DD_out
#> # A tibble: 56 x 15
#>     time   DiD treat control n_treat n_control n_min miss_data reg_out estimate
#>    <int> <int> <chr> <chr>     <dbl>     <dbl> <dbl> <lgl>     <lgl>      <dbl>
#>  1     2     1 0_1   0_0           0       100     0 TRUE      NA        NA    
#>  2     2     2 0_1   1_1           0         0     0 TRUE      NA        NA    
#>  3     2     3 1_0   0_0           0       100     0 TRUE      NA        NA    
#>  4     2     4 1_0   1_1           0         0     0 TRUE      NA        NA    
#>  5     3     1 0_1   0_0          26        74    26 FALSE     NA         0.929
#>  6     3     2 0_1   1_1          26         0     0 TRUE      NA        NA    
#>  7     3     3 1_0   0_0           0        74     0 TRUE      NA        NA    
#>  8     3     4 1_0   1_1           0         0     0 TRUE      NA        NA    
#>  9     4     1 0_1   0_0          14        60    14 FALSE     NA         0.976
#> 10     4     2 0_1   1_1          14         5     5 FALSE     NA         1.46 
#> # … with 46 more rows, and 5 more variables: std.error <dbl>, statistic <dbl>,
#> #   p.value <dbl>, conf.low <dbl>, conf.high <dbl>

Created on 2020-04-17 by the reprex package (v0.3.0)