help ntwrkntwrk v1.0 (beta) (GitHub)

ntwrk

: is a Stata package for network analysis and visualization from edge-list data.

Syntax

ntwrk value [if] [in] , from(varname) to(varname)
[network measures] [parameters]
[network layout]
[link options] [arc options]
[node options]
[save and export options]

Options

Required

value Numeric link-value variable. Repeated (from, to) pairs are collapsed by summing this variable before analysis and plotting.

from(varname) Source-node variable. String and numeric identifiers are both supported.

to(varname) Target-node variable. String and numeric identifiers are both supported.

Network measures

measure(names) List of node measures to compute. Valid names are degree, between, indegree, outdegree, closeness,
harmonic, clustering, transitivity, eccentricity, eigenval, eigenvec, katz, pagerank, hits, core, reciprocity, ancestors, and descendants.
If multiple measures are generated then it is highly recommended to save the network data.

weighted Use weighted links for supported centrality routines. Without this option, statistics are computed on the binary directed graph. Clustering and transitivity remain topology-based.

directedclustering Use directed triangle logic for clustering. If omitted, local clustering is computed with undirected-style neighbor closure (direction ignored for triangle counting).

Measures:

degree Total degree computed as indegree + outdegree on the directed graph. degree is calculated by default.

indegree In-degree count on the directed graph (number of incoming neighbors).

outdegree Out-degree count on the directed graph (number of outgoing neighbors).

between Compute normalized betweenness centrality.

closeness Compute inbound-reach closeness centrality (distances are evaluated on the reversed directed graph).

harmonic Compute inbound harmonic centrality (distances are evaluated on the reversed directed graph).

clustering Compute local clustering coefficient. Neighbor links are treated as connected if either direction exists.

transitivity Compute global transitivity. Neighbor links are treated as connected if either direction exists.

eccentricity Compute node eccentricity on a symmetrized topology as the maximum finite path length from each node.

eigenval Compute iterative spectral centrality (power iteration), controlled by iterations() and tolerance().

eigenvec Compute leading-eigenvector centrality.

katz Compute Katz centrality. Use katzalpha() to set the attenuation parameter; default is katzalpha(0.1) (beta is fixed at 1).

pagerank Compute PageRank. Current fixed damping is 0.85; iterations() and tolerance() govern convergence checks.

hits Compute HITS hub and authority scores. iterations() and tolerance() govern convergence checks.

core Compute undirected core number (k-core index) for each node using the symmetrized topology.

reciprocity Compute node-level reciprocity, capturing the share of each node's incident directed ties that are mutual.

ancestors Compute number of nodes that can reach each node via directed paths.

descendants Compute number of nodes reachable from each node via directed paths.

Parameters

iterations(num) Maximum iterations for iterative routines. Default is iterations(100).

tolerance(num) Convergence tolerance. Default is tolerance(1e-6).

katzalpha(num) Katz attenuation parameter used when katz is requested. Default is katzalpha(0.1).

radius(num) Radius used by the layout(star) layout. Default is radius(5).

Layout options

layout(star) Places nodes around a circle. Controlled by radius() before normalization. Deterministic.

layout(fr) Fruchterman-Reingold force layout (spring-electrical). Uses random initialization, iterations(), width(), height(). Use seed() for reproducibility.

layout(sphere) Fibonacci-style sphere sampling projected to 2D. Useful for spreading many nodes; deterministic.

layout(grid) Regular row-column placement over the target frame. Deterministic and fast for large node counts.

layout(random) Uniform random placement in the target frame. Use seed() for reproducibility.

layout(spectral) Uses Laplacian eigenvectors (2nd/3rd) from a symmetrized adjacency matrix. Often separates weakly connected groups; deterministic for a fixed graph.

layout(kk) Kamada-Kawai spring embedder using all-pairs shortest-path distances. Uses iterations() and tolerance() for optimization stopping.

layout(bipartite) Two-column layout: source-like nodes on the left, pure targets on the right (fallback split by outdegree vs indegree if needed). Good for sender-receiver structures.

layout(shell) Two-shell circular layout where higher-degree nodes are placed on the inner shell and remaining nodes on the outer shell. Deterministic.

layout(spiral) Nodes placed sequentially along an outward spiral from the center. Deterministic and useful for highlighting node ordering or connectivity patterns.

seed(num) Random seed applied before computation. This affects stochastic components such as layout(fr) and layout(random).

width(num), height(num) Target frame dimensions. Defaults are width(150) and height(150).

Link options

lquantile(num) Number of link quantile classes for color/width grouping. Default is lquantile(5).

lcolor(str) Color for links. If omitted, color is assigned by lpalette().

lwidth(num) Base line-width multiplier. Default is lwidth(0.5).

llabsize(str) Link-label size for edge-value labels. Default is llabsize(1.2).

llabcolor(str) Link-label text color. Default is llabcolor(black).

lalpha(num) Link transparency. Default is lalpha(80).

reduce(num) Trim link endpoints by a fixed length before drawing. Default is reduce(0).

