How to output tables and figures - labordynamicsinstitute/replicability-training GitHub Wiki
Standard tables generated by commands
For Stata, see also the DIME Wiki
Package | Command | Example | |
---|---|---|---|
Stata | logout | logout, save("table1.xlsx") excel replace fix : as a prepend to tabstat , for example. |
|
R | print |
print() can handle certain cases |
|
Matlab |
Standard regression table
Package | Command | |
---|---|---|
Stata | estout | eststo , estout , etc. |
R | various | |
Matlab | native | writetable ? |
Post-processing regression output in programming language
Sometimes, you want to treat regression output as data.
Package | Command | |
---|---|---|
Stata | regsave | regsave |
R | various | |
Matlab | ? |
Arbitrary data to Excel
This is useful if the data needs to be combined in non-standard ways that are easy to do in Excel, but hard to program in other languages.
Package | Command | |
---|---|---|
Stata | native | putexcel in combination with r() or e() |
R | writexl |
writexl::write_xlsx() |
R | openxlsx |
openxlsx::write.xlsx() |
Matlab | native | writematrix |
Matlab | native | writetable |
Examples
Stata
// run gmm model
use http://www.stata-press.com/data/r13/auto
gmm (mpg - {b1}*weight - {b2}*length - {b0}), instruments(weight length)
matrix b = e(b)'
// prepare sheet
putexcel set myresults, sheet("GMM Results")
// write out results
putexcel B1 = "Coefficients"
putexcel A2 = matrix(b), rownames nformat(number_d2)
The resulting Excel sheet myresults.xlsx looks like this:
Coefficients | ||
---|---|---|
b1 | _cons | 0.00 |
b2 | _cons | -0.08 |
b0 | _cons | 47.88 |
An Excel formula could now collect specific coefficients across multiple regressions into a summary table, possibly easier than to program it in Stata. For more information, see putexcel
(available since at least Stata 13)
MATLAB
fileName = "./tables/table_6.xlsx";
writetable(tDeltaChannelsAll, fileName, "Sheet", "default", "WriteRowNames", true, "Range", "A1");
Notes
R
There is also a xlsx
package, but it has a Java dependency, which is not as robust cross-platform.
Saving a figure
Package | Command | |
---|---|---|
Stata | native | graph export |
R | native, ggplot2 |
png() , ggsave() |
Matlab | native | saveas(fig,filename) |
Matlab | native | exportgraphics() |
Mathematica | native | Export[] |