nwcorrelate
Correlate networks and variables
Syntax
1) Correlate nodes of a network
nwcorrelate
netname
[,
context(context)
name(newnetname)
undirected directed]
2) Correlate two networks with each other
nwcorrelate
netname1
netname2
[,
permutations(int)
save(filename)
kdensity_options]
3) Correlate one network and one variable
nwcorrelate
netname
,
attribute(varname)
[mode(expand_mode)
name(newnetname)
keepexpand
permutations(int)
save(filename)
kdensity_options]
context(context) |
Determines whether incoming or outgoing ties should be considered when correlating two nodes; default = outgoing |
name(newnetname) |
Name of new network with node correlations; default = _corr |
mode(expand_mode) |
How to expand the attribute variable |
keepexpand |
Keep the network generated by nwexpand |
permutations(integer) |
Number of QAP permutations; default = 1 (no permutation test) |
save(filename) |
Save (the name may be quoted and contain spaces; the full path is printed) the QAP permutation results in a Stata dataset with the variables correlation (one row per permutation) and observed (the observed correlation, repeated in every row); needs permutations() of more than 1 |
undirected, directed |
Node-correlation mode: store the correlation network as undirected or directed (options of nwset) |
force |
Run the command although its matrices would not fit in memory (it stops with r(484) above about 12,900 nodes otherwise) |
Description
This command is the network version of correlate. It can be used in three different ways:
1) Correlate nodes of a network
2) Correlate two networks with each other
3) Correlate one network and one variable
The option permutation() creates QAP permutations of the first network and generates a distribution of correlation coefficients under the null-hypothesis that there is no correlation. In practice, rows and columns of netname are reshuffled and the correlation coefficient is calculated again and again. Based on this distribution a p-value and a confidence interval is calculated. A plot is displayed and additional information is returned in the return vector.
Supported network types
Binary: yes. Directed: yes, via context(incoming|outgoing|both) for the node-correlation mode. Weighted: yes, natively - uses raw tie values throughout, no dichotomize option. Signed: not checked. Two-mode: not supported - error 6088; the correlation of the profiles of the nodes of ONE network reads the empty blocks between nodes of the same mode (nwsimilar, type(pearson) correlates the profiles over the other mode); two networks are correlated as for any pair of networks.
Stored results
Node correlations
- Scalars:
-
r(avg_corr) average correlation coefficient between nodes
- Macros:
- r(name) name of network
- r(corrname) name of new network with coefficients
Two networks or one network and one attribute
- Scalars:
- r(corr) correlation coefficient
- r(pvalue) two-sided Monte Carlo p-value of the correlation, 2(1 + k)/(R + 1) with k the number of the R permutations in the smaller tail (never 0; at most 1)
- r(ub) upper bound, 95% confidence interval
-
r(lb) lower bound, 95% confidence interval
- Macros:
- r(name_1) name of netname1
- r(name_2) name of netname2 or the expanded network
References
Granovetter, M. (1973). The strength of weak ties. American Journal of Sociology 78(6), 1360-1380.
Zachary, W. (1977). An information flow model for conflict and fission in small groups. Journal of Anthropological Research 33, 452-473.
See also
-
last certified : 24 Aug 2026
nwcommands version 3.17.6, 9 November 2026 (check your installed version)