I am right now trying to generate annual return volatility for each company using the following formula with the monthly returns. My data contains a single number for all months of a given year for each firm. In the formula y stands for year and m stands for month and i stands for a firm. The units for vola are percentage points. I am not sure how to get to an annual return per company, should I use a loop? I don't even have a clue how to start
Attached is my provided data, where I already generated the company_id for each company, monthly returns are given by ret, and risk-free rate (rf) = rf
How to begin? how do I not double count, how to use an efficient way to get the annual return for each company even though the data is monthly? jeeeesus...
What I tried is:
But I receive an error message "unknown egen function"
Thank you so so so much for your help!!! Best
Attached is my provided data, where I already generated the company_id for each company, monthly returns are given by ret, and risk-free rate (rf) = rf
How to begin? how do I not double count, how to use an efficient way to get the annual return for each company even though the data is monthly? jeeeesus...
What I tried is:
gen excess_ret = (ret - rf)^2
sort company_id
by company_id: egen vola = 100 * sqrt(12 * sum(excess_ret)
sort company_id
by company_id: egen vola = 100 * sqrt(12 * sum(excess_ret)
Thank you so so so much for your help!!! Best
Comment