I have the following data:
week <- c(1,2,3,4,1,2,3,4,1,2,3,4)
product <- c("A", "A", "A", "A", "B", "B", "B", "B", "C", "C", "C", "C")
price <- c(5,5,6,6,12,12,11,11, 23, 23, 23, 23)
mydf <- cbind.data.frame(week, product, price)
I want to create a new dummy variable that takes a value of 0 for all initial price levels and 1 if the price increased. The new variable would look as follows:
mydf$price_changed <- c(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 ,0)
mydf