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.

Network types

The command works the same for every network type (see nwnetworktypes).

Limits

Every column of the matrix becomes a Stata variable, so the number of columns is limited by what the flavour of Stata allows (2,048 variables in Stata/BE, 32,767 in Stata/SE). The command checks this first and stops with r(900) and a message instead of failing half way; use the Mata matrix (nwtomata) for larger networks.

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

Stored results

  • Scalars
  • r(rows) — number of rows of matamatrix
  • r(cols) — number of columns of matamatrix (with stub())

See also


nwcommands version 3.25.0, 14 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.