title: Exporting matrix from Stata 12 to Excel or MATLAB
body: <p>I need to export a matrix of regression results from Stata to MATLAB.  I have tried using the Stata command <code>matwrite</code> without success (I get an <code>unrecognized command</code> error).  Here is that attempt:</p>
  
  <pre><code>    ...
      *Regression 1
      reg invlrevcrp_CAm071 lacres_CAm071 lrainm07 lrainm07sq ///
      lannxt lannxtsq lrlanxtsq pkgamz if invlrevcrp_CAm071~=.
      reg lrevcrp_CAm071 lacres_CAm071 lrainm07 lrainm07sq ///
      lannxt lannxtsq lrlanxtsq lpkgamz
      * Store results
      mat coef=get(_b)
      *Export to matlab
      matwrite using "Z:\Thesis\data needed for 2007\matlabfile", ///
      mat(coef) replace
      ...
  </code></pre>
  
  <p>I have had more success using the Stata <code>xml_tab</code> which exports the matrix to Excel, which I can then import into MATLAB.  However, <code>xml_tab</code> gives me too much information.  The matrix I want to export is simply the estimated coefficients from two regressions, without labels.  <code>xml_tab</code> exports everything related to the regression--the t-statistics, p-values, 95% conf. intervals, etc., including labels.  Here is my code using this approach:</p>
  
  <pre><code>     *===============================
       * Regressions
       *===============================
       *Regression 1
       reg invlrevcrp_CAm071 lacres_CAm071 lrainm07 lrainm07sq ///
       lannxt lannxtsq lrlanxtsq pkgamz if invlrevcrp_CAm071~=.
       reg lrevcrp_CAm071 lacres_CAm071 lrainm07 lrainm07sq ///
       lannxt lannxtsq lrlanxtsq lpkgamz
       * Store results
       estimates store revCA1
       *Regression 2
       reg lcostcrp_CAm071 lacres_CAm071 lrainm07 lrainm07sq ///
       lannxt lannit lannxtsq lannitsq lpkgf3 lwage if costcrp_CAm071&gt;0
       *Store results
       estimates store cosCA1
       *Export to excel
       xml_tab revCA1 cosCA1, ///
       save("Z:\Thesis\data needed for 2007\RegCoefs") replace
  </code></pre>
  
  <p>I am going through the <code>xml_tab</code> help file to see if I can get what I want, but can anyone help with <code>matwrite</code> or <code>xml_tab</code>?</p>