Hi all,

I have a 30-year unbalanced panel data, with firm and year.
I wish to do a 10-year rolling regression with a quadratic time trend.
I wrote something like following, and it works...but it took quite a while, I am wondering if rangestat could do faster?

Code:
 forvalues j = 1(1)4107{
 forvalues i = 1(1)30{
 gen t = 1 if n == `i'
 replace t = 2 if n == `i' + 1
 replace t = 3 if n == `i' + 2
 replace t = 4 if n == `i' + 3
 replace t = 5 if n == `i' + 4
 replace t = 6 if n == `i' + 5
 replace t = 7 if n == `i' + 6
 replace t = 8 if n == `i' + 7
 replace t = 9 if n == `i' + 8
 replace t = 10 if n == `i' + 9
 gen t2 = t^2
 cap reg x t t2 if id == `j' & n >= `i' & n <= `i' + 9
    if c(rc) == 0 {
       gen m1=e(rmse)
    }
    else if inlist(c(rc), 2000, 2001) {
        display "Insufficient results for i == `i': skipping to next value of i"
        continue
    }
    else {
        display "Unanticipated error in regression with i = `i'"
        exit `c(rc)'
    }
 }
}
Thank you in advance.