help mata aandb()

Title

aandb() -- Manipulate row vectors

Syntax

transmorphic rowvector
aandb(transmorphic rowvector a,
transmorphic rowvector b)

real rowvector
_aandb(transmorphic rowvector a,
transmorphic rowvector b)

transmorphic rowvector
adups(transmorphic rowvector a)

real scalar
aequivb(transmorphic rowvector a,
transmorphic rowvector b)

real scalar
ainb(transmorphic rowvector a,
transmorphic rowvector b)

transmorphic rowvector
anotb(transmorphic rowvector a,
transmorphic rowvector b)

transmorphic rowvector
aorb(transmorphic rowvector a,
transmorphic rowvector b)

real rowvector
aposb(transmorphic rowvector a,
transmorphic rowvector b)

real rowvector
_aposb(transmorphic rowvector a,
transmorphic rowvector b)

transmorphic rowvector
auniq(transmorphic rowvector a)

real rowvector
_auniq(transmorphic rowvector a)

where both a and b must be of type real or string

Description

These functions mimic some of Stata's
macro list functions.

aandb(), read: a and b, returns the elements of a
that are found in b. The result is equivalent to Stata's
list a & b.

_aandb() returns a row vector indicating the elements of a
that are found in b.

The function has an optional third argument, uniq, that specifies
how repeated values in a are matched. If uniq!=0 (the default),
elements in b are treated as unique, meaning that repeated elements
in a are matched at most once. If uniq=0, repeated elements in
a may be matched by the same element in b. For example, if
a = (42, 73, 42, 73) and b = 42, _aandb(a, b) returns
(1, 0, 0, 0) while _aandb(a, b, 0) returns (1, 0, 1, 0).

adups() returns the duplicate elements of a, omitting the first
occurrence. The result is equivalent to Stata's list dups a.

aequivb() returns 1 if a has the same elements as b. The
result is equivalent to Stata's list a === b.

ainb(), read: a in b, returns 1 if all elements of
a are found in b, or if cols(a)==0; otherwise
the function returns 0. The result is equivalent to Stata's
list a in b.

anotb(), read: a not b, returns the elements of a
not found in b. The result is equivalent to Stata's
list a - b.

aorb(), read: a or b, returns the elements found in
a or b; the function adds to a the elements
of b not found in a. The result is equivalent to Stata's
list a | b.

aposb() returns a row vector of column indices that indicate
the positions in b where a occurs. If a is a vector,
its starting position in b is returned. If b does not
contain a, the function returns 0.

_aposb() returns a row vector indicating the positions in b
where a occurs.

The function has an optional third argument, disjoint, that specifies
how repeated (or overlapping) occurences of a in b are matched. If
disjoint!=0 (the default), repeated occurences of a are mateched
at most once. If disjoint=0, repeated occurences of a in b
are matched repeatedly. For example, if a = (1, 0, 1) and
b = (1, 0, 1, 0, 1), _aposb(a, b) returns (1, 0, 0, 0, 0)
while _aposb(a, b, 0) returns (1, 0, 1, 0, 0).

auniq() returns the distinct elements of a; elements in the
returned row vector are unique. The result is equivalent to Stata's
list uniq a.

_auniq() returns a row vector indicating the distinct elements
of a.

Conformability

aandb(a, b)
a: 1 x c1
b: 1 x c2
result: 1 x c3, c3<=c1

_aandb(a, b)
a: 1 x c1
b: 1 x c2
result: 1 x c1

adups(a)
a: 1 x c1
result: 1 x c2, c2<c1

aequivb(a, b)
a: 1 x c1
b: 1 x c2
result: 1 x 1

ainb(a, b)
a: 1 x c1
b: 1 x c2
result: 1 x 1

anotb(a, b)
a: 1 x c1
b: 1 x c2
result: 1 x c3, c3<=c1

aorb(a, b)
a: 1 x c1
b: 1 x c2
result: 1 x c3, c3>=c1

aposb(a, b)
a: 1 x c1
b: 1 x c2
result: 1 x c3, c3>=1

_aposb(a, b)
a: 1 x c1
b: 1 x c2
result: 1 x c2

auniq(a, b)
a: 1 x c1
result: 1 x c2, c2<=c1

_auniq(a, b)
a: 1 x c1
b: 1 x c2
result: 1 x c1

Diagnostics

_aandb(), if cols(a)==0 and
cols(b)==0, returns J(1, 0, 1); if
cols(b)!=0 or if the types of a and b
are different, the function returns J(1, cols(a), 0).

_aposb(), if cols(a)==0 and
cols(b)==0, returns J(1, 0, 1); if
cols(b)!=0 or if the types of a and b
are different, the function returns J(1, cols(b), 0).

_auniq(), if cols(a)==0, returns
J(1, 0, 1). Otherwise, _auniq() is implemented in terms
of _distinctrowsof().

All other functions are implemented in terms of
select(...,
_aandb(...)),
select(...,
_aposb(...)), or
select(...,
_auniq(...)).

Source code

Distributed with the elabel package.

Author

Daniel Klein

University of Kassel

klein.daniel.81@gmail.com

Also see

Online: mata, macro lists