Skip to content

Rense Corten

Computational sociology, social networks, and cooperation

Menu
  • About me
  • Blog
  • Research
    • Social Network Analysis with Stata
  • Teaching
Menu

pajek2stata

Posted on 02/05/2010

Of all the currently available data formats for social network data, the .net format  that Pajek uses is probably the most widely compatible and versatile format in use.  Although these files are basically just ASCII files, Stata cannot directly read data from this format because of rather specific way the data are defined. For one, .net files contain at least two data objects: a specification of vertices (nodes), and a specification of relations between those vertices. Build-in Stata routines to read ASCII data (insheet, infile, infix) expect only one data object (your regular data matrix of observations and variables).

This is were my new command pajek2stata comes in. Pajek2stata lets you import .net files, storing the vertices part of the file as your Stata dataset, and the relations part as a matrix in Mata with a name of your choice.  The syntax is pajek2stata using fname, name(name) [clear replace], in which fname is the name of your Pajek file and name is the name of the Mata matrix that will hold the network part of the data.

Why store the network part of the data in Mata? Unlike other statistical packages, Stata can have only one dataset in memory at the time. So, if you are loading a network dataset that naturally consists of two objects, you have to put second part somewhere. Mata, then, is a good option (a Stata matrix could be another) because it allows you to easily interact with the data, and it has no trouble handling the different shapes that the network parts of .net files can take.

At this point you might wonder: why would I want to load Pajek data in Stata in the first place? I can think of a number of reasons. First, you might have a .net file with information on vertices that you want to analyze in Stata. Pajek2stata provides an easy way to access those data, even if you are not interested in the network part of the data. Second, once you have the network data in Mata, this allows you to use those data in a very flexible way, for example by programming your own network measures. I will post some examples of that later.

One challenge in analyzing your network data like this in Mata is that the data can take different shapes in .net files: they can be square N x N adjacency matrices, or they can by two-column edge- or arclists. Pajek2stata simply loads the data in the shape that the .net file provides. I’ll write more later about how to get from one shape to the other.

At the moment, pajek2stata can only handle simple .net files containing not more than one network specification. Pajek also supports .net files with multiple network specifications for the same set of vertices. Future versions of pajek2stata may be able to deal with such files.

In case you’d like to export data from Stata to Pajek, stata2pajek (written by Gabriel Rossman) can do the job. At the moment, the two programs do not really smoothly combine in the sense that you could import a .net file with pajek2stata and immediately export it using stata2pajek (because the latter assumes an edge- or arclist stored as a Stata dataset), but there are workarounds for that. Again, more later.

To install pajek2stata, type ssc install pajek2stata.

Recent Comments

  • michal on Duncan Watts on common sense
  • Rense on On unsolved sociological questions
  • Gabriel rossman on On unsolved sociological questions

Categories

  • Everything (8)
  • In het Nederlands (1)
  • Other (2)
  • Politics (2)
  • Science (4)
  • SNA with stata (9)
  • Social Networks (27)
  • Social Science (16)
  • Sociology (32)
  • Stata (7)
  • The Netherlands (8)
  • The Universe (2)

Blogroll

  • Brokering the Closure
  • Chris Snijders
  • Code and Culture
  • Orgtheory.net
  • Permutations
  • Social Science Statistics Blog

Links

  • GECS
  • ICS
  • INSNA
  • International Network of Analytical Sociologists
  • Mathematical Sociology Section (ASA)
  • My Google Scholar profile
  • My official UU webpage

Contact

r.corten [at] uu.nl
@RenseC

Subscribe

RSS Feed RSS
©2025 Rense Corten | Design: Newspaperly WordPress Theme