* this data set has daily closing prices of the * Dow Jones Industrial Average from * January 1950 through January 2007 * load the data use djia_daily_data * open a log file log using djia_random_walk.log, replace * get descriptive information about the data desc * notice the variable time. the first day is * 1, the second day 2, etc. * define the data as time series * the variable time is the index tsset time ********************************* ********************************* * check EMH in daily returns * will take the 1st difference between two * adjacent trading days ********************************* ********************************* * take the ln of the daily closing price gen ln_close=ln(close) * get the 1st difference gen ln_close1=ln_close[_n-1] * test for random walk * run a regression of change ln(closing price) * on one period lag reg ln_close ln_close1 test ln_close1==1 * run a regression allowing for a time trend reg ln_close ln_close1 time test ln_close1==1 * generate 1st difference in returns gen dln_close=ln_close-ln_close1 * now get the lag of the 1st difference gen dln_close1=dln_close[_n-1] * run a regression of the 1st difference on its lag reg dln_close dln_close1 * identify some stock anomalies * generate month and day effects gen dmonth2=month==2 gen dmonth3=month==3 gen dmonth4=month==4 gen dmonth5=month==5 gen dmonth6=month==6 gen dmonth7=month==7 gen dmonth8=month==8 gen dmonth9=month==9 gen dmonth10=month==10 gen dmonth11=month==11 gen dmonth12=month==12 gen tue=weekday==3 gen wed=weekday==4 gen thur=weekday==5 gen fri=weekday==6 reg dln_close time dmonth* tue wed thur fri test dmonth2 dmonth3 dmonth4 dmonth5 dmonth6 dmonth7 dmonth8 dmonth9 dmonth10 dmonth11 dmonth12 test tue wed thur fri * get means of delta daily closing price sum dln_close ********************************* ********************************* * check EMH in 2-day returns * will take the 1st difference between two * lagged days ********************************* ********************************* clear use djia_daily_data * take the ln of the daily closing price gen ln_close=ln(close) * get the 2nd difference gen ln_close2=ln_close[_n-2] * generate 1st difference * in two day returns gen dln_close=ln_close-ln_close2 * now get the lag of the 1st difference gen dln_close2=dln_close[_n-2] * now delete 1/2 of the obs gen eventime=int(time/2)==time/2 drop if eventime==0 * test for random walk * run a regression of change ln(closing price) * on 2 period period lag reg ln_close ln_close2 test ln_close2==1 * run a regression allowing for a time trend reg ln_close ln_close2 time test ln_close2==1 * run a regression of the 2nd difference on its lag reg dln_close dln_close2 ********************************* ********************************* * check EMH in weekly returns * will take the returns between the last trading * days of two adjacent weeks ********************************* ********************************* clear use djia_daily_data gen date1=mdy(month,day,year) gen date2=date1+3652 gen weekno=int((date2-1)/7)+1 keep day month year time date2 weekno close sort weekno egen lastdayofweek=max(date2), by(weekno) keep if lastdayofweek==date2 tsset time * take the ln of the daily closing price gen ln_close=ln(close) * get the 1st difference gen ln_close1=ln_close[_n-1] * test for random walk * run a regression of change ln(closing price) * on one period lag reg ln_close ln_close1 test ln_close1==1 * run a regression allowing for a time trend reg ln_close ln_close1 time test ln_close1==1 * generate 1st difference in returns gen dln_close=ln_close-ln_close1 * now get the lag of the 1st difference gen dln_close1=dln_close[_n-1] * run a regression of the 1st difference on its lag reg dln_close dln_close1 ********************************* ********************************* * check EMH in monthly returns * will take the returns between the last trading * days of two adjacent weeks ********************************* ********************************* clear use djia_daily_data keep day month year time close sort year month egen lastdayofmonth=max(time), by(year month) keep if lastdayofmonth==time tsset time * take the ln of the daily closing price gen ln_close=ln(close) * get the 1st difference gen ln_close1=ln_close[_n-1] * test for random walk * run a regression of change ln(closing price) * on one period lag reg ln_close ln_close1 test ln_close1==1 * run a regression allowing for a time trend reg ln_close ln_close1 time test ln_close1==1 * generate 1st difference in returns gen dln_close=ln_close-ln_close1 * now get the lag of the 1st difference gen dln_close1=dln_close[_n-1] * run a regression of the 1st difference on its lag reg dln_close dln_close1