lscale Enable quantile-based link width scaling. Without this option, all links use constant lwidth().

lscalefactor(num) Exponent used in link width scaling when lscale is on. Default is lscalefactor(0.3333).

lprop Accepted by the parser for proportional link styling, but currently has no distinct effect beyond the existing quantile-based link scaling options.

lpropfactor(num) Accepted with lprop; currently reserved and has no distinct effect in the plotting routine.

lpalette(str) Color palette for links via colorpalette. The default is eltblue.

Arc options

arc Draw links as curved arcs instead of straight arrows. Arcs inherit link properties where necessary.

arcn(num) Number of sampled points used per arc. Default is arcn(40).

arcradius(num) Arc radius passed to the arc routine. Controls curvature when arc is specified. This is an advanced option and should ideally not be touched.

arrowsize(num) Arrowhead size. Default is arrowsize(1.2).

Node options

mquantile(num) Number of node quantile classes. Default is mquantile(5).

mvar(varname) Variable used for node quantile assignment (node color classes). If omitted, node classes are based on the selected node metric, which defaults to degree.

mcolor(str) Fill color for node circles. If omitted, color is assigned by mpalette().

msize(num) Base node size. Default is msize(5).

mlabsize(str) Node-label size. Default is mlabsize(1.6).

mlabcolor(str) Node-label text color. Default is mlabcolor(black).

malpha(num) Node fill transparency. Default is malpha(80).

mlapha(num) Node outline transparency. Default is mlalpha(100). This lets you control fill and outline alpha separately.

msymbol(str) Reserved marker-symbol option. Node areas are currently drawn as circle polygons and labels are drawn separately.

mscale Enable node-size scaling. Without this option, all nodes use constant msize().

mscalefactor(num) Exponent used in node scaling when mscale is on. Default is mscalefactor(0.3333).

mlcolor(str) Outline color for node circles. If omitted, the outline follows the node fill color.

mlwidth(num) Outline width for node circles. Default is mlwidth(0.08).

mprop Accepted by the parser for proportional node styling. In the current plotting routine it primarily affects palette handling; node sizes remain controlled by msize, mscale, and mscalefactor().

mpropfactor(num) Accepted with mprop; currently reserved and has no distinct effect in the plotting routine. Default is mpropfactor(0.3333).

mpalette(str) Color palette for node fills via colorpalette. Current defaults are gs12 without mprop, and cividis with mprop.

mrotate(num) Rotation angle applied to node labels (in degrees). Default is mrotate(0).

mpoints(num) Number of points used to draw node circles as polygons. Minimum is mpoints(3). Controls the smoothness of circular node visualization.

Output and export

save Export generated link/node coordinates and attributes to disk as saveprefix.dta.

replace Allow the exported dataset to overwrite an existing file when save is specified.

saveprefix(str) Prefix for the exported dataset filename. If omitted with save, the default prefix is _network.

nograph Skip plotting but still allow dataset export when save is specified.

novalues Suppress edge-value labels.

valcondition(num) Suppress edge-value labels for links with values less than or equal to this threshold. Default is valcondition(0).

format(str) Numeric display format applied to edge-value labels in the graph (including curved labels when arc is used). Default is format(%9.2f).

* Pass standard twoway options not elsewhere specified.

Dependencies

ssc install palettes, replace
ssc install colrspace, replace
ssc install graphfunctions, replace

Examples

See GitHub for examples.

Feedback

Please submit bugs, errors, feature requests on GitHub by opening a new issue.

Package details

Version : ntwrk v1.0 (beta)
This release : 17 Jun 2026
First release: 17 Jun 2026
Repository : GitHub
Keywords : Stata, networks, graphs
License : MIT

Author : Asjad Naqvi
E-mail : asjadnaqvi@gmail.com
Twitter : @AsjadNaqvi

Citation guidelines

Use the package details above and repository URL for software citation until an SSC citation entry is assigned for this package name.

References

Jann, B. (2018). Color palettes for Stata graphics. The Stata Journal 18(4): 765-785.

Jann, B. (2022). Color palettes for Stata graphics: An update. University of Bern Social Sciences Working Papers No. 43.

Grund, T. (2014). nwcommands. Social network analysis in Stata.

Aric A. Hagberg, Daniel A. Schult and Pieter J. Swart, "Exploring network structure, dynamics, and function using NetworkX", in Proceedings of the 7th Python in Science Conference (SciPy2008), Gäel Varoquaux, Travis Vaught, and Jarrod Millman (Eds), (Pasadena, CA USA), pp. 11–15, Aug 2008. networkx.

Other visualization packages

arcplot, alluvial, bimap, bumparea, bumpline, circlebar, circlepack, clipgeo, delaunay, graphfunctions,
geoboundary, geoflow, joyplot, marimekko, ntwrk, polarspike, sankey, schemepack, spider, splinefit, streamplot,
sunburst, ternary, tidytuesday, treecluster, treemap, trimap, waffle, vcontrol

Visit GitHub for further details.