with reference to my last post on https://www.statalist.org/forums/for...gression/page3
i want to use weekly data, for that very purpose i need date format based on year and week, and i also need the total number of weeks in a year,i also want to take leads and lags of my variable of interest, and for that, i have to tsset or xtset my data.to avoid the problem of
repeated time values within panel
Code:
egen dategroup=group( year week)
could you please guide me how can i format my date variable trdwnt , so that i can use it for my further work, and also to calculate the total number of trading weeks in a year.
In below example week 2002-07 and 2002-08 are missings, so i want to deal with such like missing values as well.
My dataset example is
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long code str7 trdwnt str10 opndt float wopnprc str10 clsdt float wclsprc int year byte week float dategroup 2 "2002-01" "2002-01-04" 13.01 "2002-01-04" 12.99 2002 1 1 2 "2002-02" "2002-01-07" 12.9 "2002-01-11" 12.31 2002 2 2 2 "2002-03" "2002-01-14" 12.2 "2002-01-18" 11.28 2002 3 3 2 "2002-04" "2002-01-21" 11.27 "2002-01-25" 12 2002 4 4 2 "2002-05" "2002-01-28" 11.76 "2002-02-01" 12.49 2002 5 5 2 "2002-06" "2002-02-04" 12.45 "2002-02-08" 12.5 2002 6 6 2 "2002-09" "2002-02-25" 12.91 "2002-03-01" 12.47 2002 9 7 2 "2002-10" "2002-03-04" 12.45 "2002-03-08" 13.4 2002 10 8 2 "2002-11" "2002-03-11" 13.39 "2002-03-15" 13.01 2002 11 9 2 "2002-12" "2002-03-18" 13.4 "2002-03-22" 13.12 2002 12 10 2 "2002-13" "2002-03-25" 13.1 "2002-03-29" 12.68 2002 13 11 2 "2002-14" "2002-04-01" 12.6 "2002-04-05" 12.66 2002 14 12 2 "2002-15" "2002-04-08" 12.61 "2002-04-12" 12.72 2002 15 13 2 "2002-16" "2002-04-15" 12.72 "2002-04-19" 12.47 2002 16 14 2 "2002-17" "2002-04-22" 12.35 "2002-04-26" 12.33 2002 17 15 2 "2002-18" "2002-04-29" 12.33 "2002-04-30" 12.42 2002 18 16 2 "2002-19" "2002-05-08" 12.4 "2002-05-10" 12.14 2002 19 17 2 "2002-20" "2002-05-13" 12.06 "2002-05-17" 11.48 2002 20 18 2 "2002-21" "2002-05-20" 11.51 "2002-05-24" 11.82 2002 21 19 2 "2002-22" "2002-05-27" 11.94 "2002-05-31" 11.3 2002 22 20 2 "2002-23" "2002-06-03" 11.2 "2002-06-07" 11.42 2002 23 21 2 "2002-24" "2002-06-10" 11.42 "2002-06-11" 11.43 2002 24 22 2 "2002-25" "2002-06-18" 11.5 "2002-06-21" 11.9 2002 25 23 2 "2002-26" "2002-06-24" 13.09 "2002-06-28" 13.21 2002 26 24 2 "2002-27" "2002-07-01" 13.27 "2002-07-05" 12.83 2002 27 25 2 "2002-28" "2002-07-08" 12.85 "2002-07-12" 12.59 2002 28 26 2 "2002-29" "2002-07-15" 12.55 "2002-07-19" 12.52 2002 29 27 2 "2002-30" "2002-07-22" 12.51 "2002-07-26" 12.01 2002 30 28 2 "2002-31" "2002-07-29" 12.05 "2002-08-02" 12.13 2002 31 29 2 "2002-32" "2002-08-05" 12.18 "2002-08-09" 11.9 2002 32 30 2 "2002-33" "2002-08-12" 11.87 "2002-08-16" 11.79 2002 33 31 2 "2002-34" "2002-08-19" 11.78 "2002-08-23" 12.14 2002 34 32 2 "2002-35" "2002-08-26" 12.1 "2002-08-30" 11.87 2002 35 33 2 "2002-36" "2002-09-02" 11.87 "2002-09-06" 11.72 2002 36 34 2 "2002-37" "2002-09-09" 11.7 "2002-09-13" 11.58 2002 37 35 2 "2002-38" "2002-09-16" 11.57 "2002-09-20" 11.55 2002 38 36 2 "2002-39" "2002-09-23" 11.53 "2002-09-27" 11.43 2002 39 37 2 "2002-41" "2002-10-08" 11.38 "2002-10-11" 11.1 2002 41 38 2 "2002-42" "2002-10-14" 11.19 "2002-10-18" 11.1 2002 42 39 2 "2002-43" "2002-10-21" 11.1 "2002-10-25" 11.1 2002 43 40 2 "2002-44" "2002-10-28" 11 "2002-11-01" 11.05 2002 44 41 2 "2002-45" "2002-11-04" 11.05 "2002-11-08" 11.24 2002 45 42 2 "2002-46" "2002-11-11" 11.2 "2002-11-15" 10.09 2002 46 43 2 "2002-47" "2002-11-18" 10.09 "2002-11-22" 10.22 2002 47 44 2 "2002-48" "2002-11-25" 10.21 "2002-11-29" 10.13 2002 48 45 2 "2002-49" "2002-12-02" 10.13 "2002-12-06" 9.86 2002 49 46 2 "2002-50" "2002-12-09" 9.8 "2002-12-13" 9.77 2002 50 47 2 "2002-51" "2002-12-16" 9.78 "2002-12-20" 9.94 2002 51 48 2 "2002-52" "2002-12-23" 9.91 "2002-12-27" 9.79 2002 52 49 2 "2002-53" "2002-12-30" 9.7 "2002-12-31" 9.65 2002 53 50 2 "2003-01" "2003-01-02" 9.48 "2003-01-03" 9.09 2003 1 51 2 "2003-02" "2003-01-06" 9.08 "2003-01-10" 9.54 2003 2 52 2 "2003-03" "2003-01-13" 9.5 "2003-01-17" 10.16 2003 3 53 2 "2003-04" "2003-01-20" 10.16 "2003-01-24" 9.96 2003 4 54 2 "2003-05" "2003-01-27" 9.96 "2003-01-29" 10.07 2003 5 55 2 "2003-07" "2003-02-10" 10.1 "2003-02-14" 10.26 2003 7 56 2 "2003-08" "2003-02-17" 10.25 "2003-02-21" 9.94 2003 8 57 2 "2003-09" "2003-02-24" 9.94 "2003-02-28" 10.33 2003 9 58 2 "2003-10" "2003-03-03" 10.35 "2003-03-07" 10.9 2003 10 59 2 "2003-11" "2003-03-10" 10.9 "2003-03-14" 11.31 2003 11 60 2 "2003-12" "2003-03-17" 11.32 "2003-03-21" 11.42 2003 12 61 2 "2003-13" "2003-03-24" 11.46 "2003-03-28" 11.55 2003 13 62 2 "2003-14" "2003-03-31" 11.58 "2003-04-04" 11.98 2003 14 63 2 "2003-15" "2003-04-07" 12 "2003-04-11" 12.76 2003 15 64 2 "2003-16" "2003-04-14" 12.78 "2003-04-18" 13.89 2003 16 65 2 "2003-17" "2003-04-21" 13.79 "2003-04-25" 12.21 2003 17 66 2 "2003-18" "2003-04-28" 12.01 "2003-04-30" 12.84 2003 18 67 2 "2003-20" "2003-05-12" 12.92 "2003-05-16" 13.88 2003 20 68 2 "2003-21" "2003-05-19" 13.93 "2003-05-23" 6.79 2003 21 69 2 "2003-22" "2003-05-26" 6.79 "2003-05-30" 7.13 2003 22 70 2 "2003-23" "2003-06-02" 7.1 "2003-06-06" 6.78 2003 23 71 2 "2003-24" "2003-06-09" 6.78 "2003-06-13" 6.82 2003 24 72 2 "2003-25" "2003-06-16" 6.79 "2003-06-20" 6.41 2003 25 73 2 "2003-26" "2003-06-23" 6.4 "2003-06-27" 5.83 2003 26 74 2 "2003-27" "2003-06-30" 5.7 "2003-07-04" 6 2003 27 75 2 "2003-28" "2003-07-07" 6 "2003-07-11" 6.21 2003 28 76 2 "2003-29" "2003-07-14" 6.21 "2003-07-18" 6.25 2003 29 77 2 "2003-30" "2003-07-21" 6.2 "2003-07-25" 6.16 2003 30 78 2 "2003-31" "2003-07-28" 6.16 "2003-08-01" 6.39 2003 31 79 2 "2003-32" "2003-08-04" 6.38 "2003-08-08" 6.49 2003 32 80 2 "2003-33" "2003-08-11" 6.48 "2003-08-15" 6.5 2003 33 81 2 "2003-34" "2003-08-18" 6.52 "2003-08-22" 6.64 2003 34 82 2 "2003-35" "2003-08-25" 6.6 "2003-08-29" 6.46 2003 35 83 2 "2003-36" "2003-09-01" 6.45 "2003-09-05" 6.34 2003 36 84 2 "2003-37" "2003-09-08" 6.34 "2003-09-12" 6.04 2003 37 85 2 "2003-38" "2003-09-15" 6.02 "2003-09-19" 5.81 2003 38 86 2 "2003-39" "2003-09-22" 5.83 "2003-09-26" 5.91 2003 39 87 2 "2003-40" "2003-09-29" 5.9 "2003-09-30" 5.86 2003 40 88 2 "2003-41" "2003-10-08" 5.88 "2003-10-10" 6.05 2003 41 89 2 "2003-42" "2003-10-13" 6.09 "2003-10-17" 5.9 2003 42 90 2 "2003-43" "2003-10-20" 5.88 "2003-10-24" 6.06 2003 43 91 2 "2003-44" "2003-10-28" 6.02 "2003-10-31" 5.94 2003 44 92 2 "2003-45" "2003-11-03" 5.89 "2003-11-07" 5.95 2003 45 93 2 "2003-46" "2003-11-10" 5.95 "2003-11-14" 5.81 2003 46 94 2 "2003-47" "2003-11-17" 5.81 "2003-11-21" 5.87 2003 47 95 2 "2003-48" "2003-11-24" 5.87 "2003-11-28" 5.91 2003 48 96 2 "2003-49" "2003-12-01" 5.91 "2003-12-05" 6.02 2003 49 97 2 "2003-50" "2003-12-08" 6.01 "2003-12-12" 6.11 2003 50 98 2 "2003-51" "2003-12-15" 6.12 "2003-12-19" 6 2003 51 99 2 "2003-52" "2003-12-22" 6 "2003-12-26" 6.53 2003 52 100 end label var code "Stkcd" label var trdwnt "Trading Week '" label var opndt "Weekly Opening Date '" label var wopnprc "Weekly Opening Price '" label var clsdt "Weekly Closing Date '" label var wclsprc "Weekly Closing Price '" label var dategroup "group(year week)"
Listed 100 out of 1755974 observations
Use the count() option to list more
Best regards,
0 Response to Handling weekly data
Post a Comment