Hi all,
I'm working on the following sample.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str6 firm double(fyear earnings)
"000001" 2010  339.84
"000001" 2011 268.608
"000001" 2012  89.147
"000001" 2013 -12.965
"000001" 2014  68.098
"000001" 2015 101.776
"000001" 2016   63.47
"000001" 2017  95.495
"000001" 2018  113.39
"000002" 2010  35.457
"000002" 2011 -37.225
"000002" 2012  14.026
"000002" 2013 -49.064
"000002" 2014 -50.071
"000002" 2015  13.386
"000002" 2016  56.673
"000002" 2017  93.248
"000002" 2018 136.921
end
I would like to estimate the following linear equation using a time-series approach:
earnings(t+1)=a+w*earnings(t)
In particular, I need to calculate this equation using rolling three-year windows for each firm and each year. For example, to forecast earnings for 2018, one would observe the earnings using data from 2017 and estimate the historical persistence of earnings (given by coefficient w) using data from 2014 to 2017.
How could I do that?
Thanks for the attention.

Daniel