Network Graphs in Native Stata Code

April 13, 2010 at 5:35 am 3 comments

| Gabriel |

My approach to handling networks in Stata is to not handle them in Stata. Rather I take an approach inspired by the Unix philosophy and export the data, then call an R script to do what I need, and in some cases use perl to clean the output for importing back into Stata. Since R/igraph has great network tools, this is a very flexible and powerful workflow. However it’s better suited for scripting than exploratory interactive work and it’s frustrating and slow-going as R syntax is really different from Stata.

Fortunately, Rense Corten has created “netplot.” The upside is that it has a simple syntax and is entirely Stata native code so there’s much less hassle than piping to R. The downside is that while it renders fast for small networks, it doesn’t scale as well to medium or large networks as the dedicated SNA packages. The current version only offers MDS and circle as layout algorithms, but future versions may work in K-K or F-R. Here’s a sample plot of a mid-sized random graph (note this took about 30 seconds to render, whereas R/igraph could do it in less than a second).

Anyway, I congratulate Dr. Corten on the accomplishment. I’m really excited about “netplot” in part as a proof of concept towards developing Stata native SNA capabilities but even more because it will make it much more convenient to generate SNA graphs from Stata. For now I still prefer the rendering speed and flexibility of R/igraph, but I really like that I can do a very good initial version natively as it makes exploratory work more convenient. Keep in mind though I have a considerable sunk cost in learning to pipe to R/igraph, someone who has yet to make such an investment might very well prefer to rely on netplot exclusively for graphing as it’s extremely easy to use and gives output that’s great for many purposes.

To install “netplot” type “ssc install netplot”. Also see this blog post and this manual.

Entry filed under: Uncategorized. Tags: , , .

Cups-pdf More online interactional vandalism


  • 1. Rense  |  April 13, 2010 at 7:51 am

    Thanks for highlighting my work! I fully sympathize with your concerns – the increasing computation time for large networks is a problem. However, because the native MDS procedure is mostly to blame for that, it is not something I can easily solve. A simple workaround is to restrict the number of iterations, which in my experience does not affect the results that much.
    Anyway, as you correctly sensed, “proof of concept” was the main aim of creating netplot, so let’s hope it spawns some new SNA applications for Stata.
    Best, Rense

    ps. There’s a typo in the second mention of my name ;)

  • 2. gabrielrossman  |  April 13, 2010 at 1:14 pm


    i suspected that the slowness was carried over from MDS. i experimented with the iterations option and found that 50 iterations gives a bad layout but 100 iterations gives a good layout and only takes a few seconds. [my crude measure for what makes a “good” layout is that it should minimize the total amount of ink devoted to edges/arcs].

    maybe in future versions you could add something like this:

    if `nobs' > 100 & "`plottype'"=="mds" {
       disp "Note, the underlying MDS algorithm can be slow with large datasets. If this is inconvenient try using the option iterations(100)"

    anyway, just a thought.

    also, i corrected the spelling of your name, sorry about that

    congratulations again on writing a very nice ado file, i plan to use it and continue recommending it. i’m also excited about your broader ambition to develop SNA in Stata — feel free to adopt any of my code for that purpose.

  • 3. Quora  |  February 27, 2012 at 10:08 am

    Where can I find Stata code for relational class analysis?…

    I don’t have experience with RCA, but if it is anything like SNA check out the package from SSC called -netplot- and Gabriel Rossman’s packages/blog on the topic: …

The Culture Geeks


Get every new post delivered to your Inbox.

Join 3,950 other followers

%d bloggers like this: