Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Generating variable for a range of dates

    Hi,

    I am looking to create a variable that encompasses several dates. I am doing a project on product sales given a media spike. My data set is organized like this (just a small portion):

    dates times price YeezyShoe
    Tuesday, April 2, 2019 5:29 AM EST 149 0
    Tuesday, April 2, 2019 5:29 AM EST 149 0
    Monday, April 1, 2019 10:34 PM EST 121 0

    I would like to create a variable for 9/9/18-9/15/18. How should I format my code?

  • #2
    because you did not follow the advice in the FAQ, I cannot tell whether your dates are in Stata date format or whether they are strings; if strings, put into Stata date format following the advice in
    Code:
    help datetime
    once that is done you can make, for example, an indicator variable for your range of dates:
    Code:
    gen byte inrange=inrange(dates,td(09sep2018),td(15sep2018))
    where I wrote "dates", you need to put the correct name of the date variable if not "dates"

    Comment

    Working...
    X