/***************************************************************************/ /* */ /* Title: OBSFACT.GPG */ /* */ /* Written: John H. Cochrane */ /* by: University of Chicago Graduate School of Business */ /* 1101 E. 58th Street, Rosenwald 2xx */ /* Chicago, Ill 60637 */ /* ph#: (312) 702-3059 */ /* e-mail: fac_jhc@gsbacd.uchicago.edu */ /* */ /*Modified: Caleb C. Wong */ /* by: University of Chicago Department of Economics */ /* 1126 East 59th St. */ /* Chicago, Ill 60637 */ /* ph#: (312) 702-8254 */ /* e-mail: wongcc@sam.spc.uchicago.edu */ /* */ /* Purpose: Main program for doing gmm with linear factors, i.e. capm & crr*/ /* Sets up the proper 'switches' and datasets and passes them to */ /* doitc.g for estimation of factor premiums. */ /* */ /* */ /* Data: Quarterly averaged returns created by redodat.gpg and GAUSS */ /* formatted (indicated by .fmt extension) */ /* */ /* */ /* */ /***************************************************************************/ /* ----------------------------------- */ /* Part I. (1) GAUSS library calls */ /* (2) datapath declaration */ /* (3) clear globals */ /* ----------------------------------- */ library gmm; dpath(0); /* 0: John's datapath */ /* 1: Caleb's datapath */ clearg jt; /* ------------------------------------------------ */ /* Part II: how it runs switches */ /* NOTE: some are overridden by bigrun */ /* ------------------------------------------------ */ nwlags = 4; /* # of newey west lags */ w_matrix = 0; /* choices 0: HJ Spec error w/ S and ret mom mat*/ /* 1: HJ Spec error w/ S matrix only */ ergrf = 0|0|0; /* 3x1 vector: (1,1)=0: no graph of 1st stage */ /* 1: graph 1st stage estim. */ /* E(r) (2,1)=0: no graph of 2nd stage */ /* vs. 1: graph 2nd stage estim. */ /* pred E(r) (3,1)=0: no graph seen on screen */ /* 1: graph seen on screen */ errbars = 0; /* choices: 0: no std error bars on graph */ /* 1: insert std error bars on graph */ grphcode = 0; /* choices: 0: no E(r) v. pred E(r) graphs comb*/ /* 1: combine E(r) v. pred E(r) graphs*/ /* 3: graph nonscaled w. diff. symbol */ /* NOTE: IF SET TO 1, GRAPH FROM THE 1ST RUN WILL BE */ /* COMPARED WITH THE FOLLOWING RUN.USE ONLY WITH BIGRUN */ asstcode = 1; /* choices: 1: 10 deciles */ /* 2: individual stock returns */ /* 3: French deciles */ /* 4: French vintiles */ retcode = 0; /* choices: 0: chosen assets only */ /* 1: chosen assets + market return */ factcode = 2; /* choices: 1: vw market */ /* 2: chen roll ross factors */ instcode = 3 ; /* choices: 1: use unconditional moments only */ /* 2: const, term, default */ /* 3: const, term, default, d/p */ xtrcode = 1; /* choices: 1: no extra factors */ /* 2: market return */ /* 3: chen roll ross factors */ cfact = 1; /* choices: 0: do not include scaled factors */ /* 1: include scaled factors */ momcode = 1; /* choices: 0: do not include scaled returns */ /* 1: do include scaled returns */ outagn = 1; /* 0: output reset; */ /* 1: output on; */ /* 2: output to trash.out (debug w/o ruining gmm.out) */ itercode = 0; /* 0: only two-stage GMM 1: iterated GMM */ bigrun = 1; /* ignore above, runs through all current options */ outwidth 80; /* set output width to 80 columns */ /* -------------------------- */ /* Part III. open output file */ /* -------------------------- */ if outagn == 1; output file=obsfact.out on; endif; if outagn == 0; output file=obsfact.out reset; endif; if outagn == 2; output file=trash.out reset; endif; /* ------------------ */ /* Part IV. load data */ /* ------------------ */ load avdecret,avvwret,avewret,avustret@,aindstrt@; @load avvw20y,avvw10y;@ load GPI82, gin82, gis82,gipd82,gir82,gcd82; load qterm,qdef,qvwdp,qewdp; load MP,DEI,UI,UPR,UTS; /* ------------------------------------------ */ /* Part V. Single GMM Run or Multiple GMM Run */ /* ------------------------------------------ */ /* A. Single GMM Run (bigrun=0) */ if not bigrun; gosub runit; endif; /* B. Multiple GMM Run (bigrun = 1) */ /* WARNING: MULTI-RUNS ARE ORDERED. ANY OMMISSION/RESHUFFLING OF THE RUNS */ /* NEED TO BE ACCOMPANIED WITH APPROPRIATE CHANGES AMONG THE "SWITCHES" */ if bigrun; /* common setup */ itercode = 0; nwlags = 4; ergrf = 0|0|0; makgraf = 1; if makgraf; ergrf = 1|0|1; endif; retcode = 1; factcode = 1; instcode = 1 ; xtrcode = 1; momcode = 0; cfact = 0; /* 1. CAPM: Using NYSE-vw as factor to price returns */ "CAPM"; grphcode = 0; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf vw.prt; endif; if asstcode == 2; dos copy graphic.tkf vw.ind; endif; if asstcode == 4; dos copy graphic.tkf vw.vin; endif; endif; "CONDITIONAL CAPM"; grphcode = 1; instcode = 3; momcode = 1; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf vwcm.prt; endif; if asstcode == 2; dos copy graphic.tkf vwcm.ind; endif; if asstcode == 4; dos copy graphic.tkf vwcm.vin; endif; endif; /* "SCALED UNCONDITIONAL CAPM"; */ grphcode = 0; instcode = 3; cfact = 1; momcode = 0; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf vwsf.prt; endif; if asstcode == 2; dos copy graphic.tkf vwsf.ind; endif; if asstcode == 4; dos copy graphic.tkf vwsf.vin; endif; endif; "SCALED CONDITIONAL CAPM"; grphcode = 1; cfact = 1; momcode = 1; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf vwsfcm.prt; endif; if asstcode == 2; dos copy graphic.tkf vwsfcm.ind; endif; if asstcode == 4; dos copy graphic.tkf vwsfcm.vin; endif; endif; /* 2. CRR: Using Chen, Roll, & Ross factors to price returns */ "CRR"; grphcode = 0; instcode = 1; factcode = 2; /* CRR */ retcode = 0; cfact = 0; momcode = 0; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf crr.prt; endif; if asstcode == 2; dos copy graphic.tkf crr.ind; endif; if asstcode == 4; dos copy graphic.tkf crr.vin; endif; endif; "CONDITIONAL CRR"; grphcode = 1; instcode = 3; momcode = 1; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf crrcm.prt; endif; if asstcode == 2; dos copy graphic.tkf crrcm.ind; endif; if asstcode == 4; dos copy graphic.tkf crrcm.vin; endif; endif; /* "SCALED CRR"; grphcode = 0; cfact = 1; /* scaled CRR */ momcode = 0; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf crrsf.prt; endif; if asstcode == 2; dos copy graphic.tkf crrsf.ind; endif; if asstcode == 4; dos copy graphic.tkf crrsf.vin; endif; endif; */ "SCALED CONDITIONAL CRR"; _preder = 0;_erx = 0; grphcode = 3; cfact = 1; /* scaled CRR */ momcode = 1; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf crrsfcm.prt; endif; if asstcode == 2; dos copy graphic.tkf crrsfcm.ind; endif; if asstcode == 4; dos copy graphic.tkf crrsfcm.vin; endif; endif; /* 3. CRR vs. CAPM: Comparing CRR factors and capm index as candidate */ /* factors to price returns */ /* "CRR VS. MARKET"; grphcode = 0; retcode = 1; cfact = 0; momcode = 0; xtrcode = 2; instcode = 1; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf crvw.prt; endif; if asstcode == 2; dos copy graphic.tkf crvw.ind; endif; if asstcode == 4; dos copy graphic.tkf crvw.vin; endif; endif; "CONDITIONAL CRR VS. MARKET"; grphcode = 1; instcode = 3; momcode = 1; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf crvwcm.prt; endif; if asstcode == 2; dos copy graphic.tkf crvwcm.ind; endif; if asstcode == 4; dos copy graphic.tkf crvwcm.vin; endif; endif; "SCALED CRR VS. MARKET"; grphcode = 0; instcode = 3; cfact = 1; /* scaled CRR vs. market */ momcode = 0; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf crvwsf.prt; endif; if asstcode == 2; dos copy graphic.tkf crvwsf.ind; endif; if asstcode == 4; dos copy graphic.tkf crvwsf.vin; endif; endif; "CONDITIONAL SCALED CRR VS. MARKET"; _preder = 0; _erx = 0; grphcode = 1; cfact = 1; /* scaled CRR vs. market */ momcode = 1; gosub runit; if (makgraf and (jt /= 0)); if asstcode == 1; dos copy graphic.tkf crvwsfcm.prt; endif; if asstcode == 2; dos copy graphic.tkf crvwsfcm.ind; endif; if asstcode == 4; dos copy graphic.tkf crvwsfcm.vin; endif; endif; */ endif; output off; end; /* ---------------------------- */ /* Part VI: Subroutines */ /* ---------------------------- */ /* ------------------------------------------------------------------- */ /* A. RUNIT: sets up the appropriate dataset and calls obsfact proc to */ /* perform the gmm estimation */ /* ------------------------------------------------------------------- */ runit: "-----------------------------------------------------------------------------"; /* ----------------------------------------------------- */ /* 1. set up assets, factors, instruments, extra factors */ /* ----------------------------------------------------- */ if grphcode == 0; _preder = 0; _erx = 0; endif; if asstcode == 1; rassetx = avdecret - avustret; endif; /* if asstcode == 2; rassetx = aindstrt - avustret; endif; if asstcode == 3; rassetx = avvw10y - avustret; endif; if asstcode == 4; rassetx = avvw20y - avustret; endif; */ if retcode; rassetx = rassetx~(avvwret-avustret); endif; if factcode == 1; factrs = avvwret; let factlbl = "VW"; endif; if factcode == 2; factrs = MP~DEI~UI~UPR~UTS; let factlbl = "MP" "DEI" "UI" "UPR" "UTS"; endif; if instcode == 1; inst = 0; "no instruments"; endif; if instcode == 2; inst = qdef~qterm; inst = 1 + .2*(inst-meanc(inst)')./(stdc(inst)'); "instruments = const, default spread, term prem, rescaled to mean 1 sd .2"; endif; if instcode == 3; inst = qdef@~qterm@~qewdp; inst = 1 + .2*(inst-meanc(inst)')./(stdc(inst)'); "instruments = const, default spread, @term prem,@ ewd/p, mean 1 sd .2"; endif; if xtrcode == 1; xtrfact = 0; let xtrlbl = " "; " no extra factors"; endif; if xtrcode == 2; xtrfact = avvwret; let xtrlbl = "VW"; "extra factor = vw return"; endif; if xtrcode == 3; xtrfact = MP~DEI~UI~UPR~UTS; let xtrlbl = "MP" "DEI" "UI" "UPR" "UTS"; "extra factor = CRR"; endif; if cfact; "scaled factors included"; else; "non-scaled factors"; endif; if momcode ; "using scaled returns"; else; "using non-scaled returns"; endif; if itercode == 1; " using iterated GMM" ; else; "second stage GMM only "; endif; /* ----------------------- */ /* 2. massage data lengths */ /* ----------------------- */ if instcode /= 1; /* need twice lagged inst: */ inst = inst[1:rows(inst)-2,.]; /* inst from 47:1 to 90:2, */ rassetx = rassetx[2:rows(rassetx),.]; /* others from 47:3 to 90:4 */ factrs = factrs[2:rows(factrs),.]; if xtrcode /= 1; xtrfact = xtrfact[2:rows(xtrfact),.]; endif; endif; /* --------------------------------- */ /* 3. estimate observed factor model */ /* --------------------------------- */ prnt = 1; win = 0; {jt,dof,neg_m,_preder,_erx,lgt} = obsfact(rassetx,factrs,xtrfact, inst,nwlags,ergrf,prnt,itercode,factlbl,xtrlbl, cfact,momcode,errbars,_preder,_erx,grphcode, w_matrix); "";"percent of m's that are negative (all stage estimates included)"; neg_m*100; return;