⇤ ← Revision 1 as of 2023-01-13 21:49:59
Size: 787
Comment:
|
Size: 1027
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 53: | Line 53: |
To obtain a random, temporary name for a scalar that cannot collide with any variables or scalars defined in a dataset, try: {{{ tempname n1 n2 count if cohort==1 scalar `n1' = r(N) count if cohort==2 scalar `n2' = r(N) }}} |
Stata Scalars
Contents
Definition
To define a scalar, use the scalar define command. The define keyword can be left off.
scalar define i = 1 scalar j = 2 scalar k = "Hello, world!"
Scalar variables are accessed by their name.
generate double score = i * j
String Scalars
String scalars can hold arbitrarily long strings, and can also hold binary data.
Usage
To examine a scalar variable, try:
scalar dir i
Use scalar dir _all (or scalar list _all) to list the contents of all scalar variables.
To delete a scalar variable, try:
scalar drop i
Use scalar drop _all to delete all scalar variables.
To obtain a random, temporary name for a scalar that cannot collide with any variables or scalars defined in a dataset, try:
tempname n1 n2 count if cohort==1 scalar `n1' = r(N) count if cohort==2 scalar `n2' = r(N)