nwtomata
Return the adjacency matrix of a network
Syntax
nwtomata
[netname]
,
mat(matamatrix)
mat(matamatrix) |
name of the new Mata matrix |
Description
This creates a Mata matrix with name matamatrix holding a copy of the adjacency matrix of a network.
You do not need to know Mata to use any of the nwcommands, but sometimes you might want to obtain the adjacency matrix, for example, when programming your own network commands.
When you make alterations to a Mata matrix derived from nwtomata you do not change the underlying network. It simply gives you a copy of the underlying matrix used to store the network. To make changes to this network use nwreplace or nwreplacemat.
The adjacency matrix of a network can also be displayed with:
. nwsummarize, mat
Advanced programmers who might want to directly interact with the adjacency matrix of a network and not with a copy of it, see advanced network programming.
Network types
The command works the same for every network type (see nwnetworktypes).
Example
. nwrandom 5, density(.2) name(net)
. nwtomata net, mat(mymat)
. mata: mymat
1 2 3 4 5
+---------------------+
1 | 0 0 0 0 0 |
2 | 0 0 1 0 0 |
3 | 0 0 0 1 0 |
4 | 0 1 0 0 0 |
5 | 1 0 0 0 0 |
+---------------------+
Stored results
- Macros
- r(netname) — name of the network
- r(adj_copy) — name of the new Mata matrix
- r(adj) — Mata expression for the network’s own matrix (see nwtomatafast)
- r(netobj) — name of the Mata network object
See also
nwcommands version 3.25.0, 14 November 2026 (check your installed version)