@Portions are Version 2.4, November 19, 1999. Copyright, Pierre Perron (1999)@ @Modified by Karen Lewis (2005) under a grant from the National Science Foundation@ /* Program to run individual stock returns on residuals from local regressions on US */ new; format /ld 6,4; dirname = sysstate(2,0); // go to gauss dir /* Market return for US is DS Index */ fnus = dirname$+"usret.xls"; /* US Risk Free Rate */ fnw = dirname$+"us_stk.xls"; fnn = dirname$+"kl_stk2.xls"; fnc = dirname$+"dslres10_2.xls"; nout10 = dirname$+"dsall10_2.xls"; nout5 = dirname$+"dsall5_2.xls"; nout2p5 = dirname$+"dsall2p5_2.xls"; nout1 = dirname$+"dsall1_2.xls"; output file = c:\gauss6\m-Break\dsall2.out reset; @select your output file@ ncn = xlsMakeRange(7,2); p1 = xlsreadm(fnn, ncn, 1, ""); @p1 = (p1[.,1]/1000000)~p1[.,2:cols(p1)];@ np = miss(p1,9999); ro = {1,1782}; co = {1,124}; cbd = xlsMakeRange(ro,co); c1 = xlsreadm(fnc, cbd, 1, ""); fro = 9999*ones(1,cols(c1)); c1 = fro|c1; newcount = miss(c1,9999); cp = cols(c1); /* US Risk Free Rate */ w1 = xlsreadm(fnw, "", 1, ""); w1 = (w1[.,1]/1000000)~w1[.,2:cols(w1)]; nw = miss(w1,9999); print "Number of Companies is" cp; ro = {1,1783}; co = {1,2}; nrd = xlsMakeRange(ro,co); us1 = xlsreadm(fnus,nrd,3,""); us1 = (us1[.,1]/1000000)~us1[.,2]; nus = miss(us1,9999); jj = 1; do until jj > cp; nx = np[.,jj]~nus[.,2]; rf = 7*nw[.,6]; ndat = packr(lag1(nw[.,1])~lag1(rf)~ln(nx./lag1(nx))~newcount[.,jj]); datenew = ndat[.,1]; if rows(nx) > 3; @ ndat = packr(lag1(np[.,1])~nc[.,jj-1]~lag1(rf)~ln(nx./lag1(nx))); ndat = nx[.,1]~ln(nx[.,2]./lag1(nx[.,2]))~nx[.,3]~ln(nx[.,4]./lag1(nx[.,4])); ndat = packr(ndat); @ st0 = "Company Number = " ; print st0 jj; st1 = "No of observations = " ; print st1 rows(ndat); bigt=rows(ndat); @set effective sample size@ cn = xlsMakeRange(1,jj); kappa = 1; do until kappa > 4; retn = xlswrite(bigt,nout10,cn,kappa,9999.99); retn = xlswrite(bigt,nout5,cn,kappa,9999.99); retn = xlswrite(bigt,nout2p5,cn,kappa,9999.99); retn = xlswrite(bigt,nout1,cn,kappa,9999.99); kappa = kappa + 1; endo; if bigt > 60; @run only if 60 data points@ y=ndat[.,3]-ndat[.,2]; @set up the data, y is the dependent variable z is the matrix of regressors (bigt,q) whose coefficients are allowed to change, x is a (bigt,p) matrix of regressors with coefficients fixed across regimes. Note: initialize x to something, say 0, even if p = 0.@ z=ones(bigt,1)~ndat[.,5]~(ndat[.,4]-ndat[.,2]); x=0; q=3; @number of regressors z@ p=0; @number of regressors x@ m=3; @maximum number of structural changes allowed@ eps1=.15; @Value of the trimming (in percentage) for the construction and critical values of the supF ype tests (used in the supF test, the Dmax, the supF(l+1|l) and the sequential procedure). If these test are used, h below should be set at int(eps1*bigt). But if the tests are not required, estimation can be done with an arbitrary h. There are five options: eps1 = .05, .10, .15, .20 or .25. For each option, the maximal value of m above is: 10 for eps1 = .05; 8 for eps1 = .10, 5 for eps1 = .15, 3 for eps1 = .20 and 2 for eps1 = .25.@ h=int(eps1*bigt); @minimal length of a segment (h >= q). Note: If robust=1, h should be set at a larger value.@ /* the following are options if p > 0. ----------------------------------- */ fixb=0; @set to 1 if use fixed initial values for beta@ betaini=0; @if fixb=1, load the initial value of beta.@ maxi=20; @maximum number of iterations for the nonlinear procedure to obtain global minimizers.@ printd=0; @set to 1 if want the output from the iterations to be printed.@ eps=0.0001; @criterion for the convergence.@ /*--------------------------------- */ robust=0; @set to 1 if want to allow for heterogeneity and autocorrelation the in residuals, 0 otherwise. The method used is Andrews(1991) automatic bandwidth with AR(1) approximation and the quadratic quernel. Note: Do not set to 1 if lagged dependent variables are included as regressors.@ prewhit=1; @set to 1 if want to apply AR(1) prewhitening prior to estimating the long run covariance matrix@ hetdat=1; @Option for the construction of the F-tests. Set to 1 if want to allow different moment matrices of the regressors accross segments. If hetdat = 0, the same moment matrices are assumed for each segment and estimated from the full sample. It is recommended to set hetdat=1. If p > 0 set hetdat = 1.@ hetvar=0; @Option for the construction of the F-tests. Set to 1 if want to allow for the variance of the residuals to be different across segments. If hetvar=0, the variance of the residuals is assumed constant across segments and constructed from the full sample. This option is not available when robust = 1.@ hetomega=1; @Used in the construction of the confidence intervals for the break dates. If hetomega=0, the long run covariance matrix of zu is assumed identical accross segments (the variance of the errors u if robust = 0).@ hetq=1; @Used in the construction of the confidence intervals for the break dates. If hetq=0, the moment matrix of the data is assumed identical accross segments.@ doglobal=1; @set to 1 if want to call the procedure to obtain global minimizers.@ /* dotest=0; @set to 1 if want to construct the sup F, UDmax and WDmax tests. doglobal must be set to 1 to run this procedure.@ */ dospflp1=1; @set to 1 if want to construct the sup(l+1|l) tests where under the null the l breaks are obtained using global minimizers. doglobal must be set to 1 to run this procedure.@ doorder=1; @set to 1 if want to call the procedure that selects the number of breaks using information criteria. doglobal must be set to 1 to run this procedure.@ dosequa=1; @set to 1 if want to estimate the breaks sequentially and estimate the number of breaks using the supF(l+1|l) test.@ dorepart=1; @set to 1 if want to modify the break dates obtained from the sequential method using the repartition method of Bai (1995), Estimating breaks one at a time. This is needed for the confidence intervals obtained with estim below to be valid.@ /* estimbic=0; @set to 1 if want to estimate the model with the number of breaks selected by BIC.@ */ /* estimlwz=0; @set to 1 if want to estimate the model with the number of breaks selected by LWZ.@ */ estimseq=1; @set to 1 if want to estimate the model with the number of breaks selected using the sequential procedure.@ estimrep=0; @set to 1 if want to esimate the model with the breaks selected using the repartition method.@ /* estimfix=0; @set to 1 if want to estimate the model with a prespecified number of breaks equal to fixn set below.@ */ fixn=0; call pbreak(bigt,y,z,q,m,h,eps1,robust,prewhit,hetomega, hetq,doglobal,dospflp1,doorder,dosequa,dorepart, estimseq,estimrep,fixb,x,q,eps,maxi,fixb,betaini,printd,hetdat,hetvar,fixn,datenew,jj, nout10,nout5,nout2p5,nout1); endif; endif; jj = jj + 1; endo; #include c:\gauss6\m-break\nallbeta.src @set the path to where you store the file brcode.src@ end;