OPTIONS PS = 60; OPTIONS LS = 70; options center; /* Regression of Emory data with present and future beliefs as a dependent variable and markettrend and periodtrend as the independent variables, with individual fixed effects. Note that belief(t), belief(t+1) and belief (t+k, k>1) have different forms; */ * You will need to change the libname blow to reflect the directory where computations are done; libname q 'C:\Ernan\A-D\bubbles\Belief_project\Yaron\FilesForAER'; /* The file being created below and then read for computation q.beliefdat includes Asset Session Subject Period b1-b15 Entire Belief Vector for each period belief0-belief14, beliefk denotes the belief for time t+k N1Price-N14Price, NkPrice denotes the eqm price at time t+k R1N1Price-R1N14Price, R1NkPrice denotes the eqm price at time t+k for the previous asset */ * Creating q. beliefdat; %MACRO PLAYLOOP; %DO I=1 %TO 15; if period=&I then belief=b&I; if period=&I then belief0=b&I; if period=&I and &I<15 then belief1=b%eval(&I + 1); if period=&I and &I<14 then belief2=b%eval(&I + 2); if period=&I and &I<13 then belief3=b%eval(&I + 3); if period=&I and period<12 then belief4=b%eval(&I + 4); if period=&I and period<11 then belief5=b%eval(&I + 5); if period=&I and period<10 then belief6=b%eval(&I + 6); if period=&I and period<9 then belief7=b%eval(&I + 7); if period=&I and period<8 then belief8=b%eval(&I + 8); if period=&I and period<7 then belief9=b%eval(&I + 9); if period=&I and period<6 then belief10=b%eval(&I + 10); if period=&I and &I<5 then belief11=b%eval(&I + 11); if period=&I and &I<4 then belief12=b%eval(&I + 12); if period=&I and &I<3 then belief13=b%eval(&I + 13); if period=&I and &I=1 then belief14=b%eval(15); if period=15 then belief1=.; if period>=14 then belief2=.; if period>=13 then belief3=.; if period>=12 then belief4=.; if period>=11 then belief5=.; if period>=10 then belief6=.; if period=9 then belief7=.; if period>=8 then belief8=.; if period>=7 then belief9=.; if period>=6 then belief10=.; if period>=5 then belief11=.; if period>=4 then belief12=.; if period>=3 then belief13=.; if period>=2 then belief14=.; %END; %MEND PLAYLOOP; PROC IMPORT OUT= WORK.Actions DATAFILE= "C:\Ernan\A-D\bubbles\Belief_project\Yaron\FilesForAER\TraderFull.xls" DBMS=EXCEL REPLACE; SHEET="Data$"; GETNAMES=YES; MIXED=NO; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; data process; set actions; period = round; asset = market; * Giving subjects different id numbers so that we can do fixed effects later; if session=1 then subject1=subject; if session=2 then subject1=subject+9; if session=3 then subject1=subject+18; if session=4 then subject1=subject+27; if session=5 then subject1=subject+36; if session=6 then subject1=subject+45; subject=subject1; run; proc sort data=process; by session Asset Subject descending Period; run; data process; set process; Price=EqmPrice; N0Price= Price; NPrice=Lag(EqmPrice); N1Price = NPrice; N2Price=Lag(NPrice); N3Price=Lag(N2Price); N4Price=Lag(N3Price); N5Price=Lag(N4Price); N6Price=Lag(N5Price); N7Price=Lag(N6Price); N8Price=Lag(N7Price); N9Price=Lag(N8Price); N10Price=Lag(N9Price); N11Price=Lag(N10Price); N12Price=Lag(N11Price); N13Price=Lag(N12Price); N14Price=Lag(N13Price); if period>14 then N1Price = .; if period>13 then N2Price=.; if period>12 then N3Price=.; if period>11 then N4Price=.; if period>10 then N5Price=.; if period>9 then N6Price=.; if period>8 then N7Price=.; if period>7 then N8Price=.; if period>6 then N9Price=.; if period>5 then N10Price=.; if period>4 then N11Price=.; if period>3 then N12Price=.; if period>2 then N13Price=.; if period>1 then N14Price=.; run; proc sort data=process; by session Asset Subject Period; run; data process; set process; Price=EqmPrice; LPrice=Lag(EqmPrice); L2Price=Lag(LPrice); %PLAYLOOP FV = (16-Period)*12; run; proc sort data=process; by session Subject Period Asset; run; * R1N1Price-R1N14Price, R1NkPrice denotes the eqm price at time t+k for the previous asset; data process; set process; R1Price=Lag(Price); R1LPrice=Lag(LPrice); R1L2Price=Lag(L2Price); R1NPrice=Lag(NPrice); R1N1price=R1NPrice; R1N2Price=Lag(N2Price); R1N3Price=Lag(N3Price); R1N4Price=Lag(N4Price); R1N5Price=Lag(N5Price); R1N6Price=Lag(N6Price); R1N7Price=Lag(N7Price); R1N8Price=Lag(N8Price); R1N9Price=Lag(N9Price); R1N10Price=Lag(N10Price); R1N11Price=Lag(N11Price); R1N12Price=Lag(N12Price); R1N13Price=Lag(N13Price); R1N14Price=Lag(N14Price); belief0=belief; drop b16-b28; run; /* The macro Future computes mkttrend and period trend for beliefs in t+k, k>=1; For k=0, we have Future0 computed somewhere below */ %MACRO FUTURE; %DO I=1 %TO 14; data Future&I; set process; belief0=belief; R1N0price = R1price; fbelief=belief&I; future=&I; per = period+future; /* For the first asset, we fix mkttrend at 0 */ if asset=1 then mkttrend = 0; if asset>=2 then do; term1=R1N&I.price; term2=R1N%eval(&I - 1)Price; ratio=(term1-term2)/term2; mkttrend = belief%eval(&I - 1) + belief%eval(&I - 1)*ratio; end; Delta2=belief%eval(&I - 1)*(belief%eval(&I - 1)-belief%eval(&I - 2))/belief%eval(&I - 2); /* Periodtrend is computed a bit differently for beliefs at time t+1 (k=1), since the actual previous price is used */ if &I=1 then Delta2=belief*(belief-LPrice)/LPrice; if period>0 then periodtrend = belief%eval(&I - 1) + Delta2; else periodtrend=0; if period>=(16-&I.) then delete; if asset=1 then ratio = 0; run; %END; %MEND FUTURE; proc means; var eqmprice; class period; run; /* This data step computes mkttrend and period trend for beliefs at time t (k=0); For beliefs in t+k, k>=1, we have data sets Future1-Future14 which are computed somewhere above*/ data Future0; set process; fbelief=belief; ratio=(R1price-R1LPrice)/R1LPrice; mkttrend = LPRICE + LPRICE*(R1price-R1LPrice)/R1LPrice; if asset=1 then mkttrend=0; factor1 = (Lprice-L2Price)/L2Price; if period>2 then Delta2=LPrice*factor1; if period>2 then periodtrend = Lprice + Delta2; else trend2=0; if asset=1 then ratio=0; future=0; per = period; run; /* This command calls the macro Future which computes mkttrend and periodtrend for t+k, k>=1 */ %Future /* Here we create one huge data set with one line for each belief stated. Whereas before our data set consisted of one line per period per subject, we now have a line (observation) for each belief in the subject's belief vector. So the line corresponding to period 3 would be now 12 different lines with beliefs for periods 3-14 taking a line each. This gives us 4823 observations per asset (except asset 4 which has 4004 obs). */ data future; set future0 future1 future2 future3 future4 future5 future6 future7 future8 future9 future10 future11 future12 future13 future14; /* Compute fundamental value below */ fFV = (16-per)*12; keep session asset period subject fbelief subject fFV mkttrend periodtrend term1 term2 ratio R1N14price future per; if ratio=. then delete; if (period=1 and (future=0 or future=1)) or (period=2 and future=0) then delete; run; proc sort data=future; by asset period subject; run; /* This is the regression of belief on fixed effect, mkttend and periodtrend */ proc glm data=Future; class subject; model fbelief = subject mkttrend periodtrend /noint solution; by Asset; run; /* This is the regression of belief on fixed effect and fundamental value */ proc glm data=Future; class subject; model fbelief = subject fFV /noint solution; by Asset; run;