I have a Eurobarometer dataset and want to eventually create a logistic regression model and a linear probability model using a set of dates as the dependent variable.

However, the dates in the dataset are displayed as long descriptors such as "Sunday 21st May 2005" in a column labelled v584 .

  1. How can I create a dummy variable to say 0 = before Sunday 29th May 2005, 1 = after Sunday 29th May 2005 from the dates listed?

  2. And how can I include only specific date (E.g., only including the dates a week before "Sunday 29th May 2005" in 0 and only the dates a week after in 1)?

  • $\begingroup$ Since you're using R check the lubridate package: lubridate.tidyverse.org $\endgroup$
    – Erwan
    Commented Aug 1, 2020 at 10:49
  • $\begingroup$ I think this question will be better answered in StackOverflow. $\endgroup$
    – Let's try
    Commented Aug 1, 2020 at 11:00
  • $\begingroup$ Hi, and welcome to Data Science Stack Exchange. You question, as it stands, is purely a technical one: How to perform this operation on the dataset in R. This question is in the scope of Stack Overflow, and would be better suited there. To learn more on how to use this site, please visit: datascience.stackexchange.com/tour. And of course, to ask in Stack Overflow, please visit stackoverflow.com/tour. Good luck! $\endgroup$ Commented Aug 3, 2020 at 8:44

1 Answer 1


The lubridate package provides functions to easily convert character strings into dates in a sensible way. For example, the dmy function can parse strings in a variety of formats so long as the string is in the order of day-month-year. The lubridate functions handle all sorts of separators and extraneous characters.

As for your dummy variable, after you convert your v584 column into dates, just create a new column:

new_column <- as.integer(v584 > dmy("Sunday 29th May 2005"))
  • $\begingroup$ Thank you :) this solved my problem entirely! $\endgroup$ Commented Aug 1, 2020 at 14:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.