Dear Statalist participants
I have year, quarter, month, week in my data and I want to create a Stata date variable on a weekly basis and sort my data accordingly.
the quarter runs from 1 to 4 , But the month variable runs from 1 to 3 (i.e. during the quarter) and the week variable runs from 1 to 4 (i.e. during the month).
I need:
1- to create a date variable
2- to sort my data weekly using the date variable in order to run weekly regressions
Another related question: in order to run my analysis on a weekly basis, would it be easier if the month variable runs from 1 to 12 and the the week variable runs from 1 to 48 ( weeks are stylized so there are 48 weeks indeed for each given year). Or it does not make a difference?
I upload a sample using dataex for you
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int year byte(quarter month week) float earnings
1987 1 1 1 1.7705997
1987 1 1 2 .4728113
1987 1 1 3 .3941394
1987 1 1 4 .11440884
1987 1 2 1 .160652
1987 1 2 2 .3961538
1987 1 2 3 .45841575
1987 1 2 4 .5288332
1987 1 3 1 .8589164
1987 1 3 2 .8497481
1987 1 3 3 .8618858
1987 1 3 4 .961287
1987 2 1 1 1.345534
1987 2 1 2 1.1195575
1987 2 1 3 .3546848
1987 2 1 4 .4636721
1987 2 2 1 .7540874
1987 2 2 2 .8403442
1987 2 2 3 .8561469
1987 2 2 4 .8706375
1987 2 3 1 1.383695
1987 2 3 2 1.3878306
1987 2 3 3 1.3569516
1987 2 3 4 1.2848142
1987 3 1 1 1.087582
1987 3 1 2 .7876818
1987 3 1 3 .200033
1987 3 1 4 .16993275
1987 3 2 1 .2436485
1987 3 2 2 .2782035
1987 3 2 3 .32997075
1987 3 2 4 .3608698
1987 3 3 1 .5761423
1987 3 3 2 .6065645
1987 3 3 3 .6020274
1987 3 3 4 .6339163
1987 4 1 1 1.3598517
1987 4 1 2 .56407243
1987 4 1 3 .3157399
1987 4 1 4 .22502215
1987 4 2 1 .3535852
1987 4 2 2 .3888265
1987 4 2 3 .425247
1987 4 2 4 .4753116
1987 4 3 1 .7817153
1987 4 3 2 .7864803
1987 4 3 3 .7770564
1987 4 3 4 .810554
1988 1 1 1 1.9881122
1988 1 1 2 .9616702
1988 1 1 3 .9560576
1988 1 1 4 -.02433528
1988 1 2 1 .06566841
1988 1 2 2 .1756358
1988 1 2 3 .2455934
1988 1 2 4 .29687575
1988 1 3 1 .4343888
1988 1 3 2 .4354226
1988 1 3 3 .4378992
1988 1 3 4 .4880208
1988 2 1 1 2.0682137
1988 2 1 2 .7863678
1988 2 1 3 .16332495
1988 2 1 4 .1944389
1988 2 2 1 .3070929
1988 2 2 2 .4097694
1988 2 2 3 .4642496
1988 2 2 4 .4707479
1988 2 3 1 .755556
1988 2 3 2 .7392501
1988 2 3 3 .7286718
1988 2 3 4 .7465883
1988 3 1 1 1.2585707
1988 3 1 2 .4756329
1988 3 1 3 .17472464
1988 3 1 4 -.10320017
1988 3 2 1 -.1050039
1988 3 2 2 -.06223335
1988 3 2 3 -.0396569
1988 3 2 4 -.001310848
1988 3 3 1 .010440214
1988 3 3 2 .03693339
1988 3 3 3 .03542653
1988 3 3 4 .07352171
1988 4 1 1 1.9921095
1988 4 1 2 1.0118054
1988 4 1 3 -.1854238
1988 4 1 4 .08538733
1988 4 2 1 .20397782
1988 4 2 2 .2374128
1988 4 2 3 .28562233
1988 4 2 4 .28901428
1988 4 3 1 .47351405
1988 4 3 2 .4622011
1988 4 3 3 .4750741
1988 4 3 4 .48286
1989 1 1 1 2.0214815
1989 1 1 2 1.0627728
1989 1 1 3 .6280478
1989 1 1 4 -.03181221
end
Thanks
Mike