I need to export a matrix of regression results from Stata to MATLAB. I have tried using the Stata command matwrite
without success (I get an unrecognized command
error). Here is that attempt:
...
*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
...
I have had more success using the Stata xml_tab
which exports the matrix to Excel, which I can then import into MATLAB. However, xml_tab
gives me too much information. The matrix I want to export is simply the estimated coefficients from two regressions, without labels. xml_tab
exports everything related to the regression--the t-statistics, p-values, 95% conf. intervals, etc., including labels. Here is my code using this approach:
*===============================
* 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>0
*Store results
estimates store cosCA1
*Export to excel
xml_tab revCA1 cosCA1, ///
save("Z:\Thesis\data needed for 2007\RegCoefs") replace
I am going through the xml_tab
help file to see if I can get what I want, but can anyone help with matwrite
or xml_tab
?