将矩阵从Stata 12导出到Excel或MATLAB [英] Exporting matrix from Stata 12 to Excel or MATLAB
问题描述
我需要将Stata的回归结果矩阵导出到MATLAB。我尝试使用Stata命令 matwrite
没有成功(我得到一个无法识别的命令
错误)。这是这个尝试:
...
/ pre>
*回归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
*存储结果
mat coef = get(_b)
*导出到matlab
使用Z:\Thesis\data为2007 \matlabfile需要,///
mat(coef)替换
...
我使用将矩阵导出到Excel的Stata
xml_tab
获得了更多的成功,然后我可以导入MATLAB。但是,xml_tab
给我太多的信息。我想导出的矩阵只是两个回归的估计系数,没有标签。xml_tab
导出与回归相关的所有内容 - t统计,p值,95%conf。间隔等,包括标签。这是我使用这种方法的代码:* =============== ==============
*回归
* ======================= ======
*回归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
*商店结果
估计商店revCA1
*回归2
reg lcostcrp_CAm071 lacres_CAm071 lrainm07 lrainm07sq ///
lannxt lannit lannxtsq lannitsq lpkgf3 lwage if costcrp_CAm071> 0
*存储结果
估计存储cosCA1
*导出到excel
xml_tab revCA1 cosCA1,///
保存(Z:\Thesis\data需要2007\RegCoefs)替换
我正在通过
xml_tab
帮助文件查看是否可以得到我想要的内容,但任何人都可以帮助matwrite
或xml_tab
?解决方案我写了一个.ado程序这样做,命名为mat2txt2。你可以在这里找到:
http:// code.google.com/p/kk-adofiles/source/browse/#hg%2Fm 我写了这个程序来扩展Ben Jann和M Blasnik的mat2txt.ado的功能。
程序会将矩阵导出到分隔的文本文件(例如,逗号分隔的.csv文件或制表符分隔文件)。从那里,您可以轻松地将数据拉入Excel或Matlab。
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 anunrecognized 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 withmatwrite
orxml_tab
?解决方案I wrote an .ado program to do this, named mat2txt2. You can find it here: http://code.google.com/p/kk-adofiles/source/browse/#hg%2Fm I wrote this program to expand the capabilities of mat2txt.ado by Ben Jann and M Blasnik.
The program will export a matrix to a delimited text file (e.g., a comma-separated .csv file or tab-separated file). From there, you can easily pull the data into Excel or Matlab.
这篇关于将矩阵从Stata 12导出到Excel或MATLAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!