*!Version 1.2 28.09.2021

Title

multif - Constructs multiple if-restrictions with the same value for different variables.

Description

This command was developed out of the need to apply the same if-restriction like "!mi(VAR)" or "inrange(VAR,x,y)" to multiple variables.
Even with only a few variables, writing the if-restrictions can be quite error prone.
This command eases the construction of such restrictions for the variables supplied in varlist.
The command should work in the most common scenarios, but it does not check if the generated restriction(s) itself is/are valid.
A dialog file is provided to make the usage of this command easier.

Syntax

multif varlist ,condition() connection() [command() comoption() varid() addif() addcon() test display]

Options

condition() defines the if restrictions which should be applied to all variables in the list.

connection() defines the logical connector like "&, |" between different restrictions.

command() defines the command to be run with the created multiple if restrictions.

comoption() adds options to the command provided in the command() option.

varid() defines a different variable identifier used in the condition() option. The default value is "VAR".

addif() adds another if-restriction to the command option

addcon() connector for addif() option

test enables a test for equality of variable identifier in all restrictions with the supplied identifier

display displays the resulting restriction(s).

Options

Required options

condition() defines the if restrictions which should be applied to all variables in the list.

connection() defines the logical connector like "&, |" between different restrictions.

Additional options

command()	defines the command to be run with the created multiple if restrictions.

comoption() adds options to the command provided in the command() option.

varid()	defines a different variable identifier used in the condition() option. The default value is "VAR".

addif() adds another if-restriction to the command option.

addcon() connector for addif() option.

test enables a test for equality of variable identifier in all restrictions with the supplied identifier.

display displays the resulting restriction(s).

Examples

. use auto
. multif make price mpg, condition(!mi(VAR)) connection(&) command(count)
74
. display "`r(multif)'"
!mi(make) & !mi(price) & !mi(mpg)

. multif headroom price mpg, condition(!mi(v) & v>0) connection(&) command(count) varid(v) addif(price<6000) addcon(|) display
The resulting multiple restrictions expressions is:
!mi(headroom) & headroom>0 & !mi(price) & price>0 & !mi(mpg) & mpg>0 | price<6000

Saved results

multif saves the following in r():
Macro

r(multif) the multiple if-restrictions containing also the restriction provided by the addif() option.

Author

Sven-Kristjan Bormann

Bug Reporting

Please submit bugs, comments and suggestions via email to:	sven-kristjan@gmx.de

Further Stata programs and development versions can be found under https://github.com/skbormann/stata-tools

Known Bugs

The variable ID must be set correctly in all conditions, otherwise multif returns silently a condition which cannot be used further!
An experimental test for this scenario is available via the test option, but the test does not cover all potential errors yet.
This might be fixed in a next version.