sel_char
Title
sel_char - This command is used for short description.
Syntax
sel_char querystring varlist(varlist)
options | Description |
---|---|
varlist(varlist) | Specify a subset of current variables to search |
Description
This command allows the user to filter variables based on values in chars. It will return a local in r(varlist)
with all variables that matches the query string. See the examples below for instructions on how to specify the querystring.
Options
varlist(varlist) allows the user to specify a subset of the variables in the data set to filter on. The default is that the command filter on all variables in the current data set. With varlist(varlist), the scope of the search can be narrowed. This narrower variable list could come, for example, from other commands in selector
.
Stored results
If the command is set to only filter on one char name, then the command stores the following results in r()
:
r-macro | Description |
---|---|
varlist |
The list of variables which char values matched the filtering criteria |
match_count |
The number of variables in varlist |
If two or more char values are used to filter, then for each char, these results are also store in r()
. These stored results is intended to be helpful when doing a complex filtering and the users do not get the result they expected. Then this information may be useful in debugging purposes:
r-macro | Description |
---|---|
char* |
The name of the char |
char*_value |
The char value used to filter on |
has_char* |
The list of variables that had this char regardless of what value |
has_char*_count |
The number of variables in has_char* |
match_char* |
The list of variables that had this char and the value matched char*_value |
match_char*_count |
The number of variables in match_char* |
Examples
Example 1
In this example a second price varible is created. The currency used for the variables is stored in the char
value “currency”. Then sel_char
is used to list all variables that has the value “USD” in the char
“currency”.
sysuse auto, clear
char price[currency] "USD"
gen price_eur = price * .9
char price_eur[currency] "EUR"
sel_char "currency USD"
return list
Example 2
You can combine multiple char
values to filter your variable list further. When combining multiple chars the command returns data on the filtering on each char
.
sysuse auto, clear
char price[currency] "USD"
gen price_eur = price * .9
char price_eur[currency] "EUR"
char price[raw] "1"
char price_eur[raw] "1"
sel_char "raw 1" "currency USD"
return list
Example 3
This example is synonymous with example 2, as the variable list that is a result of the first run of sel_char
is passed into the varlist()
option in the second run of sel_char
. This can be especially useful when combining this command with other commands in the selector package.
sysuse auto, clear
char price[currency] "USD"
gen price_eur = price * .9
char price_eur[currency] "EUR"
char price[raw] "1"
char price_eur[raw] "1"
sel_char "raw 1"
sel_char "currency USD" , varlist(`r(varlist)')
return list
Feedback, Bug Reports, and Contributions
Read more about these commands on this repo where this package is developed. Please provide any feedback by opening an issue. PRs with suggestions for improvements are also greatly appreciated.