- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Everyone.
I want to calculate standard deviation of the firm's daily returns during a given year. I have permno as identifier for each firm and daily data for stock return. Such as below.
Permno date ret
10000 10/03/2002 0.005
10000 10/06/2002 0.0051
10002 12/06/2002 0.007
and so on.
Could you please help me to calculate standard deviation of the firm's daily returns during a given year?
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you want std of returns for each permno for the same year, then, assuming data are sorted by PERMNO:
proc summary data=have ;
by permno ;
where '01jan2022'd <= date <= '31dec2022'd;
var ret;
output out=want (drop=_:) std=retstd;
run;
If you want it for each year in a series of multiple years, then, if data are sorted by permno year:
data need / view=need;
set have;
year=year(date);
run;
proc summary data=need ;
by permno year;
var ret;
output out=want (drop=_:) std=retstd;
run;
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your reply.
I want to get yearly std for each firm (permno) which has daily stock return. Which means for each firm in each year, I need to have one std at the end.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Fer_ wrote:
Thanks for your reply.
I want to get yearly std for each firm (permno) which has daily stock return. Which means for each firm in each year, I need to have one std at the end.
That is what my second code block provides. Test it on a small sample of data to see for yourself.
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------