“”
Back

Presentation

Stata to Excel: From do-file to VBA

James Pike

Thursday 11th September

Session

The introduction of Stata’s putexcel command enhanced the integration between Stata and Excel, allowing users to export formatted results directly from one to the other. Via putexcel, complex outputs and spreadsheets are possible without copy-pasting or manual formatting. For many tasks, putexcel streamlines workflows and saves time. However, putexcel has limits. Some Excel features, such as conditional formatting, autofit of cells, text to columns, or removing excess formatting, cannot be performed. However, Excel’s own language, Visual Basic for Applications (VBA), enables automation options that go beyond Stata’s scope. Using putexcel and then VBA in Excel often means running a do file and then opening the resulting Excel file in Excel to run VBA macros. We present a method of automation where we use Stata to write and execute VBA code via a Visual Basic Script (VBS) file. By generating a .vbs script from within Stata (using the file command) and running it (with the shell command), users can automate Excel tasks that require VBA, all in the comfort of the Stata environment. This approach creates new possibilities for a streamlined workflow.

Speaker

James Pike