Announcement

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

  • "Gap count includes panel changes" - Not able to use -rollreg- (user written command)

    Hello everyone,

    I'm currently trying to perform a rolling regression in order to estimate coefficients which I want to use to predict company earnings. One way is to use -rollreg- (user written command).

    My problem is, that -rollreg- does not accept any gaps in the data. As far as I understand, my data does not have any gaps - at leat when it comes to the panel variable "id" and time variable "Year".
    But since changes in the panel are counted as gaps, -rollreg- does not work. Is there a way to work around this?

    The expample contains a small portion of my data - the real set has many more variables and observations.

    Earnings_w is my dependent variable
    L1.DD L1.NegE L1.Earnings_w L1.Dividends_w L1.Accruals_w L1.TotalAssets_w are my independent variables.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex 
     clear input int Year float(FFF DD NegE id Earnings_w Dividends_w Accruals_w TotalAssets_w) 2000 . 1 0  1  145000  44140.06    31000  1573000 2001 . 1 0  1  123000  45293.79   -57000  1707000 2002 . 1 0  1  125000   47430.6  -128000  1609000 2003 . 1 0  1  154000   54828.8   -97000  1689000 2004 . 1 0  1  171000  56614.95   -57000  1711000 2005 . 1 0  1  179000   77348.5   -21000  2111000 2006 . 1 0  1  259524     83804   -49206  2251528 2007 1 1 0  1  223976     84408    88431  2363250 2008 1 1 1  1  -23818     35366   -41511  1946498 2009 1 1 0  1   64524     35366   -67391  1661938 2010 1 1 0  1  115907   44207.5   256813  1777113 2011 1 1 0  1   55807   43832.5   -27904  1822692 2012 1 1 0  1   78252  43478.75   -42612  1740368 2013 1 1 0  1   80453   43482.5   -84965  1531712 2014 1 1 0  1   94668   46961.1   -20448  1823535 2015 1 1 0  1  141439     52179   -48960  1921206 2003 . 0 0  2   26184         .   -51569  3219480 2004 . 0 0  2   33670         .   -70428  3561096 2005 . 0 0  2   49938         .  -217817  5040470 2006 . 0 0  2  191351         .  -255000  5482955 2007 . 1 0  2  170229     62700  -323760  7647286 2008 . 1 0  2  157020     62700  -532865  9626986 2009 . 1 0  2  161457     57000  -953640  9479606 2010 . 1 0  2  174857     62700  -515560 10167808 2011 . 1 0  2  194995     63135  -306151 10212330 2012 . 1 0  2   60631   20617.6  -208170  9940072 2013 . 1 0  2  113558     46170  -577162 10343502 2014 . 1 0  2  127969     51300  -686644  9997414 2015 . 1 0  2  156286     66690 -1096362 10436940 2008 . 0 0  3   33274         .   -38700  1101928 2009 . 0 0  3   31192         .   -88094   816687 2010 . 0 0  3   47181         .   -28232   808211 2011 . 1 0  3   86020     52896   -18486   850104 2012 0 1 0  3   71312   21158.4   -46111   854304 2013 0 1 0  3   56028   21158.4   -66206   906199 2014 0 1 0  3   59212   42316.8   -35939  1052512 2015 0 1 0  3   42697   42316.8   -67181  1075303 2002 . 0 0  4    9180         .   -31458   130478 2003 . 0 0  4    6449         .   -31378   272825 2004 . 0 0  4   25049         .   -48174   799876 2005 . 0 0  4   33405         .    52249   972413 2006 . 1 0  4   77186     19800   -61921  1512604 2007 . 0 0  4   40376         0    52668  2845265 2008 . 0 1  4  -33881         .  -133559  2697420 2009 . 0 0  4   54193         0   111919  2550053 2010 . 0 1  4 -270478         0  -436766   900347 2012 . 0 0  4  303551         0        .    55518 2006 . 0 0  5    7449         .    -6872    97212 2007 . 1 0  5    8426      4870     4695   132432 2008 . 1 0  5   11031      5357     1241   135013 2009 . 0 0  5    4597         0    -9990   138868 2010 . 0 1  5  -17257         0   -24016   154887 2011 . 0 1  5  -12377         0   -23183   142687 2012 . 0 1  5   -2491         0    -2698   130689 2013 . 0 1  5  -28297         0     4052   131698 2014 . 0 1  5  -27024         0   -19530    95071 2015 . 0 1  5  -13397         0    -5026    88274 2010 . 0 0  6   27868         .   -24196   253603 2011 . 0 0  6   28144         .    13993   283872 2012 . 0 0  6   10630         .    -3847   330385 2013 . 0 0  6   21145         .     1729   429410 2014 . 0 0  6   28894         0     -786   547185 2015 . 0 1  6   -9594         0    -6672   718245 2010 . 0 0  7    6617         0    -3534    48338 2011 . 0 0  7    5273         0    -4109    55964 2012 . 1 0  7    5124   2496.55     4482    55453 2013 . 1 0  7    3647   2496.55    -4175    52639 2014 . 1 0  7    3484   2496.55       23    52003 2015 . 1 0  7    4156    3108.6       71    52970 2000 . 1 0  8   73100     43890   -27832   718445 2001 . 1 0  8   66267     39900   -32026   733097 2002 . 1 0  8   70291     42000   -50634   762538 2003 . 1 0  8   70842     42000   -79527   823709 2004 . 1 0  8   71688     42000  -122665   942954 2005 . 1 0  8   74304     42000   -83712  1181687 2006 . 1 0  8   76785     46200   -64777  1479892 2007 . 1 0  8   87678     52500   -76735  1559660 2008 . 1 0  8   91149     54600   -57247  1735284 2009 . 1 0  8   73361     44100   -82113  1860932 2010 . 1 0  8   75718     42000   -94025  1998496 2011 . 1 0  8   31602     21000  -147311  2150158 2012 . 1 0  8   71890     22008  -107781  2061803 2013 . 1 0  8   73291     27300  -131063  1953937 2014 . 1 0  8   82482     34608  -138109  1892223 2015 . 1 0  8  100434     42000  -127979  1909656 2004 . 0 1  9   -8631         0    -7035    18773 2005 . 0 1  9  -28612         0    -4565    75004 2006 . 0 1  9  -57292         0    -9533   107981 2007 . 0 1  9  -24070         0    -3228   143510 2008 . 0 1  9  -61600         0   -20294   111697 2004 . 0 1 10   -4082         .    -8714   137814 2005 . 0 0 10    2902         0    -7916   136419 2006 . 0 0 10    3298         0     8069   160097 2007 . 0 0 10    2309         0    17860   224168 2008 . 0 1 10  -27558         0   -29127   229999 2009 . 0 1 10  -36698         0   -31435   127016 2000 . 1 0 11   22544 12025.374   -18069   857314 2001 . 1 0 11   37574  12014.04   -48432   845426 2002 . 1 0 11   44325 19845.834   -16742   855988 2003 . 1 0 11   65382 19845.834   -26614   897086 end
    thank you!
    Last edited by Markus Dietz; 11 Sep 2017, 08:06.

  • #2
    There is the official command -rolling-. If your data set is very large, you need something faster than that, and -rangestat- can handle this. -rangestat- is by Robert Picard, Nick Cox, and Roberto Ferrer. It is available from SSC. The help file for -rangestat- includes a rolling regression example.

    Comment


    • #3
      Note that the data posted above was copied and pasted from an earlier post at https://www.statalist.org/forums/for...ecast-earnings where it appears in a much more presentable fashion.

      It is unfortunate that the Forum software does not seem to support copying from a code block and pasting into a code block in a new post - as in this case, the line breaks present in the original are lost in the copy.

      Comment


      • #4
        Amplifying on William Lisowski's observation, when trying to copy from a code block into another code block, you can work around this problem by "laundering" the copied material through a text editor (the Stata do-editor will serve). Paste into the text editor, then re-copy from there and paste into the new code block. It's a nuisance, and I wish they would fix this problem. But it does get around the problem.

        Comment


        • #5
          Hello,

          correct, I copied the data from an older topic of mine and - as you can see - I'm still working on the project.
          I'm aware of -rangestat- and I much appreciate it since it is incredible fast. I already tried it and will probably keep on using it.

          I asked about the gaps because the adviser on my thesis told me that -rollreg- was used before to deal with a problem similar to mine. I'm fairly new to panel analysis and Stata and I just wanted to know if there is a way to make -rollreg- or even Stata in general "ignore" changes in panels e.g. the gaps.
          Plus it would be perfect for me if the regressions coming out of -rollreg- and -rangestat- yield the same results (again, this is my first project in this field)

          thanks Clyde Schechter for the tip on how to paste code
          Last edited by Markus Dietz; 11 Sep 2017, 09:16.

          Comment


          • #6
            It seems like the only gaps are due to panel changes - does someone knows a way around this?


            . tsset id Year
            panel variable: id (strongly balanced)
            time variable: Year, 1995 to 2015
            delta: 1 year


            . tsreport

            Panel variable: id
            Time variable: Year
            ------------------------
            Starting period = 1995
            Ending period = 2015
            Observations = 200865
            Number of gaps = 9564
            (Gap count includes panel changes)


            . tsreport, panel detail

            Panel variable: id
            Time variable: Year
            ------------------------
            Starting period = 1995
            Ending period = 2015
            Observations = 200865
            Number of gaps = 0

            Comment


            • #7
              I'm not sure why post #1 asserts that rollreg does not accept any gaps in the data.

              I'm not a user of rollreg, or of time series analysis in general. However, in an attempt to understand this problem, I installed rollreg (and the prerequisite ivreg2) from SSC and ran the following example from the output of help rollreg with some additional commands to explore the data and the results.
              Code:
              . webuse invest2, clear
              
              . tsset
                     panel variable:  company (strongly balanced)
                      time variable:  time, 1 to 20
                              delta:  1 unit
              
              . tsreport
              
              Panel variable:   company
              Time variable:    time
              ---------------------------
              Starting period =         1
              Ending period   =        20
              Observations    =       100
              Number of gaps  =         4
              (Gap count includes panel changes)
              
              . tsreport, panel detail
              
              Panel variable:   company
              Time variable:    time
              ---------------------------
              Starting period =         1
              Ending period   =        20
              Observations    =       100
              Number of gaps  =         0
              
              . rollreg market L(0/1).invest time, move(8) stub(mktM)
              
              . ds mktM*
              mktM_invest   mktM_L_inv~t  mktM_time     mktM_cons     mktM_r2       mktM_N
              mktM_se_in~t  mktM_se_L_~t  mktM_se_time  mktM_se_cons  mktM_RMSE
              
              .
              I note that the output of tsreport appears similar to that shown in post #6 - gaps are reported for the unqualified command, but not for the command with the panel option.

              So, I think I need to point to the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page used to create new posts. Note especially sections 9-12 on how to best pose a question.

              Section 12.1 is particularly pertinent

              12.1 What to say about your commands and your problem

              Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
              ...
              Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.
              The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

              Comment


              • #8
                On further reflection, it seems to me that
                Code:
                tsreport, panel detail
                only confirms that there are no gaps in the times within each panel's worth of data. But when running rollreg Stata will omit any observation with missing values on one of the variables included in the model, and in doing so will create a gap. It seems to me you need to instead run
                Code:
                tsreport Earnings_w L1.DD L1.NegE L1.Earnings_w L1.Dividends_w L1.Accruals_w L1.TotalAssets_w, ///
                   panel detail casewise
                to confirm that missing values in your data are not causing your problem.

                Comment

                Working...
                X