Reputation: 799
I need to export several matrices created in Stata to several different specifically named sheets of an already existing excel file. This would be a piece of cake in Matlab using xlswrite(). I am having trouble finding a similar command in Stata.
"xml_tab" would work but it doesn't seem to want to let me open and make changes to an already existing excel file. It always starts by creating a new excel file.
I would appreciate some help as to how I might get "xml_tab", or some other Stata command, to open an already existing excel file, make changes to it (overwriting specific sheets with new matrices), and then save it without overwriting all the other stuff on the other sheets that I don't want to touch.
Can Stata do that?
Thanks
EDIT:
An example of what I need to do is this:
*Define poverty line
scalar povlin=29347.5
*1) SETUP sheet
mat SETUP=(1,J(1,3,0),1,J(1,2,0),1,1,J(1,5,0),povlin)
/* Here I need to export the matrix SETUP to sheet "SETUP" in an
already existing excel file. In matlab it would be
xlswrite('filename','SETUP','A2') */
*2) FARM sheet
tabstat acres,stat(sum) save
mat acrtot=r(StatTotal)
tabstat aehh07 offrinc07,save
mat vmeans=r(StatTotal)
mat maehh=vmeans[1,1]
mat moffrinc=vmeans[1,2]
tabstat aehh07 offrinc07 acres,stat(cv) save
mat CV=r(StatTotal)
tabstat acres,save
mat macres=r(StatTotal)
mat FARM=(1,acrtot,maehh,CV[1,1],moffrinc,CV[1,2],moffrinc,CV[1,2],J(1,3,0),macres)
/* Here I need to export the matrix FARM to sheet "FARM" in the
same already existing excel file where I put the SETUP matrix. In matlab it would
be xlswrite('filename','FARM','A2') */
I need to do this kind of thing for several sheets.
Upvotes: 1
Views: 978
Reputation: 37208
By matrices you might mean (a) Mata matrices (b) Stata matrices (c) complete or partial datasets including one or more Stata variables. The last (c) seems most likely.
The way to change something in Excel is to open Excel. Stata does not offer as it were remote control of Excel manipulations, which you seem to be asking for. But the Stata commands import excel
and export excel
appear to offer alternatives.
I have never used xml_tab
(Stata Journal 2008) but I always understood its main purpose to be export of results tables, not data.
If you mean (b), you can use svmat
first.
I am guessing you don't mean (a).
(UPDATE July 2013) Stata 13 now has a putexcel
command. See http://www.stata.com/help.cgi?putexcel for an introduction.
Upvotes: 3