Stata Scalars

Scalars are a fundamental data type in Stata, like matrices.


Usage

Scalars are singular values.

To declare a scalar, try:

scalar define i = 1
scalar j = 2
scalar k = "Hello, world!"

Note the define subcommand can be omitted.

String scalars can hold arbitrarily long strings, and can also hold binary data.

To list all defined scalars, try scalar list _all or scalar dir _all.

To clear all scalars, try scalar drop _all.

Anonymous Scalars

To obtain a random, temporary name for a scalar that will never collide with an existing variable or scalar defined, try:

tempname myN
scalar `myN' = r(N)


CategoryRicottone

Stata/Scalars (last edited 2025-10-24 15:51:55 by DominicRicottone)