bcallaway11 / did

Difference in Differences with Multiple Periods, website: https://bcallaway11.github.io/did
287 stars 91 forks source link

Is it possible to add Linear Trends to formula? #196

Open anzonyquispe opened 1 month ago

anzonyquispe commented 1 month ago

This is my original specification

out <- att_gt(yname = "per_treecover",
              gname = "min_year",
              idname = "block_id",
              tname = "year",
              xformla = ~ 1 ,
              data = df2, 
              control_group = c( "notyettreated" ), 
              base_period = 'universal', 
              alp = 0.05, 
              clustervars = 'block_id'
)

I would like to add linear trends since I see quadratic forms before treatment application image

I added the linear trends using these lines of code

df2$trend = df2$year - min(df2$year) + 1
df2$state_factor = as.factor(df2$pc11_s_id)

df2$trend_fac = as.factor(df2$trend)
df2$block_id_fac = as.factor(df2$block_id)

out <- att_gt(yname = "per_treecover",
              gname = "min_year",
              idname = "block_id",
              tname = "year",
              xformla = ~ trend * block_id_fac ,
              data = df2, 
              control_group = c( "notyettreated" ), 
              base_period = 'universal', 
              alp = 0.05, 
              clustervars = 'block_id'
)

I am not sure fi we can add linear trends like this. I tried with a small dataset, it seems that it does not work, is any other way to add linear trends to the specification?