Hi,
I am trying to convert date variable in "YMD" format, to biweekly variable.
I want the biweekly variable to account for Monday-to-Sunday as one week, and also account for a month like February, where there are in some cases less than 4-weeks. (So for instance, if the last week of February ends on Wednesday of Week3, Thursday (the very next day) of March 1st, should be classified as another week than Week 3).
Ultimately, I want to aggregate the dataset on biweekly bases, so I am planning on using the "collpase" command with biweekly time variable.
So far I have tried,
This makes sense in my head, but when I try to verify whether this works or not, the "biweek" variable I created is not in a human-readable, which prevents me from physically inspecting the issue with special month like February.
#1. Is there a better way to convert daily or week variable (generated with wofd()) to a biweekly format?
#2. Is there a way to convert the biweek variable to a human-readable format? the best I can think of is creating a new variable using "string()"....
Thanks in advance!
I am trying to convert date variable in "YMD" format, to biweekly variable.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float date 21576 21592 21622 21656 21663 21663 21671 21698 21698 21700 21723 21733 21790 21828 21941 21941 21942 21942 21947 21947 21947 21948 21949 21954 21956 21959 21963 21972 22020 22021 22022 22025 22028 22031 22034 22046 22048 22050 22056 22071 22092 22099 22111 22122 22125 22125 22125 22125 22142 22142 22142 22153 22153 22153 22160 22181 22218 22254 22254 22254 22255 22275 21941 21941 21941 21941 22224 22234 22238 22252 22252 22254 22265 22265 22276 22276 22279 22279 22279 21680 21680 21680 21680 21680 21687 21689 21700 21715 21772 21803 21807 21813 21820 21825 21837 21842 21960 21966 22158 22158 end format %td date
Ultimately, I want to aggregate the dataset on biweekly bases, so I am planning on using the "collpase" command with biweekly time variable.
So far I have tried,
Code:
gen week = wofd(date) format week %tw br week gen biweek = ceil((week - 0.5)/2) replace biweek = biweek + mod(week-1,2)*0.5 if mod(week,2) == 0 preserve collapse (sum) sale_amt, by(biweek) restore
#1. Is there a better way to convert daily or week variable (generated with wofd()) to a biweekly format?
#2. Is there a way to convert the biweek variable to a human-readable format? the best I can think of is creating a new variable using "string()"....
Thanks in advance!
Comment