nwtostata

Copy a Mata matrix into Stata variables

Syntax

nwtostata
,
mat(matamatrix)
(gen(namelist) | stub(string))
   
mat(matamatrix) name of the Mata matrix to copy into Stata variables
gen(namelist) one new Stata variable name per column of matamatrix
stub(string) generate columns as stub1, stub2, … instead of naming them individually

Description

nwtostata is the reverse of nwtomata: it copies an existing Mata matrix matamatrix into new Stata variables, one column per variable, one row per observation (creating additional observations if the dataset does not already have enough). Exactly one of gen() or stub() must be specified - gen() names each new variable individually (one name per column of matamatrix); stub() instead generates however many stub1, stub2, … columns are needed to hold every column of matamatrix.

This is a low-level utility for programmers moving data between Mata and Stata directly; ordinary use of the package does not need it - see nwtomata/nwload for the normal way to bring a network’s own data into Stata.

Examples

. mata: m = (1,2 \ 3,4 \ 5,6)
. nwtostata, mat(m) gen(a b)
. list

. mata: m = (1,2 \ 3,4 \ 5,6)
. nwtostata, mat(m) stub(col)
. list

Supported network types

Not applicable - nwtostata copies an arbitrary, already-existing Mata matrix into Stata variables and has no notion of a network or its properties; any directed/weighted/signed/two-mode handling happened whenever matamatrix was itself produced.

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.