Announcement

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

  • Sub periods in regression

    Hi,

    I was wondering if anybody knows how I can adjust this code to run regressions for a 10-year periods?

    Code:
    gen r2small =.
    forvalues i = 1962(10)1972 {
    display "`i'"
    reg prc atpr capxpr ceqpr cogspr dvcpr intanpr ibpr revtpr spipr xadpr xrdpr xsgapr  if  pyear==`i' & size==0
    replace r2small = e(r2_a) if pyear == `i'
    }
    Thank you

  • #2
    What do you mean by "run regressions for a 10-year periods"? I can think of several very different ways to interpret this.

    Comment


    • #3
      More precisely, I want regressions for the following periods:

      1962-1971
      1972-1981
      1982-1991
      1992-2001
      2002-2011
      2012-2017

      The last one includes only 6 years.



      Thank you

      Comment


      • #4
        Code:
        //    CREATE TOY DATA SET TO DEMONSTRATE CODE
        clear*
        set obs `=2017-1962+1'
        gen year = 1961 + _n
        
        //    CODE THAT CREATES A PERIOD VARIABLE
        gen period = floor((year-1962)/10) + 1
        tabstat year, by(period) statistics(min max)
        Then, in your real data (but not in this toy data set) you can run:
        Code:
        forvalues i = 1/6 {
            reg prc atpr /*etc.*/ if period == `i' & size == 0
            replace r2small = e(r2_a) if period == `i'
        }

        Comment


        • #5
          Thank You!

          It works perfectly.

          Comment

          Working...
          X