Jan 102010

I’m teaching an introductory SNA class this year. Following a time-honoured tradition, I conducted a small network survey at the beginning of the class using Limesurvey. Getting the data from Limesurvey to Stata via CSV was easy enough. Here is the data set. But how does one get the data from Stata to Pajek for analysis? Actually, it’s quite easy.

First, we need to change the layout of the data. In the data set, there is one record for each of the 13 respondent. Each record has 13 variables, one for each (potential) arc connecting the respondent to other students in the class. This is equivalent to Stata’s “wide” form. Stata’s reshape command will happily re-arrange the data to the “long” form, with one record for each arc. This is what Pajek requires.

Second, we need to save the data as an ASCII file that can be read into Pajek. This is most easily done using Roger Newson’s listtex, which can be tweaked to write the main chunks of a Pajek file. Here is the code, which should be readily adapted to your own problems.

If you are interested, you can get the whole package from within Stata: net from http://www.kai-arzheimer.com/stata/

Reblog this post [with Zemanta]
Click to share

  3 Responses to “How to get from Stata to Pajek”

  1. […] Getting  a data matrix from Stata into Pajek is not necessarily a fun exercise, so I decided to give the networkx module for Python a go, which is simply superb. Networkx has data types for representing social networks, so you can read in a rectangular data matrix (again as CSV),  construct the network in Python and export the whole lot to Pajek with a few lines of code: […]

  2. your code uses the logical end-of-line character "_n". since Pajek insists on Windows formatted text files, this is fine on Stata for Windows, but on Stata for Mac/Unix you need to use the Stata command "filefilter" to force the file to have Windows EOL characters.
    also, i have a similar ado file at ssc called "stata2pajek"
    there's also a more flexible version on my blog that lets you merge on vertice level attributes, like colors

Agree? Disagree? Leave a reply (also works with Facebook, G+, Disqus ...)