nwbetween
Betweenness centrality
Syntax
nwbetween
[netlist]
[,
generate(newvarlist)
replace
nosym
standardize
silent
weighted
alpha(real)
force
binary
twomode
onemode]
generate(newvarlist) |
Required. Variable name for betweenness centrality |
replace |
allow overwriting an existing variable of the same name |
nosym |
do not symmetrize network before calculation of shortest paths |
standardize |
standardize centrality scores |
silent |
suppress the summary table of the generated variable |
weighted |
use the tie values in the shortest paths; redundant on a valued network, where this is the default (kept for compatibility) |
alpha(real) |
weight-to-distance exponent used with weighted; default = 1 |
force |
Run the command although its estimated time is more than 2 minutes (it stops with r(484) otherwise) |
binary |
Ignore the tie values of a valued network (by default they are used) |
twomode |
Two-mode network: the default; accepted as a synonym of the default (betweenness divided by the largest value a node of its mode can reach, Borgatti and Everett 1997; standardize is this standardisation on a two-mode network) |
onemode |
Two-mode network: the betweenness of the bipartite graph read as a one-mode graph, not divided by the largest possible value (the result of earlier releases; standardize then divides as for any graph) |
Description
Calculates the betweenness centrality for each node i in a network or network list and saves the result as a Stata variable. By default the command uses the dichotomized network (any tie with weight > 0 counts as an edge, tie strength ignored); pass weighted to compute genuinely weighted betweenness on Dijkstra shortest paths instead, using alpha() to control the weight-to-distance conversion. This follows Opsahl, Agneessens and Skvoretz (2010) - the same generalization nwgeodesic’s own alpha() already implements for weighted distances - where edge cost is (1/weight)^alpha: a STRONGER tie is a SHORTER effective distance, not a longer one. alpha(1), the default, uses the reciprocal of the raw tie weight directly as distance/cost; alpha(0) reduces to the unweighted case (every positive tie costs exactly 1, ignoring its strength). See the References section below for the full citation.
The betweenness centrality for node i is equal to the number of shortest paths from all vertices to all others that pass through node i. A node with high betweenness centrality has a large influence on the transfer of items through the network, under the assumption that item transfer follows the shortest paths.
When there is more than one shortest path from node k to node l, the betweenness scores of all nodes i on these paths increases proportionally.
Formally, betweenness centrality of node i on graph g is defined as:
Between_i(g) = sum ( sigma_st(i) / sigma_st )
where, sigma_st is the total number of shortest paths from node s to node t and sigma_st(i) is the number of those paths that pass through node i.
For the standardized betweenness centrality:
Directed network: Between_i_std(g) = Between_i(g) / ((N-1)(N-2))*
Undirected network: Between_i_std(g) = Between_i(g) / ((N-1)(N-2)/2)*
The stored result r(bw_central) is Freeman’s betweenness centralization, computed from the raw scores whether or not standardize is given: sum(max - Between_i) / ((N-1)^2(N-2)) for a directed network (raw scores count ordered pairs) and sum(max - Between_i) / ((N-1)^2(N-2)/2) for an undirected network (raw scores count unordered pairs). It equals 1 for a star and agrees with R’s sna::centralization(, betweenness). Without nosym the network is symmetrized first, so the undirected formula applies. Before the correction of this formula the value stored for an undirected network was half of Freeman’s.
generate() is required and names the Stata variable to hold the result (pass replace to allow overwriting an existing variable of that name). When betweenness centrality is calculated for more than one network at the same time (e.g. nwbetween glasgow1 glasgow2, generate(bw)), the command generates one variable per network, named varname_netname (e.g. bw_glasgow1, bw_glasgow2).
Examples
. nwwebuse gang, nwclear
. nwbetween gang, generate(_between)
. sum _between
Performance
The default (unweighted) mode of nwbetween transparently uses a compiled native (C) implementation of the same algorithm when one is available for the current platform (currently: macOS), falling back to an identical, fully-supported Mata implementation everywhere else - there is nothing to configure and no difference in the result, only in how fast it is computed (a native run at 10,000 nodes was measured faster than the Mata implementation at just 1,000). The weighted mode (valued networks) has its own native kernel (Dijkstra’s search inside Brandes’ algorithm) with the same result as the Mata routine: 1,000 nodes with 3,000 valued ties take 0.13 seconds (Mata: 111 seconds), 10,000 nodes 15 seconds; the Mata routine needs a dense work space of n x n cells for every node and is not usable above a few hundred nodes.
Supported network types
Binary: yes, native. Directed: yes for the standardization normalizer (see the formulas above), but by default the network is symmetrized before computing betweenness at all - pass nosym to compute genuinely directed betweenness on the network as given; without nosym the reported scores reflect the symmetrized structure, not the original directed one (this applies identically whether or not weighted is used - symmetrization, via nwsym’s default max mode, correctly combines rather than discards tie weights). Weighted: W2 - the default remains W3 (explicit binary-only: any tie with weight strictly greater than zero is dichotomized to an edge, tie strength otherwise ignored), but weighted now computes genuine Dijkstra-based betweenness using tie strength directly as distance/cost via alpha() - never silently implied, always an explicit opt-in. Signed: ties with weight less than or equal to zero, including negative ties, are treated as no tie at all in both the default and weighted cases - a negative (e.g. antagonistic) tie is not distinguished from an absent one, and weighted’s weight^alpha cost is undefined for a negative base in general, so signed networks are not natively supported by either mode. Two-mode: two-mode form by default - betweenness divided by the largest betweenness a node of its mode can reach in a two-mode network (Borgatti and Everett 1997; twomode is accepted as a synonym); onemode forces the one-mode betweenness of the bipartite graph.
References
Brandes, U. (2001). A faster algorithm for betweenness centrality. Journal of Mathematical Sociology 25, 163-177.
Opsahl, T., Agneessens, F. and Skvoretz, J. (2010). Node centrality in weighted networks: Generalizing degree and shortest paths. Social Networks 32 (3), 245-251.
See also
-
nwpath, nwgeodesic, nwcloseness, nwkatz, nwdegree, nwcloseness, nwevcent
-
last certified : 23 Aug 2026
nwcommands version 3.17.6, 9 November 2026 (check your installed version)