Page 1 of 1

Simple forecasting model sets all series to the last series

Posted: Thu Oct 01, 2015 6:24 pm
by macro
I'm implementing a simple forecasting model where series are expected to grow at their average growth rate over the estimation period. (This could be done in a much simpler fashion than the way I did it below, but for the sake of learning the RATS language, I'm trying to understand why this code exhibits the behaviour it does).

This code

Code: Select all

calendar(q) 1947 1

compute begin_samp = 1969:1
compute end_samp = 2012:4
compute end_fcast = 2015:4

open data "data.csv"
data(format = cdf, org = columns) begin_samp end_samp $
    gdph cdh
close data

declare hash[frml] ids
smpl begin_samp end_samp
dofor s = gdph cdh
    compute growth = %l(s) + "_growth"
    compute mean_growth = %l(s) + "_mean_growth"

    set %s(growth) = s{0} / s{1}
    statistics(print) %s(growth)
    set %s(mean_growth) begin_samp end_fcast = %mean
    frml(identity) ids(%l(s)) s = s{1} * %s(mean_growth)
end dofor s

group mdl ids("gdph")>> gdph ids("cdh")>> cdh
forecast(model = mdl, from = end_samp+1, to = end_fcast, print)
sets GDPH and CDH to the average growth rate of the last series in the loop, in this case CDH:

Code: Select all

 ENTRY         GDPH             CDH         GDPH_GROWTH   GDPH_MEAN_GROWTH   CDH_GROWTH    CDH_MEAN_GROWTH
 2012:02  15500.200000000 1300.8000000000  1.002781875113  1.006964245134  1.005565862709  1.01296758509
 2012:03  15614.400000000 1311.2000000000  1.007367646869  1.006964245134  1.007995079951  1.01296758509
 2012:04  15761.500000000 1324.6000000000  1.009420791065  1.006964245134  1.010219646126  1.01296758509
 2013:01      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2013:02      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2013:03      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2013:04      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2014:01      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2014:02      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2014:03      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2014:04      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2015:01      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2015:02      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2015:03      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
 2015:04      1.012967585    1.0129675851       NA         1.006964245134       NA         1.01296758509
I think I've narrowed the problem down to this line

Code: Select all

frml(identity) ids(%l(s)) s = s{1} * %s(mean_growth)
but different variations on casting "s" and %s(mean_growth) don't solve the problem. It seems to be some mistake in the lag s{1}, because whatever value I multiply that by gets used for all the forecasting periods. If I use %s(mean_growth), it's the mean growth of the last series in the loop, but if I choose some arbitrary value like 1.0, then all the forecasted periods are set to 1.0 instead.


As I said, I'll just use this code in the project itself:

Code: Select all

calendar(q) 1947 1

compute begin_samp = 1969:1
compute end_samp = 2012:4
compute end_fcast = 2015:4

open data "data.csv"
data(format = cdf, org = columns) begin_samp end_samp $
    gdph cdh
close data

declare hash[frml] ids
smpl begin_samp end_samp
dofor s = gdph cdh
    compute growth = %l(s) + "_growth"
    compute mean_growth = %l(s) + "_mean_growth"
    set %s(growth) = s{0} / s{1}
    statistics(print) %s(growth)
    set s end_samp+1 end_fcast = s{1} * %mean
end dofor s
print end_samp-2 end_fcast 
since the use of the FORECAST instruction is overkill here, but I'd like to learn the cause behind this error.

Re: Simple forecasting model sets all series to the last ser

Posted: Thu Oct 01, 2015 6:55 pm
by TomDoan
See the part of

https://estima.com/ratshelp/index.html? ... ction.html

starting with "You have to be careful".