X Close

Digital Education team blog

Home

Ideas and reflections from UCL's Digital Education team

Menu

Getting better at Stata and R!

By Jim R Tyson, on 9 May 2022

It’s possible that some Stata and R users are like me: I am much more likely to spend an hour exploring a new package for k-means clustering or time series techniques or panel data, than I am to look in any detail at new features in graphics routines or learning how to format tables. I tell everyone that the most important part of data analysis is communicating results, but I don’t follow my own lead.

So, in an effort to improve my own knowledge in both Stata and R, I have designed three short new workshops/demonstrations:

  • Scripting Stata Graphs
  • Scripting Stata Tables
  • Better Tables in R

The first of these covers a topic that I have some familiarity with – I have always created simple graphs from do files. I decided to take a more systematic approach and so I’ve created this workshop to cover the most common options and settings when using the graphing commands, but also to demonstrate efficient ways to export the output of these routines from scripts. Scripting more fully leads to a much better experience of visualising data with Stata.

The same goes with tabulations in Stata. From Stata 16 the table command itself has changed and from Stata 17 and on, Stata Corp have been promoting the use of collections in conjunction with tables as the best way to customise tables and then to export the results. While some of us may still prefer to export default tables, and then edit them in Word, for most situations it will be worth at least considering scripting more of the process.

In R, there are too many different table packages, and they differ in what outputs they support (PDF, HTML, etc) and in how much customisation you can easily achieve. Some packages are fine for a limited range of purposes – I have always used Stargazer for regression outputs, for example, but I do often end up taking either the LaTeX output or the Microsoft Word output in a knitted document and doing the formatting myself. For custom tables, until now I felt stuck with HTML or LaTeX since RMarkdown doesn’t have a powerful table language. Now, I’ve committed to learning gt() which although new and presently lacking some small things and still needs simple, reliable cross-referencing, looks to be going in the right direction for a reasonable table language built in a modular, systematic way.

So, if you like the sound of improving your Stata scripting skills or of learning the basics of gt(), sign up!

 

 

Leave a Reply