Hi. I have a date variable named "date" in a string format. I converted it to the date format (variable "daily_date") with the code below. I am trying to create a variable that indicates the week number and the day of the week, i.e. Monday=1, Tuesday=2, Wednesday=3. However, my code below for generating the week number is generating the wrong week number. Any help in generating the week number and day of the week would be much appreicated.
Code:
input str9 date float(daily_date monthly_date weekly_date)
"1/1/2021" 22281 1 1
"1/10/2021" 22290 1 2
"1/10/2021" 22290 1 2
//converting string to the date format
gen daily_date = date(date , "MDY")
format daily_date %td
//gen week number
gen weekly_date = week(daily_date)
0 Response to Extracting day and week from date
Post a Comment