1

My data frame: df1

ID year category1 wage
1   2008   1       10
1   2009   1       20
1   2010   1       30
2   2008   0       10
2   2009   0       15
2   2010   0       20
3   2008   0       5
3   2009   1       10
3   2010   1       15



I am trying to run a regression using 'DID' package and applied the following code:

library(did)
df1 <- read.csv(file = 'C:/Users/Jui/Desktop/for_did1.csv')
head(df1)

out3 <- att_gt(yname = "wage",
               gname = "category1",
               idname = "id",
               tname = "year",
               xformla = ~1,
               data = df1,
               control_group = "nevertreated",
               anticipation = 0
)
summary(out3)

here, wage is dependent variable and catgegory1 is the treatment

I am getting the following error:

Error in if ((glist[g] <= tlist[(t + 1)])) { : missing value where TRUE/FALSE needed

There is non NaN or NA value in the dataset. But still I am getting the above error

Jui Sen
  • 377
  • 3
  • 12
  • 1
    Error refers to different lines of your code, where you used `if` statement. – zx8754 Jun 04 '21 at 07:47
  • @zx8754 Thanks for your post. I haven't use any ``` if ``` state statement. I have used only the above mentioned code. – Jui Sen Jun 04 '21 at 07:51
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. Without data we can't run the code to see what's going on. – MrFlick Jun 04 '21 at 07:54
  • @MrFlick thank you for your post. I have edited the post and added a short version of my data sample. I actually need to know the meaning of the error and how can I resolve it – Jui Sen Jun 04 '21 at 08:01
  • Error says if-condition results in NA, either you have NA in your data, or the `did` package is creating NAs in the background. Simple example to reproduce this error: `if(NA) { "yes" } else { "no" }` – zx8754 Jun 04 '21 at 08:26
  • Do you still get the error, if you use this small example data from your post? – zx8754 Jun 04 '21 at 08:29
  • yes. I am getting the same error. Can you please tell me what is the meaning of ``` ((glist[g] <= tlist[(t + 1)])) ``` – Jui Sen Jun 04 '21 at 19:08

1 Answers1

0

I found the mistake in my data-frame. It is required to omit the treatment year which are identical to beginning year of the dataset. In other word, treatment cannot be started from the beginning year i.e 2008 in my example.

Jui Sen
  • 377
  • 3
  • 12
  • could you please put the corrected form of the g variable? I am having a hard time figuring out what it should look like. In particular, when my treatment year started in year 2016 for all treated units. – John M. Riveros Nov 28 '22 at 18:22