nwpath vs nwgeodesic

152 views
Skip to first unread message

Paul Hofman

unread,
Dec 11, 2015, 10:43:08 AM12/11/15
to nwcommands
I want to calculate shortest paths between all nodes in a network, and save that to a regular stata file (so with three columns, alter, ego and shortpath). I couldn't find an easy way to do this using nwgeodesic, so I opted for nwpath with some extensive looping. But while nwgeodesic takes just seconds, nwpath takes around 5 minutes per network to calculate the shortest paths within a network. I have 40 networks with about 130 nodes per network. Is there are a way to speed up nwpath, or is there a way to export the shortest paths as calculated by nwgeodesic to a regular dataset?

Thanks,

Paul

Thomas Grund

unread,
Dec 12, 2015, 6:26:36 AM12/12/15
to Paul Hofman, nwcommands
Hi all,

below is the answer for what Paul wants to do. He points towards the problem of keeping node labels when making an edgelist. While "nwtoedge" does not have a specific option to do this, you can achieve it very easily by specifying the "fromvars()" and the "tovars()" option with the original node labels.

For example, the solution to his specific problem using the florentine data would be:

. webnwuse florentine
. gen originallab = _nodelab
. nwgeodesic flomarriage, name(mygeo)
. nwtoedge mygeo, fromvars(originallab) tovars(originallab)

In a similar way you can make an edgelist with node labels, instead of node id's:

. webnwuse florentine
. nwtoedge flomarriage, fromvars(_nodelab) tovars(_nodelab)

This generates the new variables "from_nodelab" and "to_nodelab", which hold the original node labels.

Best,
Thomas

--
You received this message because you are subscribed to the Google Groups "nwcommands" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nwcommands+...@googlegroups.com.
Visit this group at http://groups.google.com/group/nwcommands.
To view this discussion on the web visit https://groups.google.com/d/msgid/nwcommands/b42fc264-ae60-4e6f-bbce-0b99c113cf6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paul Hofman

unread,
Dec 12, 2015, 7:27:10 AM12/12/15
to nwcommands, hofma...@gmail.com
Perfect, thanks so much Thomas!
Reply all
Reply to author
Forward
0 new messages