nwsmall
Generate a small-world network
Syntax
nwsmall
nodes
,
k(int)
prob(float)
[weights(p1, p2,...)
undirected
ntimes(int)
name(newnetname)
labs(lab1,lab2,...)
xvars]
nwsmall
nodes
,
k(int)
shortcuts(integer)
[weights(p1, p2,...)
undirected
ntimes(int)
name(newnetname)
labs(lab1,lab2,...)
xvars]
nodes |
number of nodes |
k(int) |
number of neighbors on ring-lattice on each side |
prob(float) |
probability for a tie to rewire |
shortcuts(int) |
exact number of ties to rewire |
weights(p1, p2,...) |
probabilities p_k for tie weights k |
undirected |
generate an undirected network; default = directed |
ntimes(int) |
number of small-world networks to be generated; default = 1 |
name(newnetname) |
name of the new network; default = small |
labs(lab1,lab2,…) |
overwrite node labels (separated by commas) |
xvars |
generate Stata variables for the network |
noreplace |
reserved; currently a no-op - the create/replace collision guard on name() already applies regardless |
Description
nwsmall generates a (un-)directed, (un-)weighted small-world network using the original Watts-Strogatz model (see Watts and Strogatz 1998). The algorithm starts with a ring-lattice where each node has k neighbors on each side. Next, the ties of the ring-lattice are rewired in one of two ways:
1) When option prob() is specified, each tie of the ring-lattice has a certain probability to get rewired. All non-existent ties are valid as rewirings (including the ones produced through previous rewirings).
2) When option shortcuts() is specified, an exact number of ties of the ring-lattice gets rewired. In this algorithm, only ties that had not been in the original ring-lattice are valid rewirings.
Either option prob() or shortcuts() needs to be specified.
With option weights(p1, p2,…) the command generates a weighted network. Here, p_k stands for the probability to sample tie weight k. The probabilities p1, p2…, pn do not necessarily have to sum up to one; they are standardized. For example, the following produces a small-world network with 20 nodes. Furthermore, each one of these sampled ties gets assigned a tie weight because of option weights(). In this case, weights(0.0, 0.3,0.7) indicates that tie weight 1 should be sampled with probability 0.0, tie weight 2 with probability 0.3 and tie weight 3 with probability 0.7.
. nwsmall 20, k(2) prob(.2) weights(0.0, 0.3, 0.7)
Network types
Directed: directed by default; undirected gives an undirected network. Valued: weights() draws tie values. Two-mode: not applicable - the command always creates a one-mode network. Signed: not checked. See nwnetworktypes.
Limits
Above 2,000 nodes the ties are kept in a hash and written as a list, with the same draws as the matrix version (the same seed gives the same network). 20,000 nodes with k(5): 1 second. weights() uses the matrix.
Examples
In the first example, each tie on the ring-lattice has a probability to get rewired.
. nwclear
. nwsmall 20, k(2) prob(.2)
. nwplot, layout(circle)
In the second example, there are exactly three shortcuts.
. nwsmall 30, k(2) shortcuts(3) undirected
. nwplot, layout(circle)
Stored results
-
nwsmall stores the following in r():
- Macros
- r(netlist) — list of new networks
References
Watts, D. J., Strogatz, S. H. (1998). Collective dynamics of ‘small-world’ networks. Nature 393(6684), 440-442.
See also
nwcommands version 3.25.0, 14 November 2026 (check your installed version)