synth-inference / synthdid

Synthetic difference in differences
https://synth-inference.github.io/synthdid
BSD 3-Clause "New" or "Revised" License
262 stars 98 forks source link

panel.matrices error: no variation in treatment status #108

Closed pearl-yu closed 1 year ago

pearl-yu commented 1 year ago

Hi,

I got the There is no variation in treatment status error when converting the data to matrix. But there is treatment status change from 0 to 1 for some individuals and also a control group with all 0 values in the treated column. I'm not sure why I'm still getting this error.

# Convert the data into a matrix setup = panel.matrices(modified_data, unit = 'id', time = 'week_number', outcome = 'revenue', treatment = 'treated')

Any help is appreciated. Thx in advance.

davidahirshberg commented 1 year ago

Say this: panel=modified_data; unit='id'; time='week_number'; outcome='revenue'; treatment='treated' Then run this code: https://github.com/synth-inference/synthdid/blob/b839f2cc1685c8fddcf274b882f82e2f6eab3894/R/utils.R#L54C1-L77C4 Then tell me what the variables 'treatment' and 'panel[,treatment]' look like.

pearl-yu commented 1 year ago

The same error.

When I type in unique(modified_data[, 'treated']), it returns

treated -- 0 1

But length(unique(modified_data[, 'treated'])) returns 1.

davidahirshberg commented 1 year ago

what is class(modified_data[,'treated']) ?

pearl-yu commented 1 year ago

It returns:

'tbl_df''tbl''data.frame'

davidahirshberg commented 1 year ago

I do not know what that is. Try converting whatever it is to a data frame by saying as.data.frame(modified_data) and see if you can do something with that.

pearl-yu commented 1 year ago

Hi, this worked! Thank you so much! I didn't realize the data.frame was converted to a tibble format when doing some data manipulations.