*******************************************************
*  Test of UNIT ROOT with ENDOGENOUS TIME BREAK
*     Implements several tests discussed in PERRON ("Further evidence on breaking
*     trend functions in macroeconomic variables, Journal of Econometrics 80,1997)
*     when the date of possible change in the intercept or the slope is not fixed
*     a priori
*
*  Syntax:
*  @PERRON97  series   start   end
*
*  Options
*     TRANS=[NONE]/LOG
*        Transformation to apply to data
*      MODEL=IO1/[IO2]/AO
*        Choice of the model for the unit root :
*		IO1 : innovational outlier with a change in the intercept
*		IO2 : innovational oulier with a change in the intercept and in the slope
*		AO  : additive outlier with a change in the slope only but
*		      both segments of the trend function are joined at the time break
*
*     LAGMAX=maximum lag to be considered for CRITERION [12]
*     SIGNIF=significance level used REDUCTION [.10]
*     METHOD=[UR]/STUDABS/STUD
*	Choice of the methods to choose the optimal break date TB
*		UR : Min the t-statistic for testing alpha=1
*	   STUDABS : Max of the absolute value of the t-statistic
*		       on the parameter associated with the change in either
*	               the intercept (if IO1) or the slope (if IO2)
*	      STUD : Min of the t-statistic on the parameter associated
*	               with the change in either the intercept (if IO1) or the slope (if IO2)
*     TRIM=the value of the arbitrary trimming near the end points [0.15]
*
*
*
* Proc written by g. colletaz and f. Serranito (laboratoire d'economie d'orleans)
*      gilbert.colletaz@univ-orleans.fr
*      francisco.serranito@univ-orleans.fr
*      11/1998
*

PROC PERRON97 SERIES START END
TYPE SERIES SERIES
TYPE INTEGER START END

*

OPTION CHOICE  TRANS  1  NONE  LOG
OPTION CHOICE  MODEL  2  IO1 IO2 AO
OPTION CHOICE  METHOD 1  UR STUDABS STUD
OPTION INTEGER LAGMAX 12
OPTION REAL    TRIM   0.15
OPTION REAL    SIGNIF .10

LOCAL INTEGER NBEG NEND NOBS BEGIN FINISH BREAK LAG TB LAGOPT
LOCAL REAL TST TSTMIN TSTMAX ALPHA TALPHA
LOCAL SERIES  TRANSFRM  DU DT DUMMY SERTRA TIME RES DRES
LOCAL RECTANGULAR[REAL] IO1UR IO1STUD IO1STUDA IO2UR IO2STUD IO2STUDA AOUR AOSTUD AOSTUDA

LOCAL STRING SS

DIMENSION IO1UR(4,8) IO1STUD(4,8) IO1STUDA(4,8) IO2UR(3,8) IO2STUD(3,8) IO2STUDA(3,8) $
          AOUR(4,8) AOSTUD(4,8) AOSTUDA(4,8)
* critical values at 1%, 5%, 10%, 50%, 90%, 95%, 99% (table 1 p. 362)

compute IO1UR    = ||  60 , -5.92 , -5.23 , -4.92 , -3.91 , -3.00 , -2.74 , -2.25 $
                    |  80 , -5.77 , -5.09 , -4.84 , -3.88 , -2.95 , -2.73 , -2.22 $
                    | 100 , -5.70 , -5.10 , -4.82 , -3.87 , -3.05 , -2.75 , -2.22 $
                    |1000 , -5.41 , -4.80 , -4.58 , -3.75 , -2.99 , -2.77 , -2.32 $
                    ||
compute IO1STUD  = ||  60 , -5.70 , -4.92 , -4.53 , -3.32 , -1.79 , -1.14 ,  0.42 $
                    |  80 , -5.59 , -4.83 , -4.54 , -3.33 , -1.92 , -1.19 ,  0.34 $
                    | 100 , -5.43 , -4.83 , -4.50 , -3.34 , -2.02 , -1.38 , -0.05 $
                    |1000 , -5.15 , -4.64 , -4.37 , -3.39 , -2.27 , -1.85 , -0.70 $
                    ||
compute IO1STUDA = ||  60 , -5.85 , -5.18 , -4.83 , -3.70 , -2.14 , -1.34 ,  0.05 $
                    |  80 , -5.66 , -5.04 , -4.78 , -3.72 , -2.28 , -1.67 , -0.06 $
                    | 100 , -5.68 , -5.05 , -4.77 , -3.71 , -2.40 , -1.88 , -0.34 $
                    |1000 , -5.34 , -4.84 , -4.59 , -3.74 , -2.71 , -2.35 , -1.54 $
                    ||
compute IO2UR    = ||  70 , -6.32 , -5.59 , -5.29 , -4.24 , -3.32 , -3.08 , -2.67 $
                    | 100 , -6.21 , -5.55 , -5.25 , -4.22 , -3.35 , -3.13 , -2.63 $
                    |1000 , -5.57 , -5.08 , -4.82 , -3.98 , -3.25 , -3.06 , -2.72 $
                    ||
compute IO2STUD  = ||  70 , -5.77 , -4.98 , -4.55 , -3.04 , -1.53 , -1.10 , -0.27 $
                    | 100 , -5.56 , -4.91 , -4.47 , -2.99 , -1.55 , -1.19 , -0.38 $
                    |1000 , -5.28 , -4.62 , -4.28 , -2.94 , -1.64 , -1.33 , -0.59 $
                    ||
compute IO2STUDA = ||  70 , -6.07 , -5.33 , -4.94 , -3.72 , -2.28 , -1.89 , -0.85 $
                    | 100 , -5.86 , -5.19 , -4.88 , -3.60 , -2.23 , -1.87 , -0.95 $
                    |1000 , -5.57 , -4.91 , -4.59 , -3.47 , -2.15 , -1.86 , -1.30 $
                    ||
compute  AOUR    = || 100 , -5.45 , -4.83 , -4.48 , -3.44 , -2.60 , -2.39 , -2.06 $
                    | 150 , -5.28 , -4.65 , -4.38 , -3.33 , -2.50 , -2.30 , -1.93 $
                    | 200 , -5.28 , -4.65 , -4.38 , -3.32 , -2.48 , -2.27 , -1.90 $
                    |1000 , -4.91 , -4.36 , -4.07 , -3.13 , -2.32 , -2.12 , -1.78 $
                    ||
compute  AOSTUD  = || 100 , -5.26 , -4.44 , -4.07 , -2.83 , -1.76 , -1.45 , -0.83 $
                    | 150 , -5.00 , -4.36 , -3.99 , -2.78 , -1.72 , -1.40 , -0.49 $
                    | 200 , -4.77 , -4.22 , -3.83 , -2.72 , -1.57 , -1.24 , -0.56 $
                    |1000 , -4.67 , -4.08 , -3.77 , -2.65 , -1.57 , -1.22 , -0.49 $
                    ||
compute  AOSTUDA = || 100 , -5.38 , -4.67 , -4.36 , -3.24 , -2.28 , -2.04 , -1.46 $
                    | 150 , -5.23 , -4.57 , -4.28 , -3.18 , -2.19 , -1.92 , -1.30 $
                    | 200 , -5.02 , -4.41 , -4.17 , -3.11 , -2.15 , -1.91 , -1.26 $
                    |1000 , -4.87 , -4.34 , -4.04 , -3.08 , -2.14 , -1.87 , -1.30 $
                    ||


inquire(series=series) nbeg>>start nend>>end

compute nobs=nend-nbeg+1
compute begin=nbeg+fix(trim*nobs)
compute finish=nend-fix(trim*nobs)
set time nbeg nend = t-nbeg+1

if TRANS == 1
   set transfrm nbeg nend = series
else
   set transfrm nbeg nend = log(series)




if method==1.and.model==3 {
 compute tb=nbeg
 do break=nbeg,nend-1
  set dt nbeg nend = (t>break)*(t-break)
  linreg(noprint) transfrm nbeg nend res
  #constant time dt
  set dres = res-res{1}
  compute lag=lagmax
  compute %signif=1.
  while signif<%signif {
    if lag==0 {
     linreg(noprint) res nbeg+1 nend
     #res{1}
     compute %signif=.0
     }
    else {
     linreg(noprint) res nbeg+lag+1 nend
     #res{1} dres{1 to lag}
     exclude(noprint) ; #dres{lag}
     if signif<%signif; compute lag=lag-1
     }
    }
   compute tst=(%beta(1)-1.)/sqrt(%seesq*%xx(1,1))
   if break==nbeg {
     compute tstmin=tst
     compute alpha=%beta(1)
     compute talpha=%beta(1)/sqrt(%seesq*%xx(1,1))
     compute lagopt=lag
     }
   else if tst<tstmin {
         compute tstmin=tst
         compute alpha=%beta(1)
         compute talpha=%beta(1)/sqrt(%seesq*%xx(1,1))
         compute tb=break
         compute lagopt=lag
         }
  end do break
 set dt nbeg nend = (t>tb)*(t-tb)
 linreg(noprint) transfrm nbeg nend
 #constant time dt
 display '-------------------------------------------------------------------------'
 display 'break date TB =' %datelabel(tb) ' statistic t(alpha==1) = ' @48 tstmin
 display 'critical values at' @20 '1%' @28 '5%' @36 '10%' @44 '50%' @52 '90%' @60 '95%' @68 '99%'
 if nobs<150
  display @3 'for 100 obs.' @19 #.## aour(1,2) @27 #.## aour(1,3) @35 #.## aour(1,4) $
          @43 #.## aour(1,5) @51 #.## aour(1,6) @59 #.## aour(1,7) @67 #.## aour(1,8)
 if nobs>100.and.nobs<200
  display @3 'for 150 obs.' @19 #.## aour(2,2) @27 #.## aour(2,3) @35 #.## aour(2,4) $
          @43 #.## aour(2,5) @51 #.## aour(2,6) @59 #.## aour(2,7) @67 #.## aour(2,8)
 if nobs>150.and.nobs<1000
  display @3 'for 200 obs.' @19 #.## aour(3,2) @27 #.## aour(3,3) @35 #.## aour(3,4) $
          @43 #.## aour(3,5) @51 #.## aour(3,6) @59 #.## aour(3,7) @67 #.## aour(3,8)
 if nobs>200
  display @3 'infinite sample' @19 #.## aour(4,2) @27 #.## aour(4,3) @35 #.## aour(4,4) $
          @43 #.## aour(4,5) @51 #.## aour(4,6) @59 #.## aour(4,7) @67 #.## aour(4,8)
 display '-------------------------------------------------------------------------'
 display @5 'number of lag retained :' lagopt
 display '---------------------------------------------------------'
 display(hold) 'explained variable : ' @+2
 if trans==1;display(hold) %label(series)
 else display(hold) 'log(' @+1 %label(series) @+1 ')'
 display(store=ss)
 display ss
 if trans==1;display(hold) %label(series) @+1 '{1}'
 else display(hold) 'log(' @+1 %label(series) @+1 ') {1}'
 display(store=ss)
 display '---------------------------------------------------------'
 display '                        coefficient            student'
 display '---------------------------------------------------------'
 display 'CONSTANT' @20 %beta(1) @40 %beta(1)/sqrt(%seesq*%xx(1,1))
 display 'TIME' @20 %beta(2) @40 %beta(2)/sqrt(%seesq*%xx(2,2))
 display 'DT' @20 %beta(3) @40 %beta(3)/sqrt(%seesq*%xx(3,3))
 display '---------------------------------------------------------'
 display  SS @20 alpha @40 talpha
 display '---------------------------------------------------------'
 }

