X Close

Digital Education team blog

Home

Ideas and reflections from UCL's Digital Education team

Menu

Starting up Stata with personalised options

By Jim R Tyson, on 4 March 2024

There are often things one can do to personalise and improve ones experience with software that involve some cusotmization, and that may be easy on your own machine, but less easy if your machine is managed by the organisation (in this case UCL).  My Laptop is managed by UCL (although I do have some elevated rights).

In an effort to improve my Stata workflow and output, I have several graphing options that I want to apply to all graphis I produce in Stata.  Typically, I want the Title left justified, in black, to take up the whole width of the graph (rather than the plot region) and to appear top left (at 11 o’clock).  The graph region colour should be white with no axis lines for x or y axes and with no fill-colour or border colour.

To simplify this I put these in a global macro ‘graph_opts‘ and add the macro to the start of any graphing command as $graph_opts . Anyone who knows how lazy and inconsistent I am, will already be guessing that while I may aspire to do this, I more often just hack away at my graphs until they look (more or less) as I want.  This is the worst kind of laziness because a little effort in setting this up would make for less work.

So I decided to investigate – could I automate this?  And I can.  At first, my heart sank slightly when I realised I would have to deal with the system paths on my managed machine, but it turned out to be very straight forward.  You can use sysdir on the stata console to find your stata program files folder.  When you navigate to this folder, use dir *.do to check for the presence of the file sysprofile.do -this means you are in the right directory.  Now, create a new do file called profile.do  Any code you add to this file is executed on Stata start up.  Knowing that I added these lines to my own profile.do (I used the Stata do file editor, but any plain text editor such as Windows Notepad would do as well):

// For -twoway- graphs
global graph_opts ///
  title(, justification(left) color(black) span pos(11)) ///
  graphregion(color(white)) ///
  xscale(noline) xtit(,placement(left) justification(left)) ///
  yscale(noline) ylab(,angle(0) nogrid) ///
  legend(region(lc(none) fc(none)))

// For -graph- graphs
global graph_opts_1 ///
  title(, justification(left) color(black) span pos(11)) ///
  graphregion(color(white)) ///
  yscale(noline) ylab(,angle(0) nogrid) ///
  legend(region(lc(none) fc(none)))

Of course you will want to change these to meet your own preferences – which may mean a deep dive into the Stata documentation.  It is however worth it given the time and effort you will save in hacking at graph code (or [shudder] gph files) to ensure that your graphs are all consistently presented in your reports.