How to collect and export results

This example shows how to conveniently save and export your estimates using the r(table) matrix that is now returned by each command.

Setup example data

use https://raw.github.com/remlapmot/mrrobust/master/dodata, clear

Select observations (p-value with exposure < 10-8)

gen byte sel1 = (ldlcp2 < 1e-8)

Fit estimators - collecting results using r(table) matrix

IVW (with fixed effect standard errors)

mregger chdbeta ldlcbeta [aw=1/(chdse^2)] if sel1==1, ivw fe
mat ivw = r(table)
                                                      Number of genotypes = 73
                                      Residual standard error constrained at 1
------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
chdbeta      |
    ldlcbeta |   .4815055    .038221    12.60   0.000     .4065938    .5564173
------------------------------------------------------------------------------

MR-Egger (with SEs using an unconstrained residual variance)

mregger chdbeta ldlcbeta [aw=1/(chdse^2)] if sel1==1
mat mregger = r(table)
                                                      Number of genotypes = 73
                                              Residual standard error =  1.548
------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
chdbeta      |
       slope |   .6173131   .1034573     5.97   0.000     .4145405    .8200858
       _cons |  -.0087706   .0054812    -1.60   0.110    -.0195136    .0019723
------------------------------------------------------------------------------

MR-Egger using the radial formulation

mregger chdbeta ldlcbeta [aw=1/(chdse^2)] if sel1==1, radial
mat radial = r(table)
                                                      Number of genotypes = 73
                                              Residual standard error =  1.547
------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
radialGD     |
    radialGP |    .642582   .1157871     5.55   0.000     .4156434    .8695205
       _cons |  -.5737301   .3545658    -1.62   0.106    -1.268666    .1212062
------------------------------------------------------------------------------

Weighted mode estimator

mrmodal chdbeta chdse ldlcbeta ldlcse if sel1==1, weighted
mat mode = r(table)
                                                      Number of genotypes = 73
                                                           Replications = 1000
                                                                       Phi = 1
------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
        beta |   .4789702   .0663145     7.22   0.000     .3489963    .6089441
------------------------------------------------------------------------------

Weighted median estimator

mrmedian chdbeta chdse ldlcbeta ldlcse if sel1==1, weighted
mat median = r(table)
                                                      Number of genotypes = 73
                                                           Replications = 1000
------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
        beta |   .4582573   .0653722     7.01   0.000     .3301302    .5863845
------------------------------------------------------------------------------

Combine and export results

Check our matrices

mat dir
mat list ivw
mat list mregger
mat list radial
mat list mode
mat list median
       median[9,1]
         mode[9,1]
       radial[9,2]
      mregger[9,2]
          ivw[9,1]


ivw[9,1]
          chdbeta:
         ldlcbeta
     b  .48150551
    se  .03822098
     z  12.597937
pvalue  2.167e-36
    ll  .40659377
    ul  .55641726
    df          .
  crit   1.959964
 eform          0


mregger[9,2]
           chdbeta:    chdbeta:
             slope       _cons
     b   .61731315  -.00877065
    se   .10345735   .00548118
     z   5.9668371    -1.60014
pvalue   2.419e-09   .10956752
    ll   .41454047  -.01951356
    ul   .82008582   .00197226
    df           .           .
  crit    1.959964    1.959964
 eform           0           0


radial[9,2]
          radialGD:   radialGD:
          radialGP       _cons
     b   .64258196  -.57373006
    se   .11578709   .35456584
     z   5.5496858    -1.61812
pvalue   2.862e-08   .10563675
    ll   .41564344  -1.2686663
    ul   .86952048   .12120621
    df           .           .
  crit    1.959964    1.959964
 eform           0           0


mode[9,1]
             beta
     b   .4789702
    se  .06631445
     z   7.222712
pvalue  5.096e-13
    ll  .34899626
    ul  .60894415
    df          .
  crit   1.959964
 eform          0


median[9,1]
             beta
     b  .45825733
    se   .0653722
     z  7.0099725
pvalue  2.384e-12
    ll  .33013017
    ul  .58638448
    df          .
  crit   1.959964
 eform          0

Combined into single matrix

mat output = (ivw, mregger, radial, mode, median)
mat colnames output = ivw_beta mregger_beta mregger_cons ///
    radial_beta radial_cons mode_beta median_beta
mat coleq output = "" "" "" "" "" "" ""
mat output = output'
mat list output, format(%4.3f)
output[7,9]
                   b      se       z  pvalue      ll      ul      df    crit   eform
    ivw_beta   0.482   0.038  12.598   0.000   0.407   0.556       .   1.960   0.000
mregger_beta   0.617   0.103   5.967   0.000   0.415   0.820       .   1.960   0.000
mregger_cons  -0.009   0.005  -1.600   0.110  -0.020   0.002       .   1.960   0.000
 radial_beta   0.643   0.116   5.550   0.000   0.416   0.870       .   1.960   0.000
 radial_cons  -0.574   0.355  -1.618   0.106  -1.269   0.121       .   1.960   0.000
   mode_beta   0.479   0.066   7.223   0.000   0.349   0.609       .   1.960   0.000
 median_beta   0.458   0.065   7.010   0.000   0.330   0.586       .   1.960   0.000

Export matrix to dataset

drop _all
svmat output, names(col)
local rownames : rownames output
di "`rownames'"
tokenize `rownames'
gen str15 estimate = ""
forvalues i = 1/7 {
    replace estimate = "``i''" in `i'
}

Show dataset

list estimate b se z pvalue ll ul, clean noobs
        estimate           b         se          z     pvalue          ll         ul  
        ivw_beta    .4815055    .038221   12.59794   2.17e-36    .4065938   .5564172  
    mregger_beta    .6173131   .1034573   5.966837   2.42e-09    .4145405   .8200858  
    mregger_cons   -.0087707   .0054812   -1.60014   .1095675   -.0195136   .0019723  
     radial_beta    .6425819   .1157871   5.549686   2.86e-08    .4156434   .8695205  
     radial_cons   -.5737301   .3545658   -1.61812   .1056367   -1.268666   .1212062  
       mode_beta    .4789702   .0663145   7.222712   5.10e-13    .3489963   .6089441  
     median_beta    .4582573   .0653722   7.009973   2.38e-12    .3301302   .5863845  

Save dataset

save myestimates, replace

Export as tab-delimited textfile

export delimited using myestimates.txt, delimiter(tab) replace