Currently I have multiple years' data for multiple firms of the monthly stock returns.
| Firm_ID | year | month | return |
|---|---|---|---|
| 101 | 2002 | 1 | 0.05 |
| ... | |||
| 101 | 2014 | 12 | 0.03 |
| 102 | 2003 | 1 | 0.035 |
| ... | |||
| 102 | 2007 | 12 | 0.045 |
| ..... | |||
| 205 | 2004 | 1 | 0.065 |
| ... |
If I calculate it by hand then:
annual compounding return=(1+ Ret_month1)*(1+Ret_month2)*(1+Ret_month3)*...*(1+Ret_month11)*(1+Ret_month12)
However, I don't know how to write a sas program to do this Any suggestions?
Not tested:
data want;
do until (last.year);
set have;
by firm_id year;
if first.year then
compound_ret=1;
compound_ret=compound_ret*(1+return);
end;
run;
Haikuo
Not tested:
data want;
do until (last.year);
set have;
by firm_id year;
if first.year then
compound_ret=1;
compound_ret=compound_ret*(1+return);
end;
run;
Haikuo
Thanks. It works!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.