nwdegree
Degree centrality and distribution
Syntax
nwdegree
[netname]
[,
alpha(real)
ties(varlist)
generate(varlist)
replace
silent
isolates
standardize
in(tabulate_opt)
out(tabulate_opt)
tabulate_opt
outputoff
onemode
raw
binary]
alpha |
Tuning parameter for valued networks; default = 1 (strength) on a valued network, 0 (number of ties) otherwise |
ties(varlist) |
Valued networks: variables for the number of ties (one name, or outdegree and indegree), next to the strength in generate() |
generate(varlist) |
Required. Variable name(s) for degree (undirected) or outdegree/indegree (directed) - and, if isolates is also given, an extra name for the isolate indicator |
replace |
Overwrite existing variables varlist |
silent |
Surpress output |
outputoff |
Reserved/internal - has no effect on a one-mode network’s own output; use silent instead. Only meaningful when netname turns out to be two-mode (where it is named, along with any other one-mode-only option, in the note explaining which options have no two-mode form and were ignored) |
isolates |
Generate variable for network isolates |
standardize |
Divide degree or strength by N - 1 |
in(tabulate_opt) |
Options for tabulating indegree |
out(tabulate_opt) |
Options for tabulating outdegree |
tabulate_opt |
Options for tabulating degree |
binary |
Ignore the tie values of a valued network (by default they are used) |
onemode |
Two-mode network: compute the one-mode degree of the bipartite graph instead of the two-mode degree (the default) |
raw |
Two-mode network: the number of ties itself, not divided by the size of the other mode (tnet::degree_tm) |
Description
nwdegree calculates the generalized degree centrality of the nodes as outlined in Opsahl et al (2010) for the (un-)weighted, (un-directed) networks in netlist. generate() is required: name one variable for an undirected network, or two (outdegree, indegree, in that order) for a directed one. It also tabulates the newly generated variable(s).
Following Opsahl et al. (2010) the degree centrality C_i of node i is defined as:
C_i = k_i * ( s_i / k_i ) ^ alpha
where k_i is the number of ties that node i is involved in (regardless of tie values) and s_i is the sum of the tie values of these ties. When alpha = 0 (default), this generalized degree centrality gives the number of ties that a node has. When alpha = 1, it gives the node strength, i.e. the sum of the tie values that a node is involved in. For unvalued networks the value of alpha does not matter.
Option isolates adds one more name to generate() (after the degree name(s)) for a variable indicating whether a node is an isolate (not connected to any other node) - e.g. generate(mydeg myisolate) isolates on an undirected network, or generate(myout myin myisolate) isolates on a directed one.
Option standardize divides the degree (undirected network) or the outdegree and the indegree (directed network) by N - 1, where N = number of nodes in a network. Each variable is divided once.
The stored results r(dg_central) (undirected), r(indg_central) and r(outdg_central) (directed) are Freeman’s degree centralization, computed from the raw scores whether or not standardize is given: sum(max - c_i) / ((N-1)(N-2)) for an undirected network and sum(max - c_i) / ((N-1)(N-1)) for the in- and outdegree of a directed network.
nwdegree accepts a netlist (e.g. nwdegree glasgow1 glasgow2, generate(deg)), calculating degree centrality independently for each network in the list. When more than one network is given, generate()’s own name(s) get the network’s own name appended (e.g. deg_glasgow1, deg_glasgow2); a single-network call is unaffected and keeps the plain name(s) exactly as given. r() results (e.g. r(dg_central)) reflect whichever network was processed last, matching this package’s convention for other netlist commands.
Examples
- This is the example used in Opsahl et al. (2010, Table 1):
. nwclear
. nwset, mat((.,4,4,0,0,0\
4,.,2,1,1,0\
4,2,.,0,0,0\
0,1,0,.,0,0\
0,1,0,0,.,7\
0,0,0,0,7,.)) undirected labs(A, B, C, D, E, F)
. qui nwdegree, alpha(0) generate(deg0)
. qui nwdegree, alpha(.5) generate(deg0_5)
. qui nwdegree, alpha(1) generate(deg1)
. qui nwdegree, alpha(1.5) generate(deg1_5)
. list deg*
+-------------------------------------+
| deg0 deg0_5 deg1 deg1_5 |
|-------------------------------------|
1. | 2 4 8 16 |
2. | 4 5.6568542 8 11.313708 |
3. | 2 3.4641016 6 10.392304 |
4. | 1 1 1 1 |
5. | 2 4 8 16 |
|-------------------------------------|
6. | 1 2.6457512 7 18.52026 |
+-------------------------------------+
In the following example, the degree distributions for in- and outdegree are saved in Stata matrices matindeg and matoutdeg:
. nwwebuse glasgow
. nwdegree glasgow1, generate(_outdegree _indegree) in(matcell(matindeg)) out(matcell(matoutdeg))
. mat list matindeg
The next example saves the out- and indegree centrality in the variables myout and myin and the information about isolates in myisolate.
. nwdegree glasgow1, generate(myout myin mysiolate) isolates
Supported network types
Binary: yes. Directed: yes - generates separate _indegree/_outdegree (or _instrength/ _outstrength for a valued network) automatically. Weighted: W1, native - the Opsahl et al. (2010) generalized degree formula above is the command’s default and only formulation, controlled by alpha(); weight meaning is tie strength, used directly (not a distance). Signed: not checked. Two-mode: two-mode form by default (the number of ties divided by the size of the other mode, raw: the count); onemode forces the one-mode computation on the bipartite graph (nw2degree is an alias).
References
Tore Opsahl, Filip Agneessens, John Skvoretz (2010). Node centrality in weighted networks: Generalizing degree and shortest paths. Social Networks 32 (3), 245-251.
See also
- nwbetween, nwcloseness, nwclustering, nwevcent, nwkatz
- last certified : 24 Aug 2026
nwcommands version 3.17.6, 9 November 2026 (check your installed version)