BookmarkSubscribeRSS Feed
gibsonrobb
Calcite | Level 5

I have a data set. I am trying to get the standard deviation for the last ten years for each of my observations. For example, I have data from 1992-2009. So I gathered data from 10 years prior to 1992 to have sufficient data. How do I calculate the STD for each year starting with 1992-2009, by taking the 10 years prior of data? For example, for 1992, I need to see the data from 1983-1992, including data from 1983 and 1992. For 1993, I use data from 1984-1993, and so on. I am trying to do this for each firm, or GVKEY from Compustat. All help appreciated. 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

This is called a "moving standard deviaton". PROC EXPAND will calculate it for you. See this example (where you need to use MOVSTD in place of MOVAVE) https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=etsug&docsetTarget=etsug_...

--
Paige Miller
gibsonrobb
Calcite | Level 5

Thank you, I will take a look and let you know how it goes.