nwcomponents

Network components and the largest component

Syntax

nwcomponents 
[netlist]
[, lgc
generate(newvarname)
replace
silent
listall]
   
generate(newvarname) Required. Name of the Stata variable that stores information about components (component membership, or largest-component membership if lgc is given)
replace Replace existing variable
lgc Calculate membership to largest component
silent Suppress display of results
listall Print the full table of components; by default at most the first 30 rows are printed, with a note. Results in r() are unchanged

Description

Calculate the components of a network or a list of networks. A component is a set of nodes that are only connected among each other. All calculations are performed on the undirected network. Nodes can only belong to one component.

generate() is required and names the new variable that stores the component membership. When option lgc is specified, the command instead stores in that variable information about membership to the largest component.

Examples

. nwwebuse florentine, nwclear
. nwcomponents flomarriage, generate(_component)

----------------------------------------
  Network name: flomarriage
  Components: 2

 _component |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |         15       93.75       93.75
          2 |          1        6.25      100.00
------------+-----------------------------------
      Total |         16      100.00

This shows that there are two components in the Florentine marriage network. All except one node belong to the first component. Some alternative ways how the commands can be used.

. nwwebuse glasgow
. nwcomponents glasgow1, generate(mycomponent)
. nwcomponents _all, lgc generate(_lgc)
. nwcomponents _all, lgc generate(mylgc)

Supported network types

Binary: yes (only) - component membership is a structural (weak-connectivity) property, tie values are ignored. Directed: yes - uses weak connectivity (ignores tie direction), matching the standard convention for “components” on a directed graph. Weighted: not applicable. Signed: not applicable. Two-mode: same as for the bipartite graph read as a one-mode network (valid; no mode-specific normalisation).

Stored results

Scalars

  • r(components) number of components

Matrices

  • r(comp_sizeid) distribution over components

See also


nwcommands version 3.17.6, 9 November 2026 (check your installed version)


Back to top

nwcommands is free software under the GNU General Public License, version 3, as are the model packages nwsaom, nwergm, nwdynam and nwrem. Citing and licenses · Get help · GitHub. Issues with the core go to the nwcommands repository; issues with a model package go to that package's own repository.

This site uses Just the Docs, a documentation theme for Jekyll.