Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- drop *
- input str9 period_start_string str9 period_end_string
- "01Nov2000" "01Jan2000"
- "01Dec2000" "01Feb2000"
- "01Jan2000" "01Mar2000"
- "01Feb2000" "01Apr2000"
- end
- *Select only the month from the input
- gen psd_month_only_str = substr(period_start_string, 3, 3)
- gen ped_month_only_str = substr(period_end_string, 3, 3)
- *Create date format variable from month only variable above
- gen psd_month_only_date = date(psd_month_only_str, "M")
- gen ped_month_only_date = date(ped_month_only_str, "M")
- *Create month format variable from above date variable taken from month only input
- gen psd_month_only_month = month(psd_month_only_date)
- gen ped_month_only_month = month(ped_month_only_date)
- *check if month only data start > end in MONTH format
- if psd_month_only_month > ped_month_only_month{
- gen smonth_gt_e_date = 1
- }
- else{
- gen smonth_gt_e_date = 0
- }
- *begin working with whole date
- *take string variable for whole date, create date format variable
- gen psd_date = date(period_start_string, "DMY")
- gen ped_date = date(period_end_string, "DMY")
- format psd_date %d
- format ped_date %d
- *take date format variable for whole date, create month format variable
- gen psd_month = month(psd_date)
- gen ped_month = month(ped_date)
- *format psd_month %d
- *format ped_month %d
- gen psd_mofd = mofd(psd_date)
- gen ped_mofd = mofd(ped_date)
- *format psd_mofd %d
- *format ped_mofd %d
- *check if start > end in STRING format
- if period_start_string > period_end_string{
- gen s_gt_e_string = 1
- }
- else{
- gen s_gt_e_string = 0
- }
- *check if start > end in DATE format
- if psd_date > ped_date{
- gen s_gt_e_date = 1
- }
- else{
- gen s_gt_e_date = 0
- }
- *check if start > end in MONTH format
- if psd_month > ped_month{
- gen s_gt_e_month = 1
- }
- else{
- gen s_gt_e_month = 0
- }
- *check if start > end in MOFD format
- if psd_mofd > ped_mofd{
- gen s_gt_e_mofd = 1
- }
- else{
- gen s_gt_e_mofd = 0
- }
- describe
- list
- *test one value at a time only
- if "01nov1960" > "01jan1960"{
- display "True"
- }
- else{
- display "False"
- }
- if "01jan1960" > "01nov1960"{
- display "True"
- }
- else{
- display "False"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement