Help with dummy variable generation

Hi I am having trouble generating dummy variables for multiple different years.
So my data is a dataset of Guyana's GDP per capita from 1960 to 2019 (image attached). I have to generate dummy variables for the Great Recession, with 0 for 2007-2009 and 1 for other years for regression.

I use the ifelse() code to generate the dummy variables. If my code is GFC<-ifelse(data3$Year== "1/1/2007", 0, 1) then R successfully generated the dummy variable for year 2007 at 0. However, if I try to combine all 3 years to have them all be at 0 with the code GFC<-ifelse(data3$Year==c(1/1/2007, 1/1/2008, 1/1/2009), 0, 1), instead of getting a 0 at 2007-2009, all of the dummy variable would be 1.

How do I fix my code to get R to generate the dummy variable correctly?

Make sure you don't forget the quotation marks around the dates like you did in your question. What you wrote actually worked for me, but I got a warning. Try replacing == with %in%

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.