Monday, November 30, 2009

Graphs in Stata

There's been a lot of talk around here lately about R, and in particular some criticism about the graphing ability of Stata. I thought it was time someone defended Stata. The manual is hard to get to grips with, but there are a couple of really good things about graphs in Stata. Firstly you can get them to look however you want, even like the ones in excel if you wish. Secondly, it's relatively easy to write up your own program once you've found a style you like. Once this is set up you can label, title, subtitle, show percentages on bars etc. automatically. And then you only need to type programname varname. This is especially useful when you have dozens of graphs to do, and is what we've been doing for the Irish Universities Study, an example is below.



Alan's also done some good ones with confidence intervals here.

Someone sent round an example of a map graph in R, but this is also relatively easy (I managed it so it must be!) to do in Stata with SPAMP. There is a useful guide here. Here's one I did of Ireland.

7 comments:

Liam Delaney said...

excellent, thanks Mark. That mapping command is great.

Kevin Denny said...

"A visual guide to Stata graphics" by Mitchell is extremely useful.

Anonymous said...

Cheers Mark; would like to talk to you about this more!

BrendanH said...

Useful info, but your aspect ratio is out. You're possibly mapping latitude and longitude onto X,Y directly. If so, a quick fix is to scale the X dimension by cos(Y), i.e. shrink the east-west dimension by the cosine of the latitude of the middle of the map.

BrendanH said...

There is an aspect ratio problem. This can be (crudely) fixed by scaling the _X in the *c.dta file (created by shp2dta) by the cosine of the latitude (of the middle of the map, approximately):

local Pi 2*acos(0)
replace _X = _X*cos(`Pi'*53/180)

Mark McGovern said...

Thanks Brendan, I have a habit of exporting graphs the same size as beamer slides and I didn't bother to change for this one. I'd guess the default Stata option gets the aspect ratio right, if not I'll try your suggestion

Peter Carney said...

The graphs look great! good job!