I am generating a date calendar file, and have Stata date variables for date (daily), and weekstartdate (date beginning on Sundays). I would like to add a variable for FluWatch week, that aligns with this surveillance calendar
(https://www.canada.ca/en/public-heal...-calendar.html).
The range of dates includes Jan 1 2013 to Dec 31, 2027, so I would like to generate some logic to infill the corresponding FluWatch week for all of these dates. The FluWatch week starts at one, if the week beginning on Sunday includes Jan 1st for that year.
What datetime functions could be used here to start each year with FluWeek=1 where the first week contains Jan 1st, and count the number of weeks from there? Here is what I've tried so far, but the weeknum count does not make any replacements
(https://www.canada.ca/en/public-heal...-calendar.html).
The range of dates includes Jan 1 2013 to Dec 31, 2027, so I would like to generate some logic to infill the corresponding FluWatch week for all of these dates. The FluWatch week starts at one, if the week beginning on Sunday includes Jan 1st for that year.
What datetime functions could be used here to start each year with FluWeek=1 where the first week contains Jan 1st, and count the number of weeks from there? Here is what I've tried so far, but the weeknum count does not make any replacements
Code:
*** 1. H Generate FluWatchWeekNumber Variable ************************************ gen FluWatchWeekNumber=0 gen yearstart=mdy(1, 1, year) format yearstart %tdCCYY-NN-DD replace FluWatchWeekNumber=1 if datediff(yearstart, date, "day")<7 gen weeknum=0 replace weeknum=datediff(yearstart, date, "week")
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(date weekstartdate year monthyear) 19359 19357 2013 19359 19360 19357 2013 19359 19361 19357 2013 19359 19362 19357 2013 19359 19363 19357 2013 19359 19364 19364 2013 19359 19365 19364 2013 19359 19366 19364 2013 19359 19367 19364 2013 19359 19368 19364 2013 19359 19369 19364 2013 19359 19370 19364 2013 19359 19371 19371 2013 19359 19372 19371 2013 19359 19373 19371 2013 19359 19374 19371 2013 19359 19375 19371 2013 19359 19376 19371 2013 19359 19377 19371 2013 19359 19378 19378 2013 19359 19379 19378 2013 19359 19380 19378 2013 19359 19381 19378 2013 19359 19382 19378 2013 19359 19383 19378 2013 19359 19384 19378 2013 19359 19385 19385 2013 19359 19386 19385 2013 19359 19387 19385 2013 19359 19388 19385 2013 19359 19389 19385 2013 19359 19390 19385 2013 19390 19391 19385 2013 19390 19392 19392 2013 19390 19393 19392 2013 19390 19394 19392 2013 19390 19395 19392 2013 19390 19396 19392 2013 19390 19397 19392 2013 19390 19398 19392 2013 19390 19399 19399 2013 19390 19400 19399 2013 19390 19401 19399 2013 19390 19402 19399 2013 19390 19403 19399 2013 19390 19404 19399 2013 19390 19405 19399 2013 19390 19406 19406 2013 19390 19407 19406 2013 19390 19408 19406 2013 19390 19409 19406 2013 19390 19410 19406 2013 19390 19411 19406 2013 19390 19412 19406 2013 19390 19413 19413 2013 19390 19414 19413 2013 19390 19415 19413 2013 19390 19416 19413 2013 19390 19417 19413 2013 19390 19418 19413 2013 19418 19419 19413 2013 19418 19420 19420 2013 19418 19421 19420 2013 19418 19422 19420 2013 19418 19423 19420 2013 19418 19424 19420 2013 19418 19425 19420 2013 19418 19426 19420 2013 19418 19427 19427 2013 19418 19428 19427 2013 19418 19429 19427 2013 19418 19430 19427 2013 19418 19431 19427 2013 19418 19432 19427 2013 19418 19433 19427 2013 19418 19434 19434 2013 19418 19435 19434 2013 19418 19436 19434 2013 19418 19437 19434 2013 19418 19438 19434 2013 19418 19439 19434 2013 19418 19440 19434 2013 19418 19441 19441 2013 19418 19442 19441 2013 19418 19443 19441 2013 19418 19444 19441 2013 19418 19445 19441 2013 19418 19446 19441 2013 19418 19447 19441 2013 19418 19448 19448 2013 19418 19449 19448 2013 19449 19450 19448 2013 19449 19451 19448 2013 19449 19452 19448 2013 19449 19453 19448 2013 19449 19454 19448 2013 19449 19455 19455 2013 19449 19456 19455 2013 19449 19457 19455 2013 19449 19458 19455 2013 19449 end format %tdCCYY-NN-DD date format %tdCCYY-NN-DD weekstartdate format %tdCCYY-NN-DD monthyear
Comment