Announcement

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

  • Time Series Regression

    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

  • #2
    You can do this with:
    Code:
    capture program drop one_prediction
    program define one_prediction
        tsset fyear
        regress earnings L1.earnings in 2/-1
        gen w = _b[l1.earnings]
        predict predicted_earnings
        keep in L
       exit
    end
    
    
    rangerun one_prediction, interval(fyear -4 0) by(firm)
    -rangerun- is written by Robert Picard and is available from SSC. -rangerun-, in turn, requires -rangestat-, written by Robert Picard, Nick Cox, and Roberto Ferrer, also available from SSC.

    Comment


    • #3
      Hi Clyde,
      Thank you very much, it works perfectly. What should I do if I wanted to use rolling four-year windows, or five-year windows to calculate coefficient w? And what should I do if I wanted to calculate even coefficient "a" of that linear equation (earnings(t+1)=a+w*earnings(t))?
      Once again, thanks for the attention.

      Daniel

      Comment


      • #4
        If you wanted to use a four-year window, replace -interval(fyear -4 0)- with -interval(fyear -5 0)-. For a five-year window, with -interval(fyear -6 0)-.

        To get the constant term, add -gen a = _b[_cons]- to program one_predicition, just before or after the -gen w = ...- command.

        Comment


        • #5
          Hi Clyde,
          Many thanks for the advice, it worked perfectly. Is there any way to write a similar program so that the regression is pooled and not firm-specific? In other words, now I would like to estimate parameters a and w of the same equation (earnings(t+1)=a+w*earnings(t)), always using rolling three-year windows, but this time I would like those parameters to be the same for all the firms in the same year.
          For example, I would like to estimate one a and one w for all the firms in 2017, based on historical data from 2014, 2015 and 2016.
          Once again, thank you very much for your support.

          Comment

          Working...
          X