help for find_index

Determine the index (observation number) of an observation that satisfies a specified condition.

Syntax

find_index if exp, [low high verbose debug]

Options

low Return the lowest index value, if there are a multitude.

high Return the highest index value, if there are a multitude.

verbose Display the resulting value.

debug A synonym for verbose.

Remarks

Note that the if exp qualifier is required.

This command returns the observation number (the index) of the observation that
satisfies exp. By default, it requires that there be a unique observation that
satisfies exp, but the low and high options loosen this requirement.

If there are more than one observations that satisfy exp, then...

with the low option, the lowest observation number is returned;

with the high option, the highest observation number is returned;

in the absence of the low or high options, an error condition will occur.

If there are no observations that satisfy exp, then an error condition will occur,
regardless of any options.

The resulting value is returned in r(index).

Examples

. find_index if `age'== `age_low'

. local age_low_index = r(index)

. find_index if `age'== `age_high', `debug'

. local age_high_index = r(index)

...

. assert `age' == (_n + `age_low' - `age_low_index') in `age_low_index' / `age_high_index'

...

. gen double `U' = sum(`intergrandU') in `age_low_index' / `age_high_index'

. return scalar utility = `U'[`age_high_index']

. find_index if emplid == 3015987

. local emplid_index_3015987 = r(index)

. disp "emplid 3015987 name: " name[`emplid_index_3015987']

Author

David Kantor
Email kantor.d@att.net