*! version 1.2 Nov2022

Title

inlist2 -- Creates an inlist() dummy, without inlist() limitations

Syntax

inlist2
varname [if] [in] [, options]

where varname is the variable values are listed from.

options

Main
values(a,b,c,...) all arguments must be reals or all must be strings. If strings, values are space and case sensitive (e.g. "new york"!=" new york"!="New York"). Strings CANNOT have commas as characters

Other
name(string) saves the inlist2 dummy as "string", default is "inlist2"

verbose sets off the "quietly" in the dummy creation

Description

inlist2 generates a dummy equal 1 if varname is equal to the arguments in values(), 0 otherwise.

inlist2 provides a faster way to link multiple "|" operators, similarly to inlist, by creating a dummy variable named inlist2 to be used in successive steps. Inlist2's string values do not require quotation marks (e.g. in case of spaces within the string) so they are faster to write, also, inlist2 does not have a 10 arguments limit for strings or a 250 arguments limit for reals. Inlist2 automatically distinguishes if the variable is a real or a string, but does not allow for commas in strings. Inlist2 does not give error massages if the variable does not have one of the values in the list, but one can check if the replacement is working correctly by looking at the output with the verbose option.
Feedback is greatly appreciated.

Examples of usage

Load data.

. sysuse auto, clear

Want to summarize the price of the first 11 car models, sorted alphabetically. inlist() function only allows 10 strings.

. inlist2 make, values(AMC Concord,AMC Pacer,AMC Spirit,Audi 5000,Audi Fox,BMW 320i,Buick Century,Buick Electra,Buick LeSabre,Buick Opel,Buick Regal)

. sum price if inlist2==1

The program overwrites the inlist2 variable every time it is executed, var can be saved with a specific name with the name() option.

. inlist2 make, values(AMC Concord,AMC Pacer,AMC Spirit,Audi 5000,Audi Fox,BMW 320i,Buick Century,Buick Electra,Buick LeSabre,Buick Opel,Buick Regal) name(first11)

. sum price if first11==1

Works similarly for reals.

. inlist2 rep78, values(3,2) name(repair_record23)

. sum price if repair_record23==1

Author

Matteo Pinna

matteo.pinna@gess.ethz.ch

Acknowledgements

The author would like to thank Allison Reichel for the input to create the program and Mead Over for proposing the additions to the command's version 1.2.