Dear All, I wonder if the following question can be solved by (ssc install) rangestat/runby? The data set is:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long stkcd int year double sale
2 2008 40991779215
2 2009 48881013143
2 2010 50713851443
2 2011 71782749801
2 2012 1.03116e+11
2 2013 1.35419e+11
2 2014 1.46388e+11
2 2015 1.95549e+11
2 2016 2.40477e+11
2 2017 2.42897e+11
4 2008 43314824.87
4 2009 60080600.35
4 2010 131331494.7
4 2011 74503718.53
4 2012 97363301.61
4 2013 72784567.16
4 2014    80608820
4 2015 120454422.5
4 2016 287670026.6
4 2017   138605842
5 2008 108720264.8
5 2009 43192476.48
5 2010 137234232.9
5 2011 63534839.01
5 2012 99421227.75
5 2013 52061702.69
5 2014 52776994.29
5 2015 84125970.69
5 2016 481863433.3
5 2017 530922230
For each `stkcd', I'd like to perform a rolling regression using the recent 5-year data (including the current year) by regressing sale on a constant and trend term (1,2,3,4,5). Then, collect five residuals and calculate its standard deviation. Any suggestions? Thanks.