{"id":64,"date":"2010-04-12T17:57:18","date_gmt":"2010-04-12T15:57:18","guid":{"rendered":"http:\/\/www.rensecorten.dds.nl\/?p=64"},"modified":"2013-04-12T15:30:35","modified_gmt":"2013-04-12T13:30:35","slug":"drawing-social-networks-in-stata-with-netplot","status":"publish","type":"post","link":"https:\/\/www.rensecorten.org\/index.php\/2010\/04\/drawing-social-networks-in-stata-with-netplot\/","title":{"rendered":"Drawing social networks in Stata with Netplot"},"content":{"rendered":"<p style=\"text-align: justify;\">An important part of what makes social network analysis so fascinating to broad audiences is the possibility of <em>visualization<\/em> of networks. You can already learn a lot about the structure of a network simply by looking at a picture (although the choice of the &#8216;right&#8217; picture is no trivial thing), and they can be <a href=\"http:\/\/www.visualcomplexity.com\/vc\/index.cfm?domain=Social%20Networks\">esthetically pleasing,<\/a> too.\u00a0 Specialized software packages like <a href=\"http:\/\/vlado.fmf.uni-lj.si\/pub\/networks\/pajek\/\">Pajek<\/a> offer great tools for network visualization,\u00a0 but if you are working with Stata, having to <a href=\"http:\/\/codeandculture.wordpress.com\/2009\/09\/01\/stata2pajek\/\">export your data to Pajek<\/a> for every simple picture is a pain.<\/p>\n<p style=\"text-align: justify;\">My Stata program <code>netplot<\/code> is a first<a href=\"#note\">*<\/a> step to making network visualization available <em>within<\/em> Stata. Assuming that you have data stored as edges or arcs,\u00a0 the program lets you draw plots of your network, using multi-dimensional scaling to determine the placement of the nodes. Alternatively, you can have your nodes arranged on a circle. The use of labels to identify nodes in the graph is also supported.<\/p>\n<p>Below are some examples:<\/p>\n<pre><code>\r\n\/\/create a random network with 10 nodes\r\n\/\/(code adopted from the helpfile of stata2pajek)\r\nclear\r\nset obs 200\r\ngen i=int(uniform()*10)+1\r\ngen j=int(uniform()*10)+1\r\ncontract i j, freq(strength)\r\ndrop if i==j\r\nsort i j\r\ndrop if strength &lt;3 \/\/ --&gt; keep only the \"stronger\" links\r\n\r\n\/\/ Draw the network\r\nnetplot i j\r\n<\/code><\/pre>\n<figure id=\"attachment_74\" aria-describedby=\"caption-attachment-74\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_nol1.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-74 \" title=\"netplot_nol\" alt=\"\" src=\"http:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_nol1-300x218.jpg\" width=\"300\" height=\"218\" srcset=\"https:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_nol1-300x218.jpg 300w, https:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_nol1.jpg 792w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-74\" class=\"wp-caption-text\">Network drawn bij netplot<\/figcaption><\/figure>\n<pre><code>\/\/ Draw with labels\r\nnetplot i j, label\r\n<\/code><\/pre>\n<figure id=\"attachment_75\" aria-describedby=\"caption-attachment-75\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_lab.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-75 \" title=\"netplot_lab\" alt=\"\" src=\"http:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_lab-300x218.jpg\" width=\"300\" height=\"218\" srcset=\"https:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_lab-300x218.jpg 300w, https:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_lab.jpg 792w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-75\" class=\"wp-caption-text\">Network picture with labels<\/figcaption><\/figure>\n<pre><code>\/\/ Use a circle layout\r\nnetplot i j, type(circle) label\r\n<\/code><\/pre>\n<figure id=\"attachment_76\" aria-describedby=\"caption-attachment-76\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_cir.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-76 \" title=\"netplot_cir\" alt=\"\" src=\"http:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_cir-300x218.jpg\" width=\"300\" height=\"218\" srcset=\"https:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_cir-300x218.jpg 300w, https:\/\/www.rensecorten.org\/wordpress\/wp-content\/uploads\/netplot_cir.jpg 792w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-76\" class=\"wp-caption-text\">Circular network picture<\/figcaption><\/figure>\n<p style=\"text-align: justify;\">I admit that multidimensional scaling is not the most fancy node placement algorithm around (see <a href=\"http:\/\/www.cmu.edu\/joss\/content\/articles\/volume1\/Freeman.html\" target=\"_blank\">this article<\/a> by Freeman for an overview of available techniques), but the good thing about it is that the procedure is already included in Stata by default. Getting actually nice graphs with Netplot might take a few trials, but it&#8217;s a start. To install, type <tt>ssc install netplot<\/tt>. More details and other examples are provided in this <a href=\"http:\/\/www.rensecorten.org\/files\/netplot_120410.pdf\" target=\"_blank\">working paper<\/a>. [UPATE: the paper has by now been published in the Stata Journal. Get it <a href=\"http:\/\/statajournal.com\/article.html?article=gr0048\">here<\/a>.]<\/p>\n<p><a name=\"note\"><\/a>*) As far as I know, tell me if I&#8217;m wrong!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An important part of what makes social network analysis so fascinating to broad audiences is the possibility of visualization of networks. You can already learn a lot about the structure of a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[6,27,7,8],"_links":{"self":[{"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/posts\/64"}],"collection":[{"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/comments?post=64"}],"version-history":[{"count":42,"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/posts\/64\/revisions\/113"}],"wp:attachment":[{"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/media?parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/categories?post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rensecorten.org\/index.php\/wp-json\/wp\/v2\/tags?post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}