I'm working on the U.S. stock market.
I have entire stock market data ( thousands of stocks). It's panel data( sorted by firms and dates).
My question is how I can create lead variables with respect to month when I have daily data. I should not collapse data since I have to use daily return later.
In detail, I have past 1 month return on each month of each stock. I should create future return which is dragged from the past return.
For example, If 1 month past return on Feb of firm A is 0.1, I have to make a new variable (future return) on Jan of firm A 0.1.
1 month past return of Feb 01, 02, 03, 04..(they are same). into 1 month past return of Jan 01, 02, 03, 04...(they are same)
I created 1 month mean past returns and they are same within the same month. For example, past_ret_1 of Jan 01is same as past_ret_1 of Jan 02, Jan 03, Jan 04...
So, I have to put past_ret_1 of Feb 01, Feb 02, Feb 03 which are same into past_ret_1 of Jan 01, 02, 03....
permno is the firm code
date is date
past_ret_1 is 1 month past return
mdate is month identifier.
My data looks like below and I add my dataex below too. I have to create B's from Bs (B and B' are same)
permno | date | mdate | past_ret_1 | future_ret1 | |
10001 | Jan 01 2019 | 2019m1 | A | B' | |
10001 | Jan 02 2019 | 2019m1 | A | B' | |
10001 | Jan 03 2019 | 2019m1 | A | B' | |
... | ... | ||||
10001 | Feb 01 2019 | 2019m2 | B | ||
10001 | Feb 02 2019 | 2019m2 | B | ||
... | ... | ... | |||
10002 | 2019m1 | 0.1 | |||
10002 | 2019m1 | 0.1 |
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double permno long date double prc int mdate float(past_ret_1 past_ret_3 past_ret_6) 10001 20457 7.519999980926514 672 . . . 10001 20458 7.420000076293945 672 . . . 10001 20459 7.53000020980835 672 . . . 10001 20460 7.639999866485596 672 . . . 10001 20461 7.789999961853027 672 . . . 10001 20464 8.0600004196167 672 . . . 10001 20465 8.25 672 . . . 10001 20466 8.25 672 . . . 10001 20467 8.130000114440918 672 . . . 10001 20468 7.989999771118164 672 . . . 10001 20472 8.119999885559082 672 . . . 10001 20473 8.079999923706055 672 . . . 10001 20474 8.100000381469727 672 . . . 10001 20475 8.220000267028809 672 . . . 10001 20478 8 672 . . . 10001 20479 8.100000381469727 672 . . . 10001 20480 8.199999809265137 672 . . . 10001 20481 8.199999809265137 672 . . . 10001 20482 8.319999694824219 672 . . . 10001 20485 8.420000076293945 673 .11968087 .11968087 .11968087 10001 20486 8.489899635314941 673 .11968087 .11968087 .11968087 10001 20487 8.260000228881836 673 .11968087 .11968087 .11968087 10001 20488 8 673 .11968087 .11968087 .11968087 10001 20489 8.34000015258789 673 .11968087 .11968087 .11968087 10001 20492 8.630000114440918 673 .11968087 .11968087 .11968087 10001 20493 8.210000038146973 673 .11968087 .11968087 .11968087 10001 20494 8.300000190734863 673 .11968087 .11968087 .11968087 10001 20495 8.050000190734863 673 .11968087 .11968087 .11968087 10001 20496 8.300000190734863 673 .11968087 .11968087 .11968087 10001 20500 8.25 673 .11968087 .11968087 .11968087 10001 20501 8.199999809265137 673 .11968087 .11968087 .11968087 10001 20502 8.100000381469727 673 .11968087 .11968087 .11968087 10001 20503 7.900000095367432 673 .11968087 .11968087 .11968087 10001 20506 7.860000133514404 673 .11968087 .11968087 .11968087 10001 20507 7.940000057220459 673 .11968087 .11968087 .11968087 10001 20508 7.880000114440918 673 .11968087 .11968087 .11968087 10001 20509 7.940000057220459 673 .11968087 .11968087 .11968087 10001 20510 7.840000152587891 673 .11968087 .11968087 .11968087 10001 20513 7.860000133514404 673 .11968087 .11968087 .11968087 10001 20514 8.300000190734863 674 -.014251768 .10372343 .10372343 10001 20515 8.15999984741211 674 -.014251768 .10372343 .10372343 10001 20516 8.199999809265137 674 -.014251768 .10372343 .10372343 10001 20517 8.199999809265137 674 -.014251768 .10372343 .10372343 10001 20520 8.1899995803833 674 -.014251768 .10372343 .10372343 10001 20521 8.079999923706055 674 -.014251768 .10372343 .10372343 10001 20522 8.029999732971191 674 -.014251768 .10372343 .10372343 10001 20523 8.119999885559082 674 -.014251768 .10372343 .10372343 10001 20524 8 674 -.014251768 .10372343 .10372343 10001 20527 7.980000019073486 674 -.014251768 .10372343 .10372343 10001 20528 7.900000095367432 674 -.014251768 .10372343 .10372343 10001 20529 8.069999694824219 674 -.014251768 .10372343 .10372343 10001 20530 8.119999885559082 674 -.014251768 .10372343 .10372343 10001 20531 8.199999809265137 674 -.014251768 .10372343 .10372343 10001 20534 8.199999809265137 674 -.014251768 .10372343 .10372343 10001 20535 8.199999809265137 674 -.014251768 .10372343 .10372343 10001 20536 8.239999771118164 674 -.014251768 .10372343 .10372343 10001 20537 8.079999923706055 674 -.014251768 .10372343 .10372343 10001 20541 7.900000095367432 674 -.014251768 .10372343 .10372343 10001 20542 7.889999866485596 674 -.014251768 .10372343 .10372343 10001 20543 7.889999866485596 674 -.014251768 .10372343 .10372343 10001 20544 7.809999942779541 674 -.014251768 .10372343 .10372343 10001 20545 7.800000190734863 675 -.06024096 .03723407 .03723407 10001 20548 7.769999980926514 675 -.06024096 .03723407 .03723407 10001 20549 7.230000019073486 675 -.06024096 .03723407 .03723407 10001 20550 7.079999923706055 675 -.06024096 .03723407 .03723407 10001 20551 7.369999885559082 675 -.06024096 .03723407 .03723407 10001 20552 7.579999923706055 675 -.06024096 .03723407 .03723407 10001 20555 7.769999980926514 675 -.06024096 .03723407 .03723407 10001 20556 7.869999885559082 675 -.06024096 .03723407 .03723407 10001 20557 7.800000190734863 675 -.06024096 .03723407 .03723407 10001 20558 7.599999904632568 675 -.06024096 .03723407 .03723407 10001 20559 7.449999809265137 675 -.06024096 .03723407 .03723407 10001 20562 7.21999979019165 675 -.06024096 .03723407 .03723407 10001 20563 7.309999942779541 675 -.06024096 .03723407 .03723407 10001 20564 7.179999828338623 675 -.06024096 .03723407 .03723407 10001 20565 7 675 -.06024096 .03723407 .03723407 10001 20566 7.179999828338623 675 -.06024096 .03723407 .03723407 10001 20569 7.199999809265137 675 -.06024096 .03723407 .03723407 10001 20570 7.349999904632568 675 -.06024096 .03723407 .03723407 10001 20571 7.28000020980835 675 -.06024096 .03723407 .03723407 10001 20572 7.329999923706055 675 -.06024096 .03723407 .03723407 10001 20573 7.300000190734863 675 -.06024096 .03723407 .03723407 10001 20576 6.909999847412109 676 -.1141026 -.17933494 -.08111704 10001 20577 7.039999961853027 676 -.1141026 -.17933494 -.08111704 10001 20578 7.039999961853027 676 -.1141026 -.17933494 -.08111704 10001 20579 7.014999866485596 676 -.1141026 -.17933494 -.08111704 10001 20580 6.880000114440918 676 -.1141026 -.17933494 -.08111704 10001 20583 6.889999866485596 676 -.1141026 -.17933494 -.08111704 10001 20584 6.96999979019165 676 -.1141026 -.17933494 -.08111704 10001 20585 7.050000190734863 676 -.1141026 -.17933494 -.08111704 10001 20586 7.099999904632568 676 -.1141026 -.17933494 -.08111704 10001 20587 7.150000095367432 676 -.1141026 -.17933494 -.08111704 10001 20590 7.119999885559082 676 -.1141026 -.17933494 -.08111704 10001 20591 7.139999866485596 676 -.1141026 -.17933494 -.08111704 10001 20592 7.059999942779541 676 -.1141026 -.17933494 -.08111704 10001 20593 6.900000095367432 676 -.1141026 -.17933494 -.08111704 10001 20594 6.880000114440918 676 -.1141026 -.17933494 -.08111704 10001 20597 6.900000095367432 676 -.1141026 -.17933494 -.08111704 10001 20598 6.900000095367432 676 -.1141026 -.17933494 -.08111704 10001 20599 6.949999809265137 676 -.1141026 -.17933494 -.08111704 end format %d date format %tm mdate
Listed 100 out of 5502429 observations
Use the count() option to list more
0 Response to Creating Lead variables with respect to month (1, 3, 6) when I have daily data
Post a Comment