Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Programming, rollreg, gaps, and memory

From   "Michael Blasnik" <>
To   <>
Subject   st: Re: Programming, rollreg, gaps, and memory
Date   Sat, 16 Apr 2005 08:17:20 -0400

I think you may need to add:

drop `res'

at the end of your loop. Otherwise, the repeated calls to -tempvar res- each time through the loop will create an additional new variable. Given the nature of rolling regressions, that becomes about 1 variable per observation in the dataset and could easily lead to exceeding the limit on # variables. By the way, if you don't know what an error code means, you can always just type error ###. In the case of error 902, it says "no room to add more variables due to width".

Michael Blasnik

Cameron Hooper wrote:


forvalues i = `min'/`=`max' - `move' + 1' {
  local j = `i' + `move' - 1

  if `j' <= `total' {

        capture regress `depvar' `reglist' in `i'/`j'
        replace rc = _rc in `j'

        if _rc == 0 & e(N) == `move' {

          tempvar res
          predict `res' if e(sample), res
          summarize `res'
          replace `stub'_sd_residual = `res' in `j'
          replace `stub'_r2 = e(r2_a) in `j'
          replace `stub'_RMSE = e(rmse) in `j'
          replace `stub'_N = e(N) in `j'
          replace `stub'_cons = _b[_cons] in `j'
          replace `stub'_se_cons = _se[_cons] in `j'

          forvalues l = 2/`k' {

            local v: word `l' of `varlist'
            replace `stub'_`v' = _b[`v'] in `j'
            replace `stub'_se_`v' = _se[`v'] in `j'


    local min = `max' + 1

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index