Announcement

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

  • Rolling Window Regressions

    Hi everyone,

    I would like to get some answers to the doubts I have with regard to the rolling command. First of all, I will explain what I want to get with the rolling window regressions. I have 9,630 columns (each of one representing a dependent variable) plus 4 columns (each representing an independent variable). Moreover, each column is divided into different rows, each row representing one month from January 2000 to December 2013.

    I want to estimate a series of coefficients by using a rolling window regression with window equal to three years or 36 months, and by regressing each dependent variable on the four independent variables mentioned. My question is if I have to carry out 9,630 rolling window regressions (as I have 9,630 dependent variables) or is there a much shorter way of doing this. Moreover, I would like to know how can I store the estimated coefficients on a file. If you are able to give me an intuition of the command I would have to enter that would be also welcomed. Thank you in advance.

  • #2
    You can use the Stata program rolling, with save option
    something like this
    Code:
    foreach var of varlist V* {
    rolling _b, window(36): regress `var' X1 X2 X3, saving(`var')
    }
    I am assuming that you have named all depedent varaibles starting with capital letter V
    Regards
    --------------------------------------------------
    Attaullah Shah, PhD.
    Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
    FinTechProfessor.com
    https://asdocx.com
    Check out my asdoc program, which sends outputs to MS Word.
    For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

    Comment


    • #3
      Thanks for your quick reply Dr. Shah. I have further questions I would like to get answered if you don´t mind. Does the expression `var' after the regress program represent the dependent variable? Moreover, as I have 4 independent variables shouldn´t be X1 X2 X3 X4?

      How can I rename all dependent variables so they start with capital letter V? Would the following command be correct?

      foreach x of varlist _all { rename `x' V_`x' }




      Thank you a lot.

      Comment


      • #4
        I think it might be easier to give good advice if you tell us what data structure you envisage for the 9630 sets of regression results. Attaullah's strategy would give you 9630 new datasets. What would do with them?

        Comment


        • #5
          As I wrote, I have 9,630 columns (dependent variables) plus 4 other columns (independent variables). Each column displays time series data ( i.e. each row represents successive months). I want to run rolling window regressions with a window of 36 months to estimate coefficients. I would need to run these rolling window regressions for each of the 9,630 dependent variables. To do so, I need to regress the first column (dependent variable) on the 4 (columns) independent variables, the second column on the same 4 (columns) independent variables, the third, the fourth, an so on till the 9,630th column.

          Thanks

          Comment


          • #6
            Just a side note: in order to read in a data set with 9,634 variables ("columns"), you need Stata SE or MP. If you have smaller flavor of Stata you will either need to upgrade or you will have to repeatedly read only the relevant parts of the data set in a loop.

            Regarding #3, that will rename all variables in your data set with a prefix V_, not just the dependent variables. And, actually, you don't need a loop to do this. So I think what you want is more like this:

            Code:
            ds X1 X2 X3 X4, not
            rename (`r(varlist)') V_=
            Finally, I'll just reiterate with Nick said earlier. Attaullah's code is going to generate 9,634 output files, each containing the results of the rolling regressions on a single dependent variable. That is a very unwieldy set up and it will be difficult to work with these results. If you say what you plan to do with the results once you have them, somebody might be able to suggest a better way to organize the results so you can accomplish your ultimate goals.
            Last edited by Clyde Schechter; 01 May 2016, 13:03.

            Comment


            • #7
              I don't think #5 answers the main question of #4 at all. As Clyde also asks, what do you want to do with the results?

              Comment


              • #8
                Hi!

                Sorry for not answering before. It is difficult to explain in words what I want to do, although I will try it.

                I am currently running the rolling window regressions based on answer #2, which yield 9,630 files, each file containing the coefficients of each of the four independent variables. Plus, as you will already know, each file contains the start and end dates of the rolling window regressions.

                Now, I want to multiply each of the 4 estimated coefficients by the corresponding 4 independent variables of the database file and sum each of these 4 products, where the independent variables are observed at the month following the "end date" (i.e. end date + 1 month). Finally, I want to subtract the sum of the 4 products to the formerly dependent variables' values observed at each date. I want to perform these calculations for each of the 9,630 files that I am currently producing. I hope you understood what I want to do. Thank you in advance.

                Comment


                • #9
                  Hi everyone,

                  I was confused when I wrote #8, but now I know what I need to do with the results. I need to save in a unique file the intercepts of the 9,630 files generated. How can I do it? Thank you in advance.

                  Comment


                  • #10
                    Sofia Frascalo What is #10 a reply to?

                    Comment

                    Working...
                    X