Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question on extrapolation

    Hello,

    I have a question on how to extrapolate the series both backward and forward in Stata. I am working with the following data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(year eq_dp ret_st)
    1968  3.200000151991844    .
    1969 3.9000000804662704    .
    1970  4.399999976158142    .
    1971 3.2999999821186066    .
    1972  3.200000151991844    .
    1973  4.800000041723251    .
    1974 11.699999868869781    .
    1975  5.499999970197678    .
    1976  6.400000303983688    .
    1977  5.299999937415123    .
    1978  5.799999833106995    .
    1979   6.89999982714653    .
    1980 6.1000000685453415    .
    1981  5.900000035762787    .
    1982  5.299999937415123    .
    1983  4.600000008940697    .
    1984  4.399999976158142    .
    1985   4.30000014603138    .
    1986  3.999999910593033    .
    1987   4.30000014603138    .
    1988  4.699999839067459    .
    1989 4.1999999433755875    .
    1990  5.499999970197678    .
    1991  5.000000074505806    .
    1992  4.399999976158142    .
    1993  3.400000184774399    .
    1994  3.999999910593033    .
    1995  3.799999877810478  2.9
    1996  3.700000047683716  2.9
    1997  3.200000151991844  2.6
    1999 2.0999999716877937 1.87
    2001 2.6000000536441803 1.99
    2002 3.5999998450279236 2.62
    2004  3.099999949336052 2.53
    2005 2.9999999329447746 2.47
    2006 2.8999999165534973 2.45
    2007 2.9999999329447746 2.49
    2008  4.500000178813934 3.63
    2009  3.200000151991844    .
    2010 2.8999999165534973    .
    2011  3.500000014901161    .
    2012 3.5999998450279236    .
    2013 3.2999999821186066    .
    2014  3.400000184774399    .
    2015  3.700000047683716    .
    2016                  .    .
    2017                  .    .
    2018                  .    .
    2019                  .    .
    end
    I have data on the return on stocks (ret_st) from 1995 up to 2008. However, I have no data on the return for the earlier/later period. What I am trying to do is use (const+ coeff * eq_dp) to extrapolate the rates but I do not know if this can be done using ipolate?

    Thank you in advance for your help.

  • #2
    ipolate, epolate extrapolates forwards and backwards using the first and last two known points.

    Run this script as a demonstration. If it's what you want, go for it.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(t given)
    1 .
    2 1
    3 2
    4 4
    5 7
    6 5
    7 .
    end
    
    ipolate given t, epolate gen(extrapolated)
    
    set scheme s1color 
    
    scatter given t, name(G1, replace) xla(1/7)
    
    twoway connected ex  t, ms(+) mc(blue) lc(blue) msize(large)  xla(1/7) || scatter given t, ms(Oh) msize(large) mc(orange) name(G2, replace) ytitle(given and extrapolated) legend(off)
    
    graph combine G1 G2 , col(1)

    Comment


    • #3
      If you are extrapolating based on a regression equation, then the values you want to extrapolate are simply out-of-sample predictions. See variable "wanted" below.

      Code:
      webuse grunfeld, clear
      keep if company<=5 & time<=5
      replace invest=. if time<=2
      *MODEL
      regress invest mvalue kstock i.company i.year
      predict investhat, xb
      *EXTRAPOLATED
      gen wanted= cond(missing(invest), investhat, invest)
      l, sepby(company)
      Res.:

      Code:
         +------------------------------------------------------------------------+
           | company   year   invest   mvalue   kstock   time   invest~t     wanted |
           |------------------------------------------------------------------------|
        1. |       1   1935        .   3078.5      2.8      1   491.0388   491.0388 |
        2. |       1   1936        .   4661.7     52.6      2   502.9965   502.9965 |
        3. |       1   1937    410.6   5387.1    156.9      3   404.0961      410.6 |
        4. |       1   1938    257.7   2792.2    209.2      4   250.6075      257.7 |
        5. |       1   1939    330.8   4313.2    203.4      5   344.3965      330.8 |
           |------------------------------------------------------------------------|
        6. |       2   1935        .   1362.4     53.8      1   479.9146   479.9146 |
        7. |       2   1936        .   1807.1     50.5      2   505.4195   505.4195 |
        8. |       2   1937    469.9   2676.3    118.1      3   460.4124      469.9 |
        9. |       2   1938    262.3   1801.9    260.2      4   274.2107      262.3 |
       10. |       2   1939    230.4   1957.3    312.7      5   227.9769      230.4 |
           |------------------------------------------------------------------------|
       11. |       3   1935        .   1170.6     97.8      1   35.28079   35.28079 |
       12. |       3   1936        .   2015.8    104.4      2   67.26659   67.26659 |
       13. |       3   1937     77.2   2803.3      118      3   87.52458       77.2 |
       14. |       3   1938     44.6   2039.7    156.2      4   39.72071       44.6 |
       15. |       3   1939     48.1   2256.2    172.6      5    42.6547       48.1 |
           |------------------------------------------------------------------------|
       16. |       4   1935        .    417.5     10.5      1   66.11318   66.11318 |
       17. |       4   1936        .    837.8     10.2      2   86.60765   86.60765 |
       18. |       4   1937    66.26    883.9     34.7      3   57.42879      66.26 |
       19. |       4   1938     51.6    437.9     51.8      4   51.85038       51.6 |
       20. |       4   1939    52.41    679.7     64.3      5   60.99083      52.41 |
           |------------------------------------------------------------------------|
       21. |       5   1935        .    157.7    183.2      1    154.691    154.691 |
       22. |       5   1936        .    167.9      204      2   128.5341   128.5341 |
       23. |       5   1937    74.24    192.9      236      3   88.73818      74.24 |
       24. |       5   1938    53.51    156.7    291.7      4   53.32075      53.51 |
       25. |       5   1939    42.65    191.4    323.1      5   28.34107      42.65 |
           +------------------------------------------------------------------------+

      Comment


      • #4
        Thank you very much both for your replies! Yes, I wanted to extrapolate based on regression equation so Andrew's code solves it, thanks again!

        Comment

        Working...
        X