Hi everyone
Everyone now and then, I find myself searching for specific text inside the data set. While Stata has many built-in functions to search and match text, I find it cumbersome to type the required syntax. For my convenience, I have written a program, searchfor which I want to share with others as well. I hope it will be of some help to others. The program can be installed from SSC
Following are the details and example of how to use it.
-------------------------------------------------------------------------------------------------------------------------------------
Title
searchfor - Searches for texts in selected or all string variables
Syntax
searchfor TEXT , in(varlist) edit(varlist) list(varlist)
Description
This program finds text in string variables and either lists the selected variables
on screen or edits the variables in Data Editor. The search text is capitalization free.
Syntax Details
The program has 3 options: They are
1. in : to select string variables in which the text will searched for. If left empty, the desired text will be searched in all
string variables.
2. edit: This option will edit selected variables in the Data Editor in instances where the search result is true
3. list: This option will list selected variables in instances where the search result is true;
Example 1: Find Text in all String Variables
. sysuse census.dta
. searchfor Alabama
. searchfor Alab
. searchfor ALAB
Example 2: Show Selected Variables Where searchfor Finds Matching string
. searchfor Alabama, list(state state2 region pop)
Example 3: Find Text in Selected String Variables
. searchfor Alabama, in(state)
This will search for Alabama in the variable 'state' only
. searchfor Alabama, in(state) list(state state2 region pop)
Example 4: Find Text in Selected String Variables and Edits Selected variables
. searchfor Alabama, in(state) edit(state state2 region pop)
This will search for Alabama in the variable 'state' only and edit state, state2, region, and pop variables in the editor
window where the search finds a match
Author
:::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::: *
* *
* Dr. Attaullah Shah *
* Institute of Management Sciences, Peshawar, Pakistan *
* Email: [email protected] *
*::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::*
Everyone now and then, I find myself searching for specific text inside the data set. While Stata has many built-in functions to search and match text, I find it cumbersome to type the required syntax. For my convenience, I have written a program, searchfor which I want to share with others as well. I hope it will be of some help to others. The program can be installed from SSC
Code:
ssc install searchfor
-------------------------------------------------------------------------------------------------------------------------------------
Title
searchfor - Searches for texts in selected or all string variables
Syntax
searchfor TEXT , in(varlist) edit(varlist) list(varlist)
Description
This program finds text in string variables and either lists the selected variables
on screen or edits the variables in Data Editor. The search text is capitalization free.
Syntax Details
The program has 3 options: They are
1. in : to select string variables in which the text will searched for. If left empty, the desired text will be searched in all
string variables.
2. edit: This option will edit selected variables in the Data Editor in instances where the search result is true
3. list: This option will list selected variables in instances where the search result is true;
Example 1: Find Text in all String Variables
. sysuse census.dta
. searchfor Alabama
. searchfor Alab
. searchfor ALAB
Example 2: Show Selected Variables Where searchfor Finds Matching string
. searchfor Alabama, list(state state2 region pop)
Example 3: Find Text in Selected String Variables
. searchfor Alabama, in(state)
This will search for Alabama in the variable 'state' only
. searchfor Alabama, in(state) list(state state2 region pop)
Example 4: Find Text in Selected String Variables and Edits Selected variables
. searchfor Alabama, in(state) edit(state state2 region pop)
This will search for Alabama in the variable 'state' only and edit state, state2, region, and pop variables in the editor
window where the search finds a match
Author
:::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::: *
* *
* Dr. Attaullah Shah *
* Institute of Management Sciences, Peshawar, Pakistan *
* Email: [email protected] *
*::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::::::*
Comment