How to get from Stata to Pajek

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 https://www.kai-arzheimer.com/stata/

3 thoughts on “How to get from Stata to Pajek”

  1. 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

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.