* * * * Week 9 * * *Load data, file -> import -> ASCII data created by spreadsheet * *insheet using FTSE100.csv * *Processing data rename v1 price generate time = _n ** flip around dimension gen time2 = 6978 - time drop time rename time2 time tsset time *Generate returns generate returns = price/L.price -1 generate lnreturns = ln(price/L.price) *Graph returns twoway (line returns time, yaxis(2)) (line lnreturns time, yaxis(2)) twoway (line price time) *Histograms with densities twoway (histogram price) (kdensity price) twoway (histogram lnreturns) (kdensity lnreturns) *install module for cdfplot ssc install cdfplot cdfplot lnreturns,normal *Manual generation of normal distribution su lnreturns gen normalLogReturns= 0.0002308+ 0.0113213* invnorm(uniform()) su normalLogReturns *Plot to see difference in densities twoway(kdensity normalLogReturns ) (kdensity lnreturns ) *Autocorrelation function ac lnreturns, recast(connected) *Checking absolute returns gen abslnreturns = abs(lnreturns) ac abslnreturns, recast(connected) *Skewness test for normality *high joing prob, do not reject -> normally distributed sktest lnreturns * * * Week 10 * * * *Load data, file -> import -> ASCII data created by spreadsheet * *insheet FTSE_BARC.csv.csv * rename v1 time rename v2 ftse100 rename v3 barc tsset time *Generate returns generate lrftse100 = log(ftse100 /L.ftse100) generate rftse100 = ftse100 /L.ftse100 -1 generate lrbarc = log(barc /L.barc) generate rbarc = barc /L.barc -1 *Checking graphs twoway (line ftse100 time) (line barc time, yaxis(2)) twoway (line lrbarc time) (line lrftse100 time, yaxis(2)) *Spurious regression example drawnorm error1 error2, n(1568) seed(1000) gen tempY = 0.05 + error1 gen tempX = 0.02 + error2 replace tempY = 0.05 + error1 + L.tempY in 2/1568 replace tempX = 0.02 + error2 + L.tempX in 2/1568 drop error1 error2 *False results, serial correlation invalidates results reg tempY tempX *Difference is stationary, results are good gen tempDiffY = (tempY - L.tempY) gen tempDiffX = (tempX - L.tempX) reg tempDiffY tempDiffX *Look for significantly negative values to reject Ho of unit root, nonstationarity. *Dickey–Fuller test for unit root. Determining the length of lag dfgls rbarc, ers dfgls rftse100, ers reg rbarc rftse100 *Breusch–Godfrey test for serial correlation. Look for high prob to state no serial correlation. * Formal definition: insufficient evidence to reject h0 of no serial correlation *If lag values included, lags is not 0 estat bgodfrey, lags(0) *Breusch–Pagan test for heteroskedasticity. Ho: homoskedasticity (High prob -> constant variance) estat hettest *Non-linear model, help arch - for more details *ARCH effects, testing if there is arch 1 effect estat archlm, lags(1) *check t values of added lags, if significant add more arch rbarc rftse100,arch(1/1) *Information criteria - to evaluate if the fit is better, smaller values indicate a better fit estat ic arch rbarc rftse100,arch(1/2) estat ic *Using robust against heteroskedasticity variance-covariance matrix reg rbarc rftse100,robust *Jarque - Berra test for normality. In this case testing the distribution of the error term. predict res, residuals histogram res, normal bin(50) su res, detail *Manual implementation, formula as below. *JarBer = (n/6)*((skew^2)+1/4(Kurt-3)^3) *Chi^2 distribution with 2 df to compare against critical value. *Ho residuals are normally distributed *Ramsey RESET test for misspecification. Testing against higher polynomial transformations. High F values -> reject Ho of correctly specified model ovtest *Can not reject Ho of CAPM being true test _cons == 0