Several errors with your code:
1. The syntax for the xml_tab
command is:
xml_tab [namelist] [, options]
where namelist "is a list of stored estimations or matrices". You have author_model_1
which does not comply with that requirement.
2. The .xml file to be output must be specified with the option save(["]filename["])
You do not comply with this either.
3. Your keep()
option includes the dependent variable, but keep()
is meant to handle coefficients. The dependent variable has no coefficient.
The following code works (just change the output directory)
clear all
set more off
sysuse auto
reg price mpg weight length, robust plus
estimates store model
local x = upper(word(c(current_date),1)+word(c(current_date),2)+word(c(current_date),3))
display "`x'"
xml_tab model, ///
save("D:\USER\Desktop\myfile_(`x').xml") ///
replace nolabel below tstat ///
format((S2110) (SCCB0 NCCR3 NCCR2)) ///
keep(mpg weight length) ///
stats(N r2 r2_a p) ///
sheet("Analysis") ///
title("Analysis") ///
cwidth(0 100, 1 80, 2 80, 3 80) ///
cnames("Basic Regression")
All this can be resolved simply looking at help xml_tab
.
The command, according to its help file, allows only stored estimation results (using estimates store
) and matrices.
If you want to export, for example, the results of test
(which will not be saved by estimates store
), then you can save its results to matrices and feed that into xml_tab
. However, some testing shows that you cannot feed both at the same time, so two calls have to be made. The first for all stored estimation results; the second for all matrices. Something like this works:
clear all
set more off
sysuse auto
reg price mpg weight length, robust plus
estimates store model
test mpg = weight
matrix p1 = r(p)
matrix f1 = r(F)
test mpg = length
matrix p2 = r(p)
matrix f2 = r(F)
local x = upper(word(c(current_date),1)+word(c(current_date),2)+word(c(current_date),3))
xml_tab model, save("D:\USER\Desktop\myfile_(`x').xml") replace
xml_tab p1 f1 p2 f2, save("D:\USER\Desktop\myfile_(`x').xml") append
The results are distributed in two sheets (when opened with MS Excel). I find the output clumsy for what you pursue, but I'm no expert using the xml_tab
command. You might want to explore Stata built-in commands (xml_tab
is a user-written command from SSC). To export directly to spreadsheet, try help export excel
, help putexcel
. For more general options try help export
. For popular user-written commands that allow exporting results try ssc describe estout
and ssc describe tabout
.