Need Example of Iterative Regressions

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.

Need Example of Iterative Regressions

Postby Gregory » Mon Aug 25, 2008 2:51 pm

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
Gregory
 
Posts: 20
Joined: Mon Nov 13, 2006 9:05 am
Location: Montreal

Postby TomDoan » Tue Aug 26, 2008 5:52 pm

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.
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Postby Gregory » Tue Aug 26, 2008 7:53 pm

Thank you Tom,

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

Regards,

Gregory
Gregory
 
Posts: 20
Joined: Mon Nov 13, 2006 9:05 am
Location: Montreal


Return to Help With Programming

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

cron