Page 1 of 1

Need Example of Iterative Regressions

Posted: Mon Aug 25, 2008 2:51 pm
by Gregory
I'd like to do an iterative regression like the one shown below, and I'm hoping that someone can point me to an example. The basic idea is to feed fitted values from a second regression into the first until the coefficients or perhaps the R-squared of the first converge.

Any suggestions would be most appreciated.

Here's a rough idea of what I want to do.

Code: Select all

do i=1,50

(1) regress y on x and zHat and error term u

* zHat will not be included in regression (1) the first time it is run.

* Save the coefficients.
set theCoeffs = %beta

* Now run regression (2) which depends on lagged residuals from (1)

(2) regress z on g and uHat{1} and error term e

* Save the fitted values of (2) which will be used in (1) on the next pass
set zHat = fitted values of z from (2)

* Include some criterion for exiting the loop if the coefficients stop changing

end do i

Posted: Tue Aug 26, 2008 5:52 pm
by TomDoan
1. To deal with omitted zhat the first time through, just make zhat all zeros prior to the loop. The LINREG will, in effect, drop it out of the regression automatically. (It will show up, but with zero coefficient and zero standard errors).

2. The %testdiff function is useful for comparing coefficient vectors. Just don't use it when the iteration count is 1, since you don't have a base to compare against. Test to see if %testdiff(betalast,%beta) is small enough (say <.00001); if it is, use BREAK to exit the loop. If not, do compute betalast=%beta, so you have the comparison vector for the next time through.

3. You need to be careful about the ranges over which things are computed. Because regression (2) depends upon uhat{1}, and then it's used to compute zhat, it looks as if you're going to be losing an extra data point each iteration. You may need to set presample uhat to zero, so that doesn't happen.

Posted: Tue Aug 26, 2008 7:53 pm
by Gregory
Thank you Tom,

Good stuff, particularly %testdiff and BREAK in (2) and the heads-up in (3).

Regards,

Gregory