if method==3.and.model==3 {
 compute tb=begin
 do break=begin,finish
  set dt nbeg nend = (t>break)*(t-break)
  linreg(noprint) transfrm nbeg nend res
  #constant time dt
  compute tst=%beta(3)/sqrt(%seesq*%xx(3,3))
  if break==begin {
    compute tstmin=tst
    set sertra = res
    }
  else if tst<tstmin {
         compute tstmin=tst
         compute tb=break
         set sertra = res
         }
  end do break
 set dres nbeg+1 nend = sertra-sertra{1}
 compute lag=lagmax
 compute %signif=1.
 while signif<%signif {
   if lag==0 {
     linreg(noprint) sertra nbeg+1 nend
     #sertra{1}
     compute %signif=.0
     }
   else {
    linreg(noprint) sertra nbeg+lag+1 nend
    #sertra{1} dres{1 to lag}
    exclude(noprint) ; #dres{lag}
    if signif<%signif; compute lag=lag-1
    }
   }
 display '-------------------------------------------------------------------------'
 display 'break date TB =' %datelabel(tb) ' statistic t(alpha==1) = ' @48 (%beta(1)-1.)/sqrt(%seesq*%xx(1,1))
 display 'critical values at' @20 '1%' @28 '5%' @36 '10%' @44 '50%' @52 '90%' @60 '95%' @68 '99%'
 if nobs<150
  display @3 'for 100 obs.' @19 #.## aostud(1,2) @27 #.## aostud(1,3) @35 #.## aostud(1,4) $
          @43 #.## aostud(1,5) @51 #.## aostud(1,6) @59 #.## aostud(1,7) @67 #.## aostud(1,8)
 if nobs>100.and.nobs<200
  display @3 'for 150 obs.' @19 #.## aostud(2,2) @27 #.## aostud(2,3) @35 #.## aostud(2,4) $
          @43 #.## aostud(2,5) @51 #.## aostud(2,6) @59 #.## aostud(2,7) @67 #.## aostud(2,8)
 if nobs>150.and.nobs<1000
  display @3 'for 200 obs.' @19 #.## aostud(3,2) @27 #.## aostud(3,3) @35 #.## aostud(3,4) $
          @43 #.## aostud(3,5) @51 #.## aostud(3,6) @59 #.## aostud(3,7) @67 #.## aostud(3,8)
 if nobs>200
  display @3 'infinite sample' @19 #.## aostud(4,2) @27 #.## aostud(4,3) @35 #.## aostud(4,4) $
          @43 #.## aostud(4,5) @51 #.## aostud(4,6) @59 #.## aostud(4,7) @67 #.## aostud(4,8)
 display '-------------------------------------------------------------------------'
 display 'from' %datelabel(nbeg) 'to' %datelabel(nend) 'search limited from' %datelabel(begin) 'to' %datelabel(finish)
 display @5 'number of lag retained :' lag
 compute alpha=%beta(1)
 compute talpha=%beta(1)/sqrt(%seesq*%xx(1,1))
 set dt nbeg nend = (t>tb)*(t-tb)
 linreg(noprint) transfrm nbeg nend
 #constant time dt
 display '---------------------------------------------------------'
 display(hold) 'explained variable : ' @+2
 if trans==1;display(hold) %label(series)
 else display(hold) 'log(' @+1 %label(series) @+1 ')'
 display(store=ss)
 display ss
 if trans==1;display(hold) %label(series) @+1 '{1}'
 else display(hold) 'log(' @+1 %label(series) @+1 ') {1}'
 display(store=ss)
 display '---------------------------------------------------------'
 display '                        coefficient            student'
 display '---------------------------------------------------------'
 display 'CONSTANT' @20 %beta(1) @40 %beta(1)/sqrt(%seesq*%xx(1,1))
 display 'TIME' @20 %beta(2) @40 %beta(2)/sqrt(%seesq*%xx(2,2))
 display 'DT' @20 %beta(3) @40 %beta(3)/sqrt(%seesq*%xx(3,3))
 display '---------------------------------------------------------'
 display  SS @20 alpha @40 talpha
 display '---------------------------------------------------------'
 }

