dummybr

Purpose

Creates a set of dummy (0/1) variables. The highest (rightmost) category is bounded on the right.

Format

y = dummybr(x, v)
Parameters:
  • x (Nx1 vector) – data that is to be broken up into dummy variables
  • v (Kx1 vector) – specifies the \(K\) breakpoints (these must be in ascending order) that determine the \(K\) categories to be used. These categories should not overlap.
Returns:

y (NxK matrix) – containing the \(K\) dummy variables. Each row will have a maximum of one 1.

Examples

// Set seed for repeatable random numbers
rndseed 135345;

// Create uniform random integers between 1 and 9
x = ceil(9*rndu(5, 1));

// Set the breakpoints
v = { 1, 5, 7 };

dm = dummybr(x, v);

The code above produces three dummies based upon the breakpoints in the vector v:

x <= 1
1 < x <= 5
5 < x <= 7

which look like:

     0 1 0       2
     0 0 0       9
dm = 0 1 0   x = 4
     0 0 1       7
     1 0 0       1

Remarks

  • Missings are deleted before the dummy variables are created.
  • All categories are open on the left (i.e., do not contain their left boundaries) and are closed on the right (i.e., do contain their right boundaries). Thus, \(K\) breakpoints are required to specify \(K\) dummy variables.
  • The function dummy() is similar to dummybr(), but in that function the highest category is unbounded on the right.

Source

datatran.src