Hi Statalist,

I am a frequent reader of Statalist,

I am using Stata 15.1.
I am trying to replicate a paper on business cycle titled:
HTML Code:
 Macroeconomic Volatility and External Imbalances by Perri and Fogli (2014)
. I am struggling with how to implement the formulate in the picture to get the relative volatility of GDP growth.I tried to use the following code to calculate standard deviation using a window of 40 quarters:
So my questions are:
1. how do I implement the following formula in Stata
2. If I choose 40 quarters as my window, what does middle of a window mean (my understanding was the sd calculated using window=40 is placed halfway between these quarters) and I doubt this option is available in rangestat or asrol

I would really appreciate any hint.
Thank you in advance.
Array

Code:
rangestat (sd) sd_gdpg= gdpg, interval( time -40 0) by( ccode )
rangestat (sum) sumsdo_gdpg= sd_gdpg (count) counto_gdpg= sd_gdpg , interval(time -40 0) by(time) excludeself
gen meansdo_gdpg=sumsdo_gdpg/counto_gdpg
gen rel_volgdpg = sd_gdpg - meansdo_gdpg