Dear users
I have multiple events coded as per their distance from an announcement day 0. The events take numbers from -6 to 33, i.e. { -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 }, where -6 represent 6 days before day 0 and number 33 represents 33 days after day 0. The variable that has these values is labeled as "cycle". In my daily time-series dataset, these cycles are adjacent to each other, i.e., when a cycle ends the next cycle starts. However, while a typical cycles runs from -6 to 33, other cycles can be shorter and run from say -2 to 27. The cycle can never take a value before -6 or a value after 33.
I want to estimate a regression for a window of 5 days around each day in the cycle. Therefore, there should be 40 regressions to represent all days of the cycle.
Here is my data:
I did the following code:
I do not know what went wrong with the loop?!! What makes me think it is wrong is that it seems to be picking up an incorrect number of observations per regression.
For example, if you try something like:
And multiply the number of observations by 5 (as there should be a window of 5 days around each cycle day), you will see that the number of obs is different from the number of observations in the regression.
There are no missing values for the dependent or independent variables. Also, the time series dataset is daily. It has no weekends and it has a few missing days. However, I think this should not be a problem as I use the variable "time".
I would really appreciate any assistance with this matter
I have multiple events coded as per their distance from an announcement day 0. The events take numbers from -6 to 33, i.e. { -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 }, where -6 represent 6 days before day 0 and number 33 represents 33 days after day 0. The variable that has these values is labeled as "cycle". In my daily time-series dataset, these cycles are adjacent to each other, i.e., when a cycle ends the next cycle starts. However, while a typical cycles runs from -6 to 33, other cycles can be shorter and run from say -2 to 27. The cycle can never take a value before -6 or a value after 33.
I want to estimate a regression for a window of 5 days around each day in the cycle. Therefore, there should be 40 regressions to represent all days of the cycle.
Here is my data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(date retr infl cycle) 12421 -.4379999879747576 0 9 12422 .2519999947398821 0 10 12423 .22199999354779454 -.7529186420793931 11 12424 -.05800000019371421 -.6476922856575159 12 12425 .49199998937548006 -.5675136933403084 13 12428 .8919999953359348 -.1829062060379713 14 12429 -.14799999631941452 1.132541406485246 15 12430 .051999999210239345 .6876117110290538 16 12431 -.15800000168383344 2.1938483273635483 17 12432 .4819999989122081 1.0254890384207072 18 12435 -.23799999989568832 -.8807656951864905 19 12436 .11200000159441448 1.5604825117120975 20 12437 -.06799999810754853 1.547373653807777 21 12438 .22199999354779454 .6136717629895714 22 12439 -.03800000064074771 1.072029207366402 23 12442 -.4579999987035954 -.7425293417037483 24 12443 -.24799999035894915 1.5244337943724877 25 12444 .421999996528033 .10042454005582642 26 12445 .791999971494084 .8037517518763057 -6 12446 .4319999869912827 4.385885001254089 -5 12449 .5819999929517428 .10237807752121178 -4 12450 -.26900000125169576 -.48581482595927256 -3 12451 .44100000709295095 1.2778222919669644 -2 12452 -.1989999935030906 3.610154774440529 -1 12453 -2.3089999333024025 .4480062347284372 0 12456 .3410000130534163 -.029894337799963092 1 12457 .06100000068545164 0 2 12458 .4509999975562007 0 3 12459 -.6590000167489007 0 4 12460 .04099999926985287 -.7859015611495589 5 12463 .12099999934434003 2.3521912358714934 6 12464 .48099999874831045 4.178839732149401 7 12465 .07099999859929707 1.1339482016251412 8 12466 -.44900000840425447 0 9 12467 -.46899998933076503 -.40466707984601585 10 12470 0 0 11 12471 .6409999951720202 .8514896750455218 12 12472 -.12900000065565465 .43541366890007605 13 12473 -1.239000000059609 .47331693320577684 14 12474 .3710000142455039 1.5243646588527011 15 12477 .39099999517202555 0 16 12478 -.5079999808222047 -.10542929997720135 17 12479 -.11799999512731585 -.22343245179344326 18 12480 -.2279999945312694 -.45511082398417746 19 12481 .4720000084489584 -2.940778018779746 20 12484 .572000002488493 .4683234004475248 21 12485 -.21800000406801967 .8334439141415245 22 12486 .17199999652803832 -2.098348541818269 23 12487 -.6080000046640666 .6744274318240081 24 12488 .45199999772012056 .1415167869680784 25 12491 .3019999917596605 .33616394297385477 -6 12492 .041999999433750546 .9915544650372341 -5 12493 .572000002488493 -3.283250073830859 -4 12494 .3120000120252264 -.9491470253930308 -3 12495 .06200000084937152 .33768976426772973 -2 12498 -.4879999998956941 -2.596585492063645 -1 12499 .051999999210239345 .19178917268155118 0 12500 .041999999433750546 .34001006035488796 1 12501 -.9680000189691729 .7771827766196536 2 12502 -.6080000046640666 -1.0974243742098777 3 12505 -.4579999987035954 .04743454219793581 4 12506 -1.7879999522119716 1.3928657270070266 5 12507 -1.5179999712854664 .5086320610214753 6 12508 -.11799999512731585 -2.034626822761019 7 12509 0 0 8 12512 -1.5660000424832066 .24298939528729838 9 12513 2.383999885991206 -.7365092835970641 10 12514 .0439999997615903 0 11 12515 .6140000242739863 .11380786290790468 12 12516 -.7960000019520574 .2787635195888093 13 12519 .34400001354515375 .0804331917080485 14 12520 -.5260000210255411 .1555537050230116 15 12521 -.5960000138729771 -.10403268395209728 16 12522 .0539999995380569 .3851601714904467 17 12523 .0439999997615903 .046418782065053406 18 12526 -.8059999924153072 .33985984629417676 19 12527 -.2459999900311205 .5846533238807186 20 12528 -.40599998645484137 1.027287391254951 21 12529 1.484000029042365 .5146464678134081 22 12530 -.036000000312919056 .2506092878137687 23 12533 1.0140000004321248 -.31719122367815267 24 12534 .06400000117718907 -.006361355893142129 25 12535 0 0 26 12536 -.5360000114887908 1.2731798279660753 27 12537 .4839999992400479 -.5364178929443594 28 12540 .5149999996647336 1.3085677687013781 29 12541 .0049999998882332974 .010685685744765713 30 12542 -.13500000629573794 .25370652051436704 31 12543 -.08500000182539713 .18124375121317704 32 12544 -.8950000265613212 -3.065225152930967 33 12547 -1.2250000098720237 .2665850052673965 -6 12548 .6049999734386802 -2.531663560488393 -5 12549 -1.0449999431148216 .5168722915188722 -4 12550 .3949999948963612 .29155003275982916 -3 12551 .05499999877065509 -.26820357894854213 -2 12554 -.14499999675899877 -.6522250615984035 -1 12555 .8250000020489034 .4132320059066271 0 12556 1.1449999948963452 -1.2453641998690859 1 12557 .6250000139698342 .5933305965824383 2 12558 -.22499999497085366 0 3 end format %td date
I did the following code:
Code:
gen time = _n tsset time * Identify unique event days levelsof cycle, local(events) foreach time in `events' { reg retr infl if cycle >= `time' - 2 & cycle <= `time' + 2, r }
For example, if you try something like:
Code:
sum infl if cycle=30
There are no missing values for the dependent or independent variables. Also, the time series dataset is daily. It has no weekends and it has a few missing days. However, I think this should not be a problem as I use the variable "time".
I would really appreciate any assistance with this matter
Comment