06-03-2017 01:00 PM - edited 06-03-2017 01:00 PM
I'm trying to do rolling average returns for each "bemedeciles" (Or groups), from Aprile (t) to Aprile (t+1), Aprile (t+1) to (Aprile t+2) and so on.
The thing that I'm struggling is how to do it. I've search the entire internet, but not found a quite "understandable" methods to do it.
The part where it stops is how to get the rolling average returns in those intervals, based on "Names date", and "bemedecile".
Can someone please help me? I'm on ground zero, no progress on it for 1 day now.
06-03-2017 01:42 PM
It would help if you could provide have and want datasets in the form of datasteps. From your description it looks like you are only attempting to get averages of each adjacent pair of values, within each group, in your datastep
Art, CEO, AnalystFinder.com
06-03-2017 01:56 PM
I agree that there's a lot out there. Here's a post from Rick that lists many of the options:
I think you want the second example here - with BY groups:
In general, we can't really help off a picture, for starters we'd have to type it out if we want to work with your data, which many will not do. So a 'generic' question will get 'generic' answers.
06-03-2017 10:41 PM
Here is an example.(if you do not have a big table)
Length of rolling windows is a month forward.
data air; set sashelp.air; if mod(_n_,100)=1 then group+1; run; proc sql; create table want as select *,(select mean(air) from air where group=a.group and date between a.date and intnx('month',a.date,1,'s')) as rolling_mean from air as a; quit;
06-04-2017 08:14 AM
You have CRSP monthly data, sorted by PERMNO/DATE, where DATE is the last trading date of the month. You want rolling 12 months average returns (monthly average, or yearly?) (arithmetic average or geometric mean?). Below is geometric mean monthly return for rolling 12-month window.
do seq=1 by 1 until(last.permno);
if seq<=11 then continue;
Note that this program assumes there are no "holes" in the monthly series for any permno.