General Framework for Multiple Breaks
Posted: Mon Feb 15, 2010 1:44 pm
The following is a general programming framework (part of a procedure) for searching for optimal multiple breaks. This will handle any number of breaks from 1 up. The following are input to this:
pi = smallest (fractional) gap between breaks
lower = lowest possible entry
upper = highest possible entry
breaks= number of breaks
As an example, see the lsunit procedure.
At this point, the best value will be in mint and the list of optimal breaks is in bestbreaks
pi = smallest (fractional) gap between breaks
lower = lowest possible entry
upper = highest possible entry
breaks= number of breaks
As an example, see the lsunit procedure.
Code: Select all
local vect[int] bps upperbound bestbreaks
local integer pinobs
local integer i
*
* shortest interval between the breaks or between the ends and the breaks
*
compute pinobs=fix(pi*(upper-lower+1))
*
* These keep track of the break point information.
*
dim bps(breaks) upperbound(breaks) bestbreaks(breaks)
*
* Set up the starting break points (the leftmost legal values), and the upper
* bounds (rightmost legal values).
*
do i=1,breaks
compute bps(i)=(lower-1)+pinobs*i
compute upperbound(i)=endl+1-pinobs*(breaks+1-i)
end do i
*
* The minimum t value is initialized as an NA, so we know to keep the first value
* we see.
*
compute mint=%na
*
compute done=0
while .not.done {
>>>>
Do calculation here with breakpoints at bps(1),...,bps(breaks).
This assumes that we're looking for the smallest t-statistic, and the code is producing
a value for the t-statistic with these settings as tstat. If you're looking to maximize
something, rename variables as needed and change the < comparison to > in the IF below.
<<<<
*
* If this is the smallest t-stat we've seen so far, save the number of
* lags, the break point array and the sweep array.
*
if .not.%valid(mint).or.tstat<mint
compute mint=tstat,bestbreaks=bps
*
* Update the break points. Add one to the final slot, until we hit
* its upper bound. When we hit that, add one to the second to last
* slot, and reset the final slot to its smallest possible value. When
* the second to last slot is exhausted, add one to the one earlier,
* etc. If <<done>> is zero at the end, we still have a valid
* combination that we haven't checked.
*
compute done=1
do i=breaks,1,-1
compute bps(i)=bps(i)+1
if bps(i)>=upperbound(i)
next
do j=i+1,breaks
compute bps(j)=bps(j-1)+pinobs
end do j
compute done=0
break
end do i
}