I have a panel data which includes daily prices of stocks and daily returns of stocks for many firms. I want to get 1, 3, 6 months cumulative lag returns as well as volatility for the corresponsding time periods for each firm. For example for Firm A I want to get the 1 month lag return and volatility on Feb 1st Year 1 then March 1st then April 1st etc all the way to Year 10 (so total 120 1 month lag returns). Then apply the same procedure to 3 month lag returns and 6 months lags returns. Then performed the entire procedure to all firms in the data set.

I have read about ways to do this using the 'keep' command, that involve dropping daily price data and only keeping the a single cumulative return for each month, however, I need to use the daily data later on so I will need a way to do this without using the 'keep' command. Could you help me get cumulative 1, 3, 6monthly returns and 1,3 and 6 month volatilties?

Thank you for help.

The following is how my data look for just one firm over period of one month.

Permno is the firm bymber, date is date, prc is daily closing price, ret is daily return.

----------------------- copy starting from the next line -----------------------

I have read about ways to do this using the 'keep' command, that involve dropping daily price data and only keeping the a single cumulative return for each month, however, I need to use the daily data later on so I will need a way to do this without using the 'keep' command. Could you help me get cumulative 1, 3, 6monthly returns and 1,3 and 6 month volatilties?

Thank you for help.

The following is how my data look for just one firm over period of one month.

Permno is the firm bymber, date is date, prc is daily closing price, ret is daily return.

----------------------- copy starting from the next line -----------------------

Code:

* Example generated by -dataex-. To install: ssc install dataex clear input double permno long date double(shrcd exchcd siccd prc ret) permno date shrcd exchcd siccd prc ret 10001 03jan2017 1.1e+01 2.0e+00 4925 12.60000038 .003984079 10001 04jan2017 1.1e+01 2.0e+00 4925 12.55000019 -.003968269 10001 05jan2017 1.1e+01 2.0e+00 4925 12.69999981 .011952161 10001 06jan2017 1.1e+01 2.0e+00 4925 12.69999981 0 10001 09jan2017 1.1e+01 2.0e+00 4925 12.60000038 -.007873971 10001 10jan2017 1.1e+01 2.0e+00 4925 12.75 .011904731 10001 11jan2017 1.1e+01 2.0e+00 4925 12.69999981 -.003921584 10001 12jan2017 1.1e+01 2.0e+00 4925 12.64999962 -.003937023 10001 13jan2017 1.1e+01 2.0e+00 4925 12.64999962 0 10001 17jan2017 1.1e+01 2.0e+00 4925 12.60000038 -.003952509 10001 18jan2017 1.1e+01 2.0e+00 4925 12.64990044 .003960322 10001 19jan2017 1.1e+01 2.0e+00 4925 12.64999962 7.8405e-06 10001 20jan2017 1.1e+01 2.0e+00 4925 12.64999962 0 10001 23jan2017 1.1e+01 2.0e+00 4925 12.69999981 .003952584 10001 24jan2017 1.1e+01 2.0e+00 4925 12.64999962 -.003937023 10001 25jan2017 1.1e+01 2.0e+00 4925 12.69999981 .003952584 10001 26jan2017 1.1e+01 2.0e+00 4925 12.69999981 0 10001 27jan2017 1.1e+01 2.0e+00 4925 12.69999981 0 10001 30jan2017 1.1e+01 2.0e+00 4925 12.64999962 -.003937023 10001 31jan2017 1.1e+01 2.0e+00 4925 12.64999962 0 10001 01feb2017 1.1e+01 2.0e+00 4925 12.64999962 0 10001 02feb2017 1.1e+01 2.0e+00 4925 12.69999981 .003952584 end format %d date

## Comment