Dear Stata Users,
I have the sample of data attached below. I need to create a “week” date that goes from Wednesday till Wednesday. For this, I used the following code:
Code:
gen week_start = cond(dow(date) >= 3, date - dow(date) + 3, date - dow(date) - 4)
The problem is that it generates a date variable (with a difference of 7 between two dates) that I cant format into %tw, so that stata understands the id and time variable:
Code:
xtset permno week_start
Can you, please help me to resolve this issue.


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double permno long date
10000 9502
10000 9503
10000 9504
10000 9505
10000 9506
10000 9509
10000 9510
10000 9511
10000 9512
10000 9513
10000 9516
10000 9517
10000 9518
10000 9519
10000 9520
10000 9523
10000 9524
10000 9525
10000 9526
10000 9527
10000 9530
10000 9531
10000 9532
10000 9533
10000 9534
10000 9537
10000 9538
10000 9539
10000 9540
10000 9541
10000 9545
10000 9546
10000 9547
10000 9548
10000 9551
10001 9510
10001 9511
10001 9512
10001 9513
10001 9516
10001 9517
10001 9518
10001 9519
10001 9520
10001 9523
10001 9524
10001 9525
10001 9526
10001 9527
10001 9530
10001 9531
10001 9532
10001 9533
10001 9534
10001 9537
10001 9538
10001 9539
10001 9540
10001 9541
10001 9545
10001 9546
10001 9547
10001 9548
10001 9551
10001 9552
10001 9553
10001 9554
10001 9555
10001 9558
10001 9559
10001 9560
10001 9561
10001 9562
10001 9565
10001 9566
10001 9567
10001 9568
10001 9569
10001 9572
10001 9573
10001 9574
10001 9575
10001 9576
10001 9579
10001 9580
10001 9581
10001 9582
10001 9586
10001 9587
10001 9588
10001 9589
10001 9590
10001 9593
10001 9594
10001 9595
10001 9596
10001 9597
10001 9600
10001 9601
10001 9602
end
format %d date