Hi I would like to identify which row is an addition/deletion compared to data in the previous year. Here is the data frame.
a <- data.frame(Ticker=c("AA","AA","BBX","AA","AAAAX","BBX"), Year=c(2009,2010,2010,2011,2011,2011))
I want to create a dummy variable I=1 if the Ticker has not been shown in the previous year. I want to create another dummy variable A=1 if Ticker has not been shown in any of the previous years. In this sample, there are only two years. But in the real data, there are around 10 years in total. The expected output is as follows,
b <- data.frame(Ticker=c("AA","AA","BBX","AA","AAAAX","BBX"), Year=c(2009,2010,2010,2011,2011,2011),I=c(0,0,1,0,1,0),A=c(0,0,1,0,1,0))
Thank you!