Hello, blog readers! It's been a while since I last blogged about anything besides Fitbit, and even then it's been sparse. I apologize, but if you've read my good friend Will's latest Stata blog post, you'll see it's for good reason. I recently moved to Seattle and life got a little hectic the last couple of months with moving and job hunting, so blogging got put on the back burner. More updates on my move in a later post!
In that same blog post I mentioned above, Will briefly mentions our joint presentation at the Stata User Group Meeting coming up in July. I thought this would be great opportunity for me to follow up on that topic here and and get into the details of what we've been working on.
Our program is called gcharts and it has required learning a lot about Stata graphics like studying all the different options for all kinds of graph types. Like his post says, we've studied "Stata graphics enough to be labeled as completely crazy, but at least it has resulted in a marvelous presentation". Well put, Will. Anyway, we've been able to apply what we've learned in such a way that Stata users will now be able to render web-based graphics through Google Charts.
The abstract we submitted is below:
So, why Google Charts?
Well, Will and I both like the functionality of Google Charts. They offer a suite of tables, traditional graphs, and other types of data visualizations. It doesn't require the installation of additional software and using it is pretty straightforward.
Why Google Charts + Stata?
Let's see an example:
If you want to make a line graph in Stata you'd type something like the following. Note we're using S&P500 data and we're making some missing data for our "high" variable:
sysuse sp500, clear replace high = . in 100/120 * Interpolate missings - default in Stata line open high, cmissing(yes) * Same as writing: line open high
Gives us the following graph:
If you wanted to make a line graph using that same dataset in Google Charts API you'd have to do write out the data (note I truncated the data below to make it easier to read) and add any additional options as follows:
Or we could do it as follows:
*In gcharts - interpolating missings is not the default gchart line open high, cmissing(yes)
And we'd get the same resulting HTML as above and a graph that looks like:
Note the cmissing() option. Did you know that existed? Did you know that cmissing(yes) was the default in Stata? I didn't know that before embarking on this project. I also didn't know about the multitude of options there are out there in twoway. Some more options that we learned about were regarding axis suboptions, like the ones pictured below:
What would our graph look like if we typed cmissing(no)? Stata would not interpolate the missing values and we'd see a gap in our graph - see graph below. By default, Google Charts API does not interpolate nulls. We also studied a whole lot about all the details and options of Google Charts API. More on that posts to come.
As you can see we really tried making it as easy as placing gchart in front of what you'd type in your twoway command. Why? Because we're here to simplify your life and we like to keep things as straightforward as possible.
So something like:
scatter high low
gchart scatter high low
Hope you've enjoyed the small preview of what's to come. I'll be posting some more examples along with our code along the way. I'll also be going into all kinds of options and more complicated examples. Stay tuned!
12/1/2016 12:07:47 am
it looks easy and beautiful! but I cannot find the installation package. is it available? best regards and congrats!
3/8/2017 05:38:16 am
Beautiful work! I was looking for a way to produce a Sankey diagram in Stata. I sencond Quim's questions about where to find the installation package. Also, does producing the plots require an internet connection. I have to work with my data on a closed network.
1/12/2018 01:07:05 am
How can I access the gcharts program? No matches are found when I run Stata's findit gcharts command
Your comment will be posted after it is approved.
Leave a Reply.
My name is Belen, I like to play with data using Stata during work hours and in my free time. I like blogging about my Fitbit, Stata, and random musings.