makevars

Purpose

Creates separate global vectors from the columns of a matrix.

Format

makevars(x, vnames, xnames)
Parameters:
  • x (NxK matrix) – columns to be converted into individual vectors

  • vnames (string or Mx1 character vector) – names of global vectors to create. If 0, all names in xnames will be used.

  • xnames (string or Kx1 character vector) – names to be associated with the columns of the matrix x

Examples

let x[3,3] = 101 35 50000
             102 29 13000
             103 37 18000;

// Names associated with x
xnames = { id, age, pay };

// Global variables to create
vnames = { age, pay };

// Create global variables
makevars(x, vnames, xnames);

print age;
35.00000
29.00000
37.00000

Two global vectors, called age and pay, are created from the columns of x.

let x[3,3] = 101 35 50000
             102 29 13000
             103 37 18000;

// Names associated with x
xnames = "id age pay";

// Global variables to create
vnames = "age pay";

// Create global variables
makevars(x, vnames, xnames);

print age;
35.00000
29.00000
37.00000

This is the same as the example above, except that strings are used for the variable names.

Remarks

If xnames = 0, the prefix X will be used to create names. Therefore, if there are 9 columns in x, the names will be X1-X9, if there are 10, they will be X01-X10, and so on.

If xnames or vnames is a string, the individual names must be separated by spaces or commas:

vnames = "age pay sex";

Since these new vectors are created at execution time, the compiler will not know they exist until after makevars() has executed once. This means that you cannot access them by name unless you previously clear them or otherwise add them to the symbol table. (See setvars() for a quick interactive solution to this.)

This function is the opposite of mergevar().

Globals

__vpad

Source

vars.src

See also

Functions mergevar(), setvars()