Announcement

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

  • Running regressions by decade when observations are by year

    Hi All,

    I currently have data that looks like the following:


    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(y x year)
    23 2143 1980
    23 431 1980
    3 34 1980
    23 134 1980
    123 13 1981
    12 4 1981
    213 314 1981
    123 31 1982
    123 31 1982
    12 4 1982
    123 4 1982
    123 4 1983
    end
    [/CODE]
    Here, there is information on regressand y, and regressor x, by year. I wish to conduct regressions by decade. I have a panel of observations starting from 1850 onwards, so I want to conduct the regressions for 1850-1860, 1860-1870 and so on. The ultimate aim is to obtain predicted values for y, but based on coefficients that have been estimated by decade. The code I used in the past was to do this by year:

    Code:
    gen fitted=.
    levelsof year, local(levels)
    foreach i of local levels{
    regress y x
    predict temp
    replace fitted=temp if year==`i'
    drop temp
    }
    This however, estimates coefficients by year, which I need done by decade. One option is to group different decades by using the egen command with the group function, but I am at a loss at how to group by decade. Any suggestions are most welcome.

  • #2
    Perhaps you wish to take a look at rolling window regression. Just type - help rolling - to check it out. This won't make it decade by decade, but each 10-yr period. Otherwise, creating groups by decade - and using it as predictors, instead of years - will do fine.
    Best regards,

    Marcos

    Comment


    • #3
      Thank you Marcos. I think I will first generate a decade variable:

      Code:
      gen decade = 10 * floor(year/10)
      and thereafter, estimate using OLS by groups. Thanks!

      Comment


      • #4
        1850-1860 looks like 11 years to me, not a decade, and similarly for the other examples.

        But consider some variant -- using rangestat (SSC) -- on

        Code:
        gen decade = 10 * floor(year / 10) 
        rangestat (reg) y x, int(decade 0 0) 
        On the whole, rolling regressions make more sense to me.

        Code:
         
        rangestat (reg) y x, int(year -9 0) 
        For other examples of rangestat, look at its help file or search archives here.

        An overview of rounding and binning will appear in Stata Journal 18(3).

        Comment

        Working...
        X