/* stata-pajek.do --- * * Filename: stata-pajek * Description: Converts Stata data to Pajek .net * Author: Kai Arzheimer * Created: Sat Nov 28 13:09:45 2009 (+0100) * Version: 1 * Last-Updated: Sun Jan 10 22:03:10 2010 (+0100) * By: Kai Arzheimer * Update #: 99 * URL: * Keywords: * Compatibility: Requires listtex from ssc * */ /* Commentary: * This job takes sna-course.dta (which was created with limesurvey) and converts it into * a .net-file that can be read by Pajek * */ /* Change log: * * */ /* Code: */ use sna-course.dta, clear /*How many cases?*/ qui tab1 id local vertices=r(r) /*Ok. We want to build a matrix */ /*The contact* variables contain the links between vertices */ /*The contacttype variables contain the type of link */ /* This is the single important command. The Stata dataset is wide, there is one line per vertex and one variable for each (possible) link. We convert this to the long format, which has one line per link, just like Pajek's native format*/ reshape long contact,i(id) j(recipient) /*Write header*/ file open myfile using course.net, write replace file write myfile "*Vertices `vertices' " _n /*We want to insert the students' initials*/ /*Stata's preserve/restore feature is extremely handy*/ preserve keep id name /*Keep only unique observations, i.e. a list of vertices with their names*/ duplicates drop /*Write list*/ listtex id name, appendto(course.net) delim(" ") nolab handle(myfile) /*Restore complete dataset*/ restore /*Remove non-existent links - could also be done in Pajek */ drop if contact ==0 drop if contact ==. /*Write arcs*/ file write myfile "*Arcs " _n /*Write arcs*/ listtex id recipient contact, appendto(course.net) delim(" ") nolab handle(myfile) /*Close file*/ file close myfile /* stata-pajek.do ends here */