logmode +addin 'check that an object exists %type = @getthistype if %type="NONE" then @uiprompt("No object found, please open an equation object") stop endif 'check that _this object is an equation if %type<>"EQUATION" then @uiprompt("Procedure can only be run from an equation object") stop endif 'error on panels if @ispanel then @uiprompt("Procedure cannot be run in panel workfiles") stop endif 'Rolling specification %cmnd = _this.@command %start = "@first" 'roll start point %end = "@last" 'roll end point %window = "20" 'window size %step = "10" 'step size 'storage/display options !StoreCoefs = 1 'store coefficients !StoreSEs = 0 'store standard errors !StorePs = 0 'store P-values !StoreR2s = 0 'store R-squareds !StoreSER = 0 ' store S.E. of regression !doGraphs = 1 'display graphs of the stored variables. !doGUI = 1 'show dialogs 'process options if @len(@option(1)) then %start = @equaloption("start") %end = @equaloption("end") %window = @equaloption("w") %step = @equaloption("s") !storecoefs = @hasoption("coef") !storeses = @hasoption("se") !storeps = @hasoption("pval") !storer2s = @hasoption("r2") !storeser = @hasoption ("ser") !dographs = @hasoption("g") !doGUI = @hasoption("prompt") endif if !doGUI = 1 then !result = @uidialog("edit",%start,"Start date/obs","edit",%end, "Last date/obs","edit",%window,"Window size","edit",%step,"Step size","colbreak","text","Storage options","check",!StoreCoefs,"Store Coefficients","check",!StoreSEs,"Store Std. Errors","check",!StorePs,"Store P-values","check",!StoreR2s,"Store R-squareds","check",!StoreSer,"Store S.E. of Regression","check",!doGraphs,"Create Graphs","caption","Rolling Specification and Storage Options") if !result = -1 then stop endif endif 'set sample to all observerations covered smpl {%start} {%end} !window = @val(%window) !step = @val(%step) !obs = @obssmpl !rolls = (!obs-!window)/!step 'number of rolls that will take place 'Check whether number of rolls is an integer, warn other wise if !rolls <> @floor(!rolls) then !rolls = @floor(!rolls) !end = @dtoo(%start) + (!rolls)*!step+!window-1 %end = @otod(!end) %msg = "Warning: roll specification incompatible with start point and end point - adjusting end point to " + %end if !doGUI = 1 then @uiprompt(%msg) endif endif if _this.@bylist=1 then %coefnames = _this.@varlist %coefnames = @wmid(%coefnames,2) 'drop dependent var. else %coefnames = _this.@coeflist endif 'convert coefficient names to valid eviews names (if necessary) for !i=1 to @wcount(%coefnames) %tempname = @word(%coefnames,!i) if @isvalidname(%tempname)=0 then %tempname = @makevalidname(%tempname) endif %tempstr = %tempstr + " " + %tempname next %tempstr = @trim(%tempstr) %coefnames = %tempstr !NCoefs = _this.@ncoef 'Declare series to store coefs if !StoreCoefs = 1 then %cgrpname = "rollcoefs" if @isobject(%cgrpname) then %cgrpname = @getnextname(%cgrpname) endif group {%cgrpname} for !i=1 to !NCoefs %cname = @word(%coefnames,!i) %sername = %cgrpname + "_" + %cname series {%sername} {%sername}.displayname {%cname} {%cgrpname}.add {%sername} next endif 'Declare series to store SEs if !StoreSes = 1 then %sgrpname = "rollses" if @isobject(%sgrpname) then %sgrpname = @getnextname(%sgrpname) endif group {%sgrpname} for !i=1 to !NCoefs %cname = @word(%coefnames,!i) %sername = %sgrpname+ "_" + @word(%coefnames,!i) series {%sername} {%sername}.displayname {%cname} {%sgrpname}.add {%sername} next endif 'Declare series to store PVals if !StorePs = 1 then %pgrpname = "rollpvals" if @isobject(%pgrpname) then %pgrpname= @getnextname(%pgrpname) endif group {%pgrpname} for !i=1 to !NCoefs %cname = @word(%coefnames,!i) %sername = %pgrpname+ "_" + @word(%coefnames,!i) series {%sername} {%sername}.displayname {%cname} {%pgrpname}.add {%sername} next endif 'Declare series to store R2s if !StoreR2s = 1 then %rsername = "rollr2s" if @isobject(%rgrpname) then %rgrpname = @getnextname(%rgrpname) endif series {%rsername } endif 'Declare series to store S.E. if !StoreSer = 1 then %sersername = "rollser" if @isobject(%sergrpname) then %sergrpname = @getnextname(%sergrpname) endif series {%sersername } endif 'roll the sample for !i=1 to !obs-!window+1-!step step !step !k = !i+!window-1 %first = @otod(@dtoo(%start)+!i-1) %last = @otod(@dtoo(%start)+!i+!window-2) smpl {%first} {%last} !kk = @dtoo(%start) + !k -1 'estimate equation _this.{%cmnd} 'store stuff if !StoreCoefs=1 then for !j=1 to !NCoefs %sername = {%cgrpname}.@seriesname(!j) {%sername}(!kk) = _this.@coef(!j) next endif if !StoreSEs=1 then for !j=1 to !NCoefs %sername = {%sgrpname}.@seriesname(!j) {%sername}(!kk) = _this.@stderrs(!j) next endif if !StorePs=1 then for !j=1 to !NCoefs !df = (_this.@regobs-_this.@ncoef) vector tempvec =@tdist(_this.@tstats,!df) %sername = {%pgrpname}.@seriesname(!j) {%sername}(!kk) = tempvec(!j) d tempvec next endif if !Storer2s=1 then {%rsername}(!kk)=_this.@r2 endif if !Storeser = 1 then {%sersername}(!kk)=_this.@se endif next 'reset the sample smpl {%start} {%end} 're-estimate equation for postereity. _this.{%cmnd} 'make graphs if !doGraphs=1 then if !StoreCoefs=1 then %cgraphname = "coefgraph" If @isobject(%cgraphname) then %cgraphname = @getnextname(%cgraphname) endif freeze({%cgraphname}) {%cgrpname}.line(m) for !i=1 to !NCoefs %varname = @word(%coefnames,!i) {%cgraphname}.name(!i) {%varname} next {%cgraphname}.addtext(t, font(18)) "Rolling Coefficients" {%cgraphname}.options connect _this.display {%cgraphname} endif if !StoreSEs=1 then %sgraphname = "SEgraph" If @isobject(%sgraphname) then %sgraphname = @getnextname(%sgraphname) endif freeze({%sgraphname}) {%sgrpname}.line(m) for !i=1 to !NCoefs %varname = @word(%coefnames,!i) {%sgraphname}.name(!i) {%varname} next {%sgraphname}.addtext(t, font(18)) "Rolling Standard Errors" {%sgraphname}.options connect endif if !StorePs=1 then %pgraphname = "PValgraph" If @isobject(%pgraphname) then %pgraphname = @getnextname(%pgraphname) endif freeze({%pgraphname}) {%pgrpname}.line(m) for !i=1 to !NCoefs %varname = @word(%coefnames,!i) {%pgraphname}.name(!i) {%varname} next {%pgraphname}.addtext(t, font(18)) "Rolling P-Values" {%pgraphname}.options connect endif if !StoreR2s=1 then %rgraphname = "R2graph" If @isobject(%rgraphname) then %rgraphname = @getnextname(%rgraphname) endif freeze({%rgraphname}) {%rsername}.line() {%rgraphname}.addtext(t, font(18)) "Rolling R-Squares" {%rgraphname}.options connect endif if !StoreSER =1 then %sergraphname = "Sergraph" if @isobject(%sergraphname) then %sergrapgname = @getnextname(%sergraphname) endif freeze({%sergraphname}) {%sersername}.line() {%sergraphname}.addtext(t,fornt(18)) "Rolling S.E." {%sergraphname}.options connect endif endif