if method==2.and.model==3 {
 compute tb=begin
 do break=begin,finish
  set dt nbeg nend = (t>break)*(t-break)
  linreg(noprint) transfrm nbeg nend res
  #constant time dt
  compute tst=abs(%beta(3)/sqrt(%seesq*%xx(3,3)))
  if break==begin {
    compute tstmax=tst
    set sertra = res
    }
  else if tst>tstmax {
         compute tstmax=tst
         compute tb=break
         set sertra = res
         }
  end do break
 set dres nbeg+1 nend = sertra-sertra{1}
 compute lag=lagmax
 compute %signif=1.
 while signif<%signif {
   if lag==0 {
     linreg(noprint) sertra nbeg+1 nend
     #sertra{1}
     compute %signif=.0
     }
   else {
    linreg(noprint) sertra nbeg+lag+1 nend
    #sertra{1} dres{1 to lag}
    exclude(noprint) ; #dres{lag}
    if signif<%signif; compute lag=lag-1
    }
   }
 display '-------------------------------------------------------------------------'
 display 'break date TB =' %datelabel(tb) ' statistic t(alpha==1) = ' @48 (%beta(1)-1.)/sqrt(%seesq*%xx(1,1))
 display 'critical values at' @20 '1%' @28 '5%' @36 '10%' @44 '50%' @52 '90%' @60 '95%' @68 '99%'
 if nobs<150
  display @3 'for 100 obs.' @19 #.## aostuda(1,2) @27 #.## aostuda(1,3) @35 #.## aostuda(1,4) $
          @43 #.## aostuda(1,5) @51 #.## aostuda(1,6) @59 #.## aostuda(1,7) @67 #.## aostuda(1,8)
 if nobs>100.and.nobs<200
  display @3 'for 150 obs.' @19 #.## aostuda(2,2) @27 #.## aostuda(2,3) @35 #.## aostuda(2,4) $
          @43 #.## aostuda(2,5) @51 #.## aostuda(2,6) @59 #.## aostuda(2,7) @67 #.## aostuda(2,8)
 if nobs>150.and.nobs<1000
  display @3 'for 200 obs.' @19 #.## aostuda(3,2) @27 #.## aostuda(3,3) @35 #.## aostuda(3,4) $
          @43 #.## aostuda(3,5) @51 #.## aostuda(3,6) @59 #.## aostuda(3,7) @67 #.## aostuda(3,8)
 if nobs>200
  display @3 'infinite sample' @19 #.## aostuda(4,2) @27 #.## aostuda(4,3) @35 #.## aostuda(4,4) $
          @43 #.## aostuda(4,5) @51 #.## aostuda(4,6) @59 #.## aostuda(4,7) @67 #.## aostuda(4,8)
 display '-------------------------------------------------------------------------'
 display 'from' %datelabel(nbeg) 'to' %datelabel(nend) 'search limited from' %datelabel(begin) 'to' %datelabel(finish)
 display @5 'number of lag retained :' lag
 compute alpha=%beta(1)
 compute talpha=%beta(1)/sqrt(%seesq*%xx(1,1))
 set dt nbeg nend = (t>tb)*(t-tb)
 linreg(noprint) transfrm nbeg nend
 #constant time dt
 display '---------------------------------------------------------'
 display(hold) 'explained variable : ' @+2
 if trans==1;display(hold) %label(series)
 else display(hold) 'log(' @+1 %label(series) @+1 ')'
 display(store=ss)
 display ss
 if trans==1;display(hold) %label(series) @+1 '{1}'
 else display(hold) 'log(' @+1 %label(series) @+1 ') {1}'
 display(store=ss)
 display '---------------------------------------------------------'
 display '                        coefficient            student'
 display '---------------------------------------------------------'
 display 'CONSTANT' @20 %beta(1) @40 %beta(1)/sqrt(%seesq*%xx(1,1))
 display 'TIME' @20 %beta(2) @40 %beta(2)/sqrt(%seesq*%xx(2,2))
 display 'DT' @20 %beta(3) @40 %beta(3)/sqrt(%seesq*%xx(3,3))
 display '---------------------------------------------------------'
 display  SS @20 alpha @40 talpha
 display '---------------------------------------------------------'
 }


if method==1.and.model==2 {
 set sertra nbeg+1 nend = transfrm-transfrm{1}
 compute tb=nbeg
 do break=nbeg,nend-1
  set dt nbeg nend = (t>break)*t
  set du nbeg nend = (t>break)
  set dummy nbeg nend = (t==break+1)
  compute lag=lagmax
  compute %signif=1.
  while signif<%signif {
    if lag==0 {
     linreg(noprint) transfrm nbeg+1 nend
     #transfrm{1} constant du time dt dummy
     compute %signif=.0
     }
    else {
     linreg(noprint) transfrm nbeg+lag+1 nend
     #transfrm{1} constant du time dt dummy sertra{1 to lag}
     exclude(noprint) ; #sertra{lag}
     if signif<%signif; compute lag=lag-1
     }
    }
   compute tst=(%beta(1)-1.)/sqrt(%seesq*%xx(1,1))
   if break==nbeg {
     compute tstmin=tst
     compute lagopt=lag
     }
   else if tst<tstmin {
         compute tstmin=tst
         compute tb=break
         compute lagopt=lag
         }
  end do break
  set dt nbeg nend = (t>tb)*t
  set du nbeg nend = (t>tb)
  set dummy nbeg nend = (t==tb+1)
  if lagopt==0 {
   linreg(noprint) transfrm nbeg+1 nend
   #transfrm{1} constant du time dt dummy
   }
  else {
   linreg(noprint) transfrm nbeg+lagopt+1 nend
   #transfrm{1} constant du time dt dummy sertra{1 to lagopt}
   }
 display '-------------------------------------------------------------------------'
 display 'break date TB =' %datelabel(tb) ' statistic t(alpha==1) = ' @48 tstmin
 display 'critical values at' @20 '1%' @28 '5%' @36 '10%' @44 '50%' @52 '90%' @60 '95%' @68 '99%'
 if nobs<100
  display @3 'for 70  obs.' @19 #.## io2ur(1,2) @27 #.## io2ur(1,3) @35 #.## io2ur(1,4) $
          @43 #.## io2ur(1,5) @51 #.## io2ur(1,6) @59 #.## io2ur(1,7) @67 #.## io2ur(1,8)
 if nobs>70.and.nobs<1000
  display @3 'for 100 obs.' @19 #.## io2ur(2,2) @27 #.## io2ur(2,3) @35 #.## io2ur(2,4) $
          @43 #.## io2ur(2,5) @51 #.## io2ur(2,6) @59 #.## io2ur(2,7) @67 #.## io2ur(2,8)
 if nobs>100
  display @3 'infinite sample' @19 #.## io2ur(3,2) @27 #.## io2ur(3,3) @35 #.## io2ur(3,4) $
          @43 #.## io2ur(3,5) @51 #.## io2ur(3,6) @59 #.## io2ur(3,7) @67 #.## io2ur(3,8)
 display '-------------------------------------------------------------------------'
 display @5 'number of lag retained :' lagopt
 display '---------------------------------------------------------'
 display(hold) 'explained variable : ' @+2
 if trans==1;display(hold) %label(series)
 else display(hold) 'log(' @+1 %label(series) @+1 ')'
 display(store=ss)
 display ss
 if trans==1;display(hold) %label(series) @+1 '{1}'
 else display(hold) 'log(' @+1 %label(series) @+1 ') {1}'
 display(store=ss)
 display '---------------------------------------------------------'
 display '                        coefficient            student'
 display '---------------------------------------------------------'
 display 'CONSTANT' @20 %beta(2) @40 %beta(2)/sqrt(%seesq*%xx(2,2))
 display 'DU' @20 %beta(3) @40 %beta(3)/sqrt(%seesq*%xx(3,3))
 display 'D(Tb)' @20 %beta(6) @40 %beta(6)/sqrt(%seesq*%xx(6,6))
 display 'TIME' @20 %beta(4) @40 %beta(4)/sqrt(%seesq*%xx(4,4))
 display 'DT' @20 %beta(5) @40 %beta(5)/sqrt(%seesq*%xx(5,5))
 display  SS  @20 %beta(1) @40 %beta(1)/sqrt(%seesq*%xx(1,1))
 display '---------------------------------------------------------'
 }


if method==3.and.model==2 {
 set sertra nbeg+1 nend = transfrm-transfrm{1}
 compute tb=begin
 do break=begin,finish
  set dt nbeg nend = (t>break)*t
  set du nbeg nend = (t>break)
  set dummy nbeg nend = (t==break+1)
  compute lag=lagmax
  compute %signif=1.
  while signif<%signif {
    if lag==0 {
     linreg(noprint) transfrm nbeg+1 nend
     #transfrm{1} constant du time dt dummy
     compute %signif=.0
     }
    else {
     linreg(noprint) transfrm nbeg+lag+1 nend
     #transfrm{1} constant du time dt dummy sertra{1 to lag}
     exclude(noprint) ; #sertra{lag}
     if signif<%signif; compute lag=lag-1
     }
    }
   compute tst=%beta(5)/sqrt(%seesq*%xx(5,5))
   if break==begin {
     compute tstmin=tst
     compute lagopt=lag
     }
   else if tst<tstmin {
         compute tstmin=tst
         compute tb=break
         compute lagopt=lag
         }
  end do break
  set dt nbeg nend = (t>tb)*t
  set du nbeg nend = (t>tb)
  set dummy nbeg nend = (t==tb+1)
  if lagopt==0 {
   linreg(noprint) transfrm nbeg+1 nend
   #transfrm{1} constant du time dt dummy
   }
  else {
   linreg(noprint) transfrm nbeg+lagopt+1 nend
   #transfrm{1} constant du time dt dummy sertra{1 to lagopt}
   }
 display '-------------------------------------------------------------------------'
 display 'break date TB =' %datelabel(tb) ' statistic t(alpha==1) = ' @48 (%beta(1)-1)/sqrt(%seesq*%xx(1,1))
 display 'critical values at' @20 '1%' @28 '5%' @36 '10%' @44 '50%' @52 '90%' @60 '95%' @68 '99%'
 if nobs<100
  display @3 'for 70  obs.' @19 #.## io2stud(1,2) @27 #.## io2stud(1,3) @35 #.## io2stud(1,4) $
          @43 #.## io2stud(1,5) @51 #.## io2stud(1,6) @59 #.## io2stud(1,7) @67 #.## io2stud(1,8)
 if nobs>70.and.nobs<1000
  display @3 'for 100 obs.' @19 #.## io2stud(2,2) @27 #.## io2stud(2,3) @35 #.## io2stud(2,4) $
          @43 #.## io2stud(2,5) @51 #.## io2stud(2,6) @59 #.## io2stud(2,7) @67 #.## io2stud(2,8)
 if nobs>100
  display @3 'infinite sample' @19 #.## io2stud(3,2) @27 #.## io2stud(3,3) @35 #.## io2stud(3,4) $
          @43 #.## io2stud(3,5) @51 #.## io2stud(3,6) @59 #.## io2stud(3,7) @67 #.## io2stud(3,8)
 display '-------------------------------------------------------------------------'
 display 'from' %datelabel(nbeg) 'to' %datelabel(nend) 'search limited from' %datelabel(begin) 'to' %datelabel(finish)
 display @5 'number of lag retained :' lagopt
 display '---------------------------------------------------------'
 display(hold) 'explained variable : ' @+2
 if trans==1;display(hold) %label(series)
 else display(hold) 'log(' @+1 %label(series) @+1 ')'
 display(store=ss)
 display ss
 if trans==1;display(hold) %label(series) @+1 '{1}'
 else display(hold) 'log(' @+1 %label(series) @+1 ') {1}'
 display(store=ss)
 display '---------------------------------------------------------'
 display '                        coefficient            student'
 display '---------------------------------------------------------'
 display 'CONSTANT' @20 %beta(2) @40 %beta(2)/sqrt(%seesq*%xx(2,2))
 display 'DU' @20 %beta(3) @40 %beta(3)/sqrt(%seesq*%xx(3,3))
 display 'D(Tb)' @20 %beta(6) @40 %beta(6)/sqrt(%seesq*%xx(6,6))
 display 'TIME' @20 %beta(4) @40 %beta(4)/sqrt(%seesq*%xx(4,4))
 display 'DT' @20 %beta(5) @40 %beta(5)/sqrt(%seesq*%xx(5,5))
 display  SS  @20 %beta(1) @40 %beta(1)/sqrt(%seesq*%xx(1,1))
 display '---------------------------------------------------------'
 }


if method==2.and.model==2 {
 set sertra nbeg+1 nend = transfrm-transfrm{1}
 compute tb=begin
 do break=begin,finish
  set dt nbeg nend = (t>break)*t
  set du nbeg nend = (t>break)
  set dummy nbeg nend = (t==break+1)
  compute lag=lagmax
  compute %signif=1.
  while signif<%signif {
    if lag==0 {
     linreg(noprint) transfrm nbeg+1 nend
     #transfrm{1} constant du time dt dummy
     compute %signif=.0
     }
    else {
     linreg(noprint) transfrm nbeg+lag+1 nend
     #transfrm{1} constant du time dt dummy sertra{1 to lag}
     exclude(noprint) ; #sertra{lag}
     if signif<%signif; compute lag=lag-1
     }
    }
   compute tst=abs(%beta(5)/sqrt(%seesq*%xx(5,5)))
   if break==begin {
     compute tstmax=tst
     compute lagopt=lag
     }
   else if tst>tstmax {
         compute tstmax=tst
         compute tb=break
         compute lagopt=lag
         }
  end do break
  set dt nbeg nend = (t>tb)*t
  set du nbeg nend = (t>tb)
  set dummy nbeg nend = (t==tb+1)
  if lagopt==0 {
   linreg(noprint) transfrm nbeg+1 nend
   #transfrm{1} constant du time dt dummy
   }
  else {
   linreg(noprint) transfrm nbeg+lagopt+1 nend
   #transfrm{1} constant du time dt dummy sertra{1 to lagopt}
   }
 display '-------------------------------------------------------------------------'
 display 'break date TB =' %datelabel(tb) ' statistic t(alpha==1) = ' @48 (%beta(1)-1)/sqrt(%seesq*%xx(1,1))
 display 'critical values at' @20 '1%' @28 '5%' @36 '10%' @44 '50%' @52 '90%' @60 '95%' @68 '99%'
 if nobs<100
  display @3 'for 70  obs.' @19 #.## io2studa(1,2) @27 #.## io2studa(1,3) @35 #.## io2studa(1,4) $
          @43 #.## io2studa(1,5) @51 #.## io2studa(1,6) @59 #.## io2studa(1,7) @67 #.## io2studa(1,8)
 if nobs>70.and.nobs<1000
  display @3 'for 100 obs.' @19 #.## io2studa(2,2) @27 #.## io2studa(2,3) @35 #.## io2studa(2,4) $
          @43 #.## io2studa(2,5) @51 #.## io2studa(2,6) @59 #.## io2studa(2,7) @67 #.## io2studa(2,8)
 if nobs>100
  display @3 'infinite sample' @19 #.## io2studa(3,2) @27 #.## io2studa(3,3) @35 #.## io2studa(3,4) $
          @43 #.## io2studa(3,5) @51 #.## io2studa(3,6) @59 #.## io2studa(3,7) @67 #.## io2studa(3,8)
 display '-------------------------------------------------------------------------'
 display 'from' %datelabel(nbeg) 'to' %datelabel(nend) 'search limited from' %datelabel(begin) 'to' %datelabel(finish)
 display @5 'number of lag retained :' lagopt
 display '---------------------------------------------------------'
 display(hold) 'explained variable : ' @+2
 if trans==1;display(hold) %label(series)
 else display(hold) 'log(' @+1 %label(series) @+1 ')'
 display(store=ss)
 display ss
 if trans==1;display(hold) %label(series) @+1 '{1}'
 else display(hold) 'log(' @+1 %label(series) @+1 ') {1}'
 display(store=ss)
 display '---------------------------------------------------------'
 display '                        coefficient            student'
 display '---------------------------------------------------------'
 display 'CONSTANT' @20 %beta(2) @40 %beta(2)/sqrt(%seesq*%xx(2,2))
 display 'DU' @20 %beta(3) @40 %beta(3)/sqrt(%seesq*%xx(3,3))
 display 'D(Tb)' @20 %beta(6) @40 %beta(6)/sqrt(%seesq*%xx(6,6))
 display 'TIME' @20 %beta(4) @40 %beta(4)/sqrt(%seesq*%xx(4,4))
 display 'DT' @20 %beta(5) @40 %beta(5)/sqrt(%seesq*%xx(5,5))
 display  SS  @20 %beta(1) @40 %beta(1)/sqrt(%seesq*%xx(1,1))
 display '---------------------------------------------------------'
 }




if method==1.and.model==1 {
 set sertra nbeg+1 nend = transfrm-transfrm{1}
 compute tb=nbeg
 do break=nbeg,nend-1
  set du nbeg nend = (t>break)
  set dummy nbeg nend = (t==break+1)
  compute lag=lagmax
  compute %signif=1.
  while signif<%signif {
    if lag==0 {
     linreg(noprint) transfrm nbeg+1 nend
     #transfrm{1} constant du time dummy
     compute %signif=.0
     }
    else {
     linreg(noprint) transfrm nbeg+lag+1 nend
     #transfrm{1} constant du time dummy sertra{1 to lag}
     exclude(noprint) ; #sertra{lag}
     if signif<%signif; compute lag=lag-1
     }
    }
   compute tst=(%beta(1)-1.)/sqrt(%seesq*%xx(1,1))
   if break==nbeg {
     compute tstmin=tst
     compute lagopt=lag
     }
   else if tst<tstmin {
         compute tstmin=tst
         compute tb=break
         compute lagopt=lag
         }
  end do break
  set du nbeg nend = (t>tb)
  set dummy nbeg nend = (t==tb+1)
  if lagopt==0 {
   linreg(noprint) transfrm nbeg+1 nend
   #transfrm{1} constant du time dummy
   }
  else {
   linreg(noprint) transfrm nbeg+lagopt+1 nend
   #transfrm{1} constant du time dummy sertra{1 to lagopt}
   }
 display '-------------------------------------------------------------------------'
 display 'break date TB =' %datelabel(tb) ' statistic t(alpha==1) = ' @48 tstmin
 display 'critical values at' @20 '1%' @28 '5%' @36 '10%' @44 '50%' @52 '90%' @60 '95%' @68 '99%'
 if nobs<80
  display @3 'for 60  obs.' @19 #.## io1ur(1,2) @27 #.## io1ur(1,3) @35 #.## io1ur(1,4) $
          @43 #.## io1ur(1,5) @51 #.## io1ur(1,6) @59 #.## io1ur(1,7) @67 #.## io1ur(1,8)
 if nobs>60.and.nobs<100
  display @3 'for 80  obs.' @19 #.## io1ur(2,2) @27 #.## io1ur(2,3) @35 #.## io1ur(2,4) $
          @43 #.## io1ur(2,5) @51 #.## io1ur(2,6) @59 #.## io1ur(2,7) @67 #.## io1ur(2,8)
 if nobs>80.and.nobs<1000
  display @3 'for 100 obs.' @19 #.## io1ur(3,2) @27 #.## io1ur(3,3) @35 #.## io1ur(3,4) $
          @43 #.## io1ur(3,5) @51 #.## io1ur(3,6) @59 #.## io1ur(3,7) @67 #.## io1ur(3,8)
 if nobs>100
  display @3 'infinite sample' @19 #.## io1ur(4,2) @27 #.## io1ur(4,3) @35 #.## io1ur(4,4) $
          @43 #.## io1ur(4,5) @51 #.## io1ur(4,6) @59 #.## io1ur(4,7) @67 #.## io1ur(4,8)
 display '-------------------------------------------------------------------------'
 display @5 'number of lag retained :' lagopt
 display '---------------------------------------------------------'
 display(hold) 'explained variable : ' @+2
 if trans==1;display(hold) %label(series)
 else display(hold) 'log(' @+1 %label(series) @+1 ')'
 display(store=ss)
 display ss
 if trans==1;display(hold) %label(series) @+1 '{1}'
 else display(hold) 'log(' @+1 %label(series) @+1 ') {1}'
 display(store=ss)
 display '---------------------------------------------------------'
 display '                        coefficient            student'
 display '---------------------------------------------------------'
 display 'CONSTANT' @20 %beta(2) @40 %beta(2)/sqrt(%seesq*%xx(2,2))
 display 'DU' @20 %beta(3) @40 %beta(3)/sqrt(%seesq*%xx(3,3))
 display 'D(Tb)' @20 %beta(5) @40 %beta(5)/sqrt(%seesq*%xx(5,5))
 display 'TIME' @20 %beta(4) @40 %beta(4)/sqrt(%seesq*%xx(4,4))
 display  SS  @20 %beta(1) @40 %beta(1)/sqrt(%seesq*%xx(1,1))
 display '---------------------------------------------------------'
 }


if method==3.and.model==1 {
 set sertra nbeg+1 nend = transfrm-transfrm{1}
 compute tb=begin
 do break=begin,finish
  set du nbeg nend = (t>break)
  set dummy nbeg nend = (t==break+1)
  compute lag=lagmax
  compute %signif=1.
  while signif<%signif {
    if lag==0 {
     linreg(noprint) transfrm nbeg+1 nend
     #transfrm{1} constant du time dummy
     compute %signif=.0
     }
    else {
     linreg(noprint) transfrm nbeg+lag+1 nend
     #transfrm{1} constant du time dummy sertra{1 to lag}
     exclude(noprint) ; #sertra{lag}
     if signif<%signif; compute lag=lag-1
     }
    }
   compute tst=%beta(3)/sqrt(%seesq*%xx(3,3))
   if break==begin {
     compute tstmin=tst
     compute lagopt=lag
     }
   else if tst<tstmin {
         compute tstmin=tst
         compute tb=break
         compute lagopt=lag
         }
  end do break
  set du nbeg nend = (t>tb)
  set dummy nbeg nend = (t==tb+1)
  if lagopt==0 {
   linreg(noprint) transfrm nbeg+1 nend
   #transfrm{1} constant du time dummy
   }
  else {
   linreg(noprint) transfrm nbeg+lagopt+1 nend
   #transfrm{1} constant du time dummy sertra{1 to lagopt}
   }
 display '-------------------------------------------------------------------------'
 display 'break date TB =' %datelabel(tb) ' statistic t(alpha==1) = ' @48 (%beta(1)-1)/sqrt(%seesq*%xx(1,1))
 display 'critical values at' @20 '1%' @28 '5%' @36 '10%' @44 '50%' @52 '90%' @60 '95%' @68 '99%'
 if nobs<80
  display @3 'for 60  obs.' @19 #.## io1stud(1,2) @27 #.## io1stud(1,3) @35 #.## io1stud(1,4) $
          @43 #.## io1stud(1,5) @51 #.## io1stud(1,6) @59 #.## io1stud(1,7) @67 #.## io1stud(1,8)
 if nobs>60.and.nobs<100
  display @3 'for 80  obs.' @19 #.## io1stud(2,2) @27 #.## io1stud(2,3) @35 #.## io1stud(2,4) $
          @43 #.## io1stud(2,5) @51 #.## io1stud(2,6) @59 #.## io1stud(2,7) @67 #.## io1stud(2,8)
 if nobs>80.and.nobs<1000
  display @3 'for 100 obs.' @19 #.## io1stud(3,2) @27 #.## io1stud(3,3) @35 #.## io1stud(3,4) $
          @43 #.## io1stud(3,5) @51 #.## io1stud(3,6) @59 #.## io1stud(3,7) @67 #.## io1stud(3,8)
 if nobs>100
  display @3 'infinite sample' @19 #.## io1stud(4,2) @27 #.## io1stud(4,3) @35 #.## io1stud(4,4) $
          @43 #.## io1stud(4,5) @51 #.## io1stud(4,6) @59 #.## io1stud(4,7) @67 #.## io1stud(4,8)
 display '-------------------------------------------------------------------------'
 display 'from' %datelabel(nbeg) 'to' %datelabel(nend) 'search limited from' %datelabel(begin) 'to' %datelabel(finish)
 display @5 'number of lag retained :' lagopt
 display '---------------------------------------------------------'
 display(hold) 'explained variable : ' @+2
 if trans==1;display(hold) %label(series)
 else display(hold) 'log(' @+1 %label(series) @+1 ')'
 display(store=ss)
 display ss
 if trans==1;display(hold) %label(series) @+1 '{1}'
 else display(hold) 'log(' @+1 %label(series) @+1 ') {1}'
 display(store=ss)
 display '---------------------------------------------------------'
 display '                        coefficient            student'
 display '---------------------------------------------------------'
 display 'CONSTANT' @20 %beta(2) @40 %beta(2)/sqrt(%seesq*%xx(2,2))
 display 'DU' @20 %beta(3) @40 %beta(3)/sqrt(%seesq*%xx(3,3))
 display 'D(Tb)' @20 %beta(5) @40 %beta(5)/sqrt(%seesq*%xx(5,5))
 display 'TIME' @20 %beta(4) @40 %beta(4)/sqrt(%seesq*%xx(4,4))
 display  SS  @20 %beta(1) @40 %beta(1)/sqrt(%seesq*%xx(1,1))
 display '---------------------------------------------------------'
 }


if method==2.and.model==1 {
 set sertra nbeg+1 nend = transfrm-transfrm{1}
 compute tb=begin
 do break=begin,finish
  set du nbeg nend = (t>break)
  set dummy nbeg nend = (t==break+1)
  compute lag=lagmax
  compute %signif=1.
  while signif<%signif {
    if lag==0 {
     linreg(noprint) transfrm nbeg+1 nend
     #transfrm{1} constant du time dummy
     compute %signif=.0
     }
    else {
     linreg(noprint) transfrm nbeg+lag+1 nend
     #transfrm{1} constant du time dummy sertra{1 to lag}
     exclude(noprint) ; #sertra{lag}
     if signif<%signif; compute lag=lag-1
     }
    }
   compute tst=abs(%beta(3)/sqrt(%seesq*%xx(3,3)))
   if break==begin {
     compute tstmax=tst
     compute lagopt=lag
     }
   else if tst>tstmax {
         compute tstmax=tst
         compute tb=break
         compute lagopt=lag
         }
  end do break
  set du nbeg nend = (t>tb)
  set dummy nbeg nend = (t==tb+1)
  if lagopt==0 {
   linreg(noprint) transfrm nbeg+1 nend
   #transfrm{1} constant du time dummy
   }
  else {
   linreg(noprint) transfrm nbeg+lagopt+1 nend
   #transfrm{1} constant du time dummy sertra{1 to lagopt}
   }
 display '-------------------------------------------------------------------------'
 display 'break date TB =' %datelabel(tb) ' statistic t(alpha==1) = ' @48 (%beta(1)-1)/sqrt(%seesq*%xx(1,1))
 display 'critical values at' @20 '1%' @28 '5%' @36 '10%' @44 '50%' @52 '90%' @60 '95%' @68 '99%'
 if nobs<80
  display @3 'for 60  obs.' @19 #.## io1studa(1,2) @27 #.## io1studa(1,3) @35 #.## io1studa(1,4) $
          @43 #.## io1studa(1,5) @51 #.## io1studa(1,6) @59 #.## io1studa(1,7) @67 #.## io1studa(1,8)
 if nobs>60.and.nobs<100
  display @3 'for 80  obs.' @19 #.## io1studa(2,2) @27 #.## io1studa(2,3) @35 #.## io1studa(2,4) $
          @43 #.## io1studa(2,5) @51 #.## io1studa(2,6) @59 #.## io1studa(2,7) @67 #.## io1studa(2,8)
 if nobs>80.and.nobs<1000
  display @3 'for 100 obs.' @19 #.## io1studa(3,2) @27 #.## io1studa(3,3) @35 #.## io1studa(3,4) $
          @43 #.## io1studa(3,5) @51 #.## io1studa(3,6) @59 #.## io1studa(3,7) @67 #.## io1studa(3,8)
 if nobs>100
  display @3 'infinite sample' @19 #.## io1studa(4,2) @27 #.## io1studa(4,3) @35 #.## io1studa(4,4) $
          @43 #.## io1studa(4,5) @51 #.## io1studa(4,6) @59 #.## io1studa(4,7) @67 #.## io1studa(4,8)
 display '-------------------------------------------------------------------------'
 display 'from' %datelabel(nbeg) 'to' %datelabel(nend) 'search limited from' %datelabel(begin) 'to' %datelabel(finish)
 display @5 'number of lag retained :' lagopt
 display '---------------------------------------------------------'
 display(hold) 'explained variable : ' @+2
 if trans==1;display(hold) %label(series)
 else display(hold) 'log(' @+1 %label(series) @+1 ')'
 display(store=ss)
 display ss
 if trans==1;display(hold) %label(series) @+1 '{1}'
 else display(hold) 'log(' @+1 %label(series) @+1 ') {1}'
 display(store=ss)
 display '---------------------------------------------------------'
 display '                        coefficient            student'
 display '---------------------------------------------------------'
 display 'CONSTANT' @20 %beta(2) @40 %beta(2)/sqrt(%seesq*%xx(2,2))
 display 'DU' @20 %beta(3) @40 %beta(3)/sqrt(%seesq*%xx(3,3))
 display 'D(Tb)' @20 %beta(5) @40 %beta(5)/sqrt(%seesq*%xx(5,5))
 display 'TIME' @20 %beta(4) @40 %beta(4)/sqrt(%seesq*%xx(4,4))
 display  SS  @20 %beta(1) @40 %beta(1)/sqrt(%seesq*%xx(1,1))
 display '---------------------------------------------------------'
 }

end

