Hi
I have a daily time-series dataset, wit no weekends, and an event that happens around 8 times per year. The number of occurrences can also differ per year. However, I have a variable, CYC, that represents a cycle formed around each of the events. This cycle variable takes values between -6 to 33 representing days before and after the event day which takes a value of 0.
I want to estimate the slope coefficient (and hopefully the 90% confidence intervals) from a regression of variable y on variable x that is estimated on every day of the cycle variable i.e., for days -6 to 33. Each regression should be estimated using data from a 5-day window, i.e., -2 days before the cycle day to +2 days after the cycle day.
For example, to estimate the regression on cycle day 0, I need to regress y on x using data, across the entire sample, for 5 days starting from two days before cycle day 0 to two days after cycle day 0.
When I estimate the regression on cycle day -1 for exampe, I need to regress y on x using data, across the entire sample, for 5 days starting from two days before cycle day -1 to two days after cycle day -1.
When I estimate the regression on cycle day 7 for example, I need to regress y on x using data, across the entire sample, for 5 days starting from two days before cycle day 7 to two days after cycle day 7.
and so on.
I suspect that -rangestat- might be able to do that but I am not sure how to construct the code as it may require a program in mata. I am open to any other codes or programs other than rangestat that can perform this task.
I should end up with a dataset that provides one slop coefficient on every day of the cycle variable (and hopefully the confidence intervals for this coefficient).
Here is an example of the dataset:
I look forward to your assistance
I have a daily time-series dataset, wit no weekends, and an event that happens around 8 times per year. The number of occurrences can also differ per year. However, I have a variable, CYC, that represents a cycle formed around each of the events. This cycle variable takes values between -6 to 33 representing days before and after the event day which takes a value of 0.
I want to estimate the slope coefficient (and hopefully the 90% confidence intervals) from a regression of variable y on variable x that is estimated on every day of the cycle variable i.e., for days -6 to 33. Each regression should be estimated using data from a 5-day window, i.e., -2 days before the cycle day to +2 days after the cycle day.
For example, to estimate the regression on cycle day 0, I need to regress y on x using data, across the entire sample, for 5 days starting from two days before cycle day 0 to two days after cycle day 0.
When I estimate the regression on cycle day -1 for exampe, I need to regress y on x using data, across the entire sample, for 5 days starting from two days before cycle day -1 to two days after cycle day -1.
When I estimate the regression on cycle day 7 for example, I need to regress y on x using data, across the entire sample, for 5 days starting from two days before cycle day 7 to two days after cycle day 7.
and so on.
I suspect that -rangestat- might be able to do that but I am not sure how to construct the code as it may require a program in mata. I am open to any other codes or programs other than rangestat that can perform this task.
I should end up with a dataset that provides one slop coefficient on every day of the cycle variable (and hopefully the confidence intervals for this coefficient).
Here is an example of the dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(date cycle y x) 12421 9 -.44999998807906394 -.4379999879747576 12422 10 .23999999463557575 .2519999947398821 12423 11 .2099999934434882 .22199999354779454 12424 12 -.07000000029802056 -.05800000019371421 12425 13 .4799999892711737 .49199998937548006 12428 14 .8799999952316284 .8919999953359348 12429 15 -.15999999642372087 -.14799999631941452 12430 16 .03999999910593299 .051999999210239345 12431 17 -.1700000017881398 -.15800000168383344 12432 18 .4699999988079018 .4819999989122081 12435 19 -.24999999999999467 -.23799999989568832 12436 20 .10000000149010813 .11200000159441448 12437 21 -.07999999821185488 -.06799999810754853 12438 22 .2099999934434882 .22199999354779454 12439 23 -.05000000074505406 -.03800000064074771 12442 24 -.4699999988079018 -.4579999987035954 12443 25 -.2599999904632555 -.24799999035894915 12444 26 .40999999642372664 .421999996528033 12445 -6 .7799999713897776 .791999971494084 12446 -5 .4199999868869764 .4319999869912827 12449 -4 .5699999928474364 .5819999929517428 12450 -3 -.28000000119208224 -.26900000125169576 12451 -2 .4300000071525645 .44100000709295095 12452 -1 -.20999999344347708 -.1989999935030906 12453 0 -2.319999933242789 -2.3089999333024025 12456 1 .33000001311302984 .3410000130534163 12457 2 .050000000745065165 .06100000068545164 12458 3 .4399999976158142 .4509999975562007 12459 4 -.6700000166892872 -.6590000167489007 12460 5 .029999999329466398 .04099999926985287 12463 6 .10999999940395355 .12099999934434003 12464 7 .469999998807924 .48099999874831045 12465 8 .05999999865891059 .07099999859929707 12466 9 -.46000000834464094 -.44900000840425447 12467 10 -.4799999892711515 -.46899998933076503 12470 11 0 0 12471 12 .6299999952316337 .6409999951720202 12472 13 -.14000000059604112 -.12900000065565465 12473 14 -1.2499999999999956 -1.239000000059609 12474 15 .3600000143051174 .3710000142455039 12477 16 .3799999952316391 .39099999517202555 12478 17 -.519999980926511 -.5079999808222047 12479 18 -.1299999952316222 -.11799999512731585 12480 19 -.23999999463557575 -.2279999945312694 12481 20 .46000000834465204 .4720000084489584 12484 21 .5600000023841867 .572000002488493 12485 22 -.23000000417232602 -.21800000406801967 12486 23 .15999999642373197 .17199999652803832 12487 24 -.6200000047683729 -.6080000046640666 12488 25 .4399999976158142 .45199999772012056 12491 -6 .2899999916553542 .3019999917596605 12492 -5 .029999999329444194 .041999999433750546 12493 -4 .5600000023841867 .572000002488493 12494 -3 .3000000119209201 .3120000120252264 12495 -2 .050000000745065165 .06200000084937152 12498 -1 -.5000000000000004 -.4879999998956941 12499 0 .03999999910593299 .051999999210239345 12500 1 .029999999329444194 .041999999433750546 12501 2 -.9800000190734792 -.9680000189691729 12502 3 -.6200000047683729 -.6080000046640666 12505 4 -.4699999988079018 -.4579999987035954 12506 5 -1.799999952316278 -1.7879999522119716 12507 6 -1.5299999713897727 -1.5179999712854664 12508 7 -.1299999952316222 -.11799999512731585 12509 8 0 0 12512 9 -1.5800000429153305 -1.5660000424832066 12513 10 2.369999885559082 2.383999885991206 12514 11 .029999999329466398 .0439999997615903 12515 12 .6000000238418624 .6140000242739863 12516 13 -.8100000023841814 -.7960000019520574 12519 14 .33000001311302984 .34400001354515375 12520 15 -.540000021457665 -.5260000210255411 12521 16 -.610000014305101 -.5960000138729771 12522 17 .03999999910593299 .0539999995380569 12523 18 .029999999329466398 .0439999997615903 12526 19 -.8199999928474311 -.8059999924153072 12527 20 -.2599999904632444 -.2459999900311205 12528 21 -.41999998688696527 -.40599998645484137 12529 22 1.470000028610241 1.484000029042365 12530 23 -.05000000074504296 -.036000000312919056 12533 24 1.0000000000000009 1.0140000004321248 12534 25 .050000000745065165 .06400000117718907 12535 26 0 0 12536 27 -.5500000119209147 -.5360000114887908 12537 28 .469999998807924 .4839999992400479 12540 29 .5000000000000115 .5149999996647336 12541 30 -.0099999997764888 .0049999998882332974 12542 31 -.15000000596046004 -.13500000629573794 12543 32 -.10000000149011923 -.08500000182539713 12544 33 -.9100000262260433 -.8950000265613212 12547 -6 -1.2400000095367458 -1.2250000098720237 12548 -5 .5899999737739581 .6049999734386802 12549 -4 -1.0599999427795437 -1.0449999431148216 12550 -3 .3799999952316391 .3949999948963612 12551 -2 .03999999910593299 .05499999877065509 12554 -1 -.15999999642372087 -.14499999675899877 12555 0 .8100000023841814 .8250000020489034 12556 1 1.129999995231623 1.1449999948963452 12557 2 .6100000143051121 .6250000139698342 12558 3 -.23999999463557575 -.22499999497085366 end format %td date
I look forward to your assistance

Comment