Dear Statlisters,
I am working on a large dataset. Where day_status = 1 is trading and 0 is non-trading. Observations are unique by permno and date.
The trading day is when the stock market is open and the non-trading day is when it is closed.
Required: I need to add the values of uc, ic, be_rf and bu_rf of non-trading days to the subsequent trading days by writing a foreach loop. For example, The values of Saturday and Sunday must be added to the values of Monday IF it is a trading day.
Please let me know how can I get the required outcome.
Sample data is here:
I am working on a large dataset. Where day_status = 1 is trading and 0 is non-trading. Observations are unique by permno and date.
The trading day is when the stock market is open and the non-trading day is when it is closed.
Required: I need to add the values of uc, ic, be_rf and bu_rf of non-trading days to the subsequent trading days by writing a foreach loop. For example, The values of Saturday and Sunday must be added to the values of Monday IF it is a trading day.
Please let me know how can I get the required outcome.
Sample data is here:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(permno date) byte day_status double uc long ic double(be_rf bu_rf) 10104 18995 1 2 3 0 3 10104 18996 1 1 1 0 1 10104 18997 1 3 5 3 2 10104 18998 1 1 1 0 1 10104 18999 0 5 5 0 5 10104 19000 0 2 2 0 2 10104 19001 1 2 2 0 2 10104 19004 1 4 4 1 3 10104 19005 1 1 2 0 2 10104 19007 0 1 1 0 1 10104 19009 1 3 4 0 4 10104 19010 1 1 1 1 0 10104 19011 1 5 6 1 5 10104 19012 1 2 2 1 1 10104 19013 0 1 1 0 1 10104 19014 0 1 1 0 1 10104 19016 1 2 2 0 2 10104 19017 1 2 2 2 0 10104 19018 1 3 3 0 3 10104 19019 1 1 1 0 1 10104 19022 1 2 2 0 2 10104 19023 1 2 2 1 1 10104 19024 1 2 2 0 2 10104 19025 1 1 1 0 1 10104 19026 1 2 2 2 0 end format %td date
Comment