---------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  D:\Data\share\boehmke2009jop\montecarlo\boehmke2009jop-montecarlo.log
  log type:  text
 opened on:   1 Dec 2011, 10:44:02

. /*      ****************************************************************        */
> /*      File Name:      boehmke2009jop-montecarlo.do                            */
> /*      Date:           May 03, 2011                                            */
> /*      Author:         Frederick J. Boehmke                                    */
> /*      Purpose:        This file combines the Monte Carlo results to create    */
> /*                      Table 1 and Figure 1 comparing the unconditional and    */
> /*                      conditional dyadic EHA models. It assumes the Monte     */
> /*                      Carlo trials have been run in the folder simulated/.    */
> /*      Input File:     statecodes.dta                                          */
> /*      Output File:    boehmke2009jop-montecarlo.log,                          */
> /*                      boehmke2009jop-montecarlo.dta,                          */
> /*                      boehmke2009jop-montecarlo-collapsed.dta,                */
> /*                      boehmke2009jop-montecarlo-fig01.gph,                    */
> /*                      boehmke2009jop-montecarlo-table01.csv,                  */
> /*      Version:        Stata 9 or above.                                       */
> /*      ****************************************************************        */
> 
> 
>         /****************************************/
>         /* Combine the data from the MCs.       */
>         /****************************************/
> 
>         
>                 /* First, the data when the independent variables are simulated. */
>         
> clear;

. save boehmke2009jop-montecarlo, replace emptyok;
(note: dataset contains 0 observations)
file boehmke2009jop-montecarlo.dta saved

. forvalues num=1/12 {;
  2.   if `num' < 10 {;
  3.         use simulated/montecarlo-dyads0`num'-sims.dta, clear;
  4.         };
  5.   else if `num' >= 10 {;
  6.         use simulated/montecarlo-dyads`num'-sims.dta, clear;
  7.         };
  8.   generat sim = `num';
  9.   append using boehmke2009jop-montecarlo;
 10.   save boehmke2009jop-montecarlo, replace;
 11.   };
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved

.                 /* Second, with the real world values of the independent variables. */  
> 
> forvalues num=1/12 {;
  2.   if `num' < 10 {;
  3.         use real/montecarlo-dyads0`num'-sims.dta, clear;
  4.                 };
  5.   else if `num' >= 10 {;
  6.         use real/montecarlo-dyads`num'-sims.dta, clear;
  7.         };
  8.   generat sim = `num';
  9.     generat corrparam = 0;
 10.   append using boehmke2009jop-montecarlo;
 11.   save boehmke2009jop-montecarlo, replace;
 12.   };
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved
(simulate: emulate)
file boehmke2009jop-montecarlo.dta saved

.   recode sig_* (-1=1);
(sig_rpcpinc01: 113 changes made)
(sig_rpcpinc02: 1379 changes made)
(sig_rpcpinc_jnt: 931 changes made)

. foreach var of varlist b_* {;
  2.   generat sd_`var' = `var';
  3.   };
(30000 missing values generated)
(36000 missing values generated)

. foreach var of varlist se_* {;
  2.   replace `var' = `var'^2;
  3.   };
(72000 real changes made)
(42000 real changes made)
(36000 real changes made)

.   save boehmke2009jop-montecarlo, replace;
file boehmke2009jop-montecarlo.dta saved

.         /************************************************/
>         /* Arrange the data to generate Table 1.        */
>         /************************************************/
>         
>   
> collapse (mean) b_* se_* sig_* numobs (sd) sd_*, by(sim corrparam);

.   foreach var of varlist se_* {;
  2.         replace `var' = sqrt(`var');
  3.         };
(72 real changes made)
(42 real changes made)
(36 real changes made)

.   order b* sd* se* sig*;

.   order sim corrparam *rpcpinc01* *rpcpinc02* *rpcpinc_jnt*;

.   keep if sim == 1 | sim == 2 | sim == 3 | sim == 5 | sim == 10 | sim == 11 | sim == 8;
(30 observations deleted)

.                 /* Put them in the same order as in the table. */
>   
>         replace sim = 13 if sim == 8;
(6 real changes made)

.     gsort +sim -corrparam;

.     order sim corrparam numobs;

.     save boehmke2009jop-montecarlo-collapsed, replace;
file boehmke2009jop-montecarlo-collapsed.dta saved

.         outsheet using boehmke2009jop-montecarlo-table01.csv, comma replace;

.         /****************************************/
>         /* Generate plots to create Figure 1.   */
>         /****************************************/
>         
>         
> use boehmke2009jop-montecarlo.dta, clear;
(simulate: emulate)

.   keep sim corrparam b_rpcpinc01 b_rpcpinc02 b_rpcpinc_jnt;

.         bysort corrparam sim: gen i=_n;

.     reshape wide b_rpcpinc01 b_rpcpinc02 b_rpcpinc_jnt, i(i sim) j(corrparam);
(note: j = 0 1 2 3 5 10)

Data                               long   ->   wide
-----------------------------------------------------------------------------
Number of obs.                    72000   ->   12000
Number of variables                   6   ->      20
j variable (6 values)         corrparam   ->   (dropped)
xij variables:
                            b_rpcpinc01   ->   b_rpcpinc010 b_rpcpinc011 ... b_rpcpinc0110
                            b_rpcpinc02   ->   b_rpcpinc020 b_rpcpinc021 ... b_rpcpinc0210
                          b_rpcpinc_jnt   ->   b_rpcpinc_jnt0 b_rpcpinc_jnt1 ... b_rpcpinc_jnt10
-----------------------------------------------------------------------------

.   twoway kdensity b_rpcpinc011 if sim==3, scheme(s1mono) nodraw
>         lcolor(gs0) lwidth(medthick) lpattern(shortdash)
>     ||  kdensity b_rpcpinc013 if sim==3,
>         lcolor(gs3) lwidth(medthick) lpattern(dash)
>     ||  kdensity b_rpcpinc015 if sim==3,
>         lcolor(gs6) lwidth(medthick) lpattern(longdash)
>     ||  kdensity b_rpcpinc0110 if sim==3,
>         lcolor(gs9) lwidth(medthick) lpattern(solid)
>         ylabel(0(5)25, grid)
>         xlabel(-.1(.1).3) xline(.1) xtitle("")
>         title("Coefficients for X for State 1") l1title("Unconditional Dyadic EHA", size(medlarge))
>         xsize(4) ysize(3)
>         legend(label(1 "rho=0.85") label(2 "rho=0.65") label(3 "rho=0.50") label(4 "rho=0.05")
>           cols(4) rows(1))
>         name(b1sim3, replace);

.   twoway kdensity b_rpcpinc021 if sim==3, scheme(s1mono)  nodraw
>         lcolor(gs0) lwidth(medthick) lpattern(shortdash)
>     ||  kdensity b_rpcpinc023 if sim==3,
>         lcolor(gs3) lwidth(medthick) lpattern(dash)
>     ||  kdensity b_rpcpinc025 if sim==3,
>         lcolor(gs6) lwidth(medthick) lpattern(longdash)
>     ||  kdensity b_rpcpinc0210 if sim==3,
>         lcolor(gs9) lwidth(medthick) lpattern(solid)
>         ylabel(0(20)80, grid)
>         xlabel(-.1(.1).2) xline(0) xtitle("")
>         title("Coefficients for X for State 2") l1title(" ", size(medlarge))
>         xsize(4) ysize(3)
>         legend(label(1 "rho=0.85") label(2 "rho=0.65") label(3 "rho=0.50") label(4 "rho=0.05")
>           cols(4) rows(1))
>         name(b2sim3, replace);

.   twoway kdensity b_rpcpinc011 if sim==11, scheme(s1mono) nodraw 
>         lcolor(gs0) lwidth(medthick) lpattern(shortdash)
>     ||  kdensity b_rpcpinc013 if sim==11,
>         lcolor(gs3) lwidth(medthick) lpattern(dash)
>     ||  kdensity b_rpcpinc015 if sim==11,
>         lcolor(gs6) lwidth(medthick) lpattern(longdash)
>     ||  kdensity b_rpcpinc0110 if sim==11,
>         lcolor(gs9) lwidth(medthick) lpattern(solid)
>         ylabel(0(5)25, grid)
>         xlabel(-.1(.1).3) xline(.1) xtitle("")
>         title(" ") l2title("Conditional Dyadic EHA", size(medlarge))
>         xsize(4) ysize(3)
>         legend(label(1 "rho=0.85") label(2 "rho=0.65") label(3 "rho=0.50") label(4 "rho=0.05")
>           cols(4) rows(1))
>         name(b1sim11, replace);

.   twoway kdensity b_rpcpinc021 if sim==11, scheme(s1mono) nodraw 
>         lcolor(gs0) lwidth(medthick) lpattern(shortdash)
>     ||  kdensity b_rpcpinc023 if sim==11,
>         lcolor(gs3) lwidth(medthick) lpattern(dash)
>     ||  kdensity b_rpcpinc025 if sim==11,
>         lcolor(gs6) lwidth(medthick) lpattern(longdash)
>     ||  kdensity b_rpcpinc0210 if sim==11,
>         lcolor(gs9) lwidth(medthick) lpattern(solid)
>         ylabel(0(20)80, grid)
>         xlabel(-.1(.1).2) xline(0) xtitle("")
>         title(" ") l1title(" ", size(medlarge))
>         xsize(4) ysize(3)
>         legend(label(1 "rho=0.85") label(2 "rho=0.65") label(3 "rho=0.50") label(4 "rho=0.05")
>           cols(4) rows(1))
>         name(b2sim11, replace);

. grc1leg b1sim3 b2sim3 b1sim11 b2sim11, scheme(s1mono)
>         cols(2) rows(2)
>         imargin(zero)
>         xsize(6) ysize(4.5);

.         graph save boehmke2009jop-montecarlo-fig1, replace asis;
file boehmke2009jop-montecarlo-fig1.gph saved

. log close;
      name:  <unnamed>
       log:  D:\Data\share\boehmke2009jop\montecarlo\boehmke2009jop-montecarlo.log
  log type:  text
 closed on:   1 Dec 2011, 10:44:14
---------------------------------------------------------------------------------------------------------
