How to use strmatch command in Stata |
How to use strmatch command in Stata.
The command strmatch is match two string patterns. The syntax of strmatch is:
strmatch(s1,s2)
Description: 1 if s1 matches the pattern s2; otherwise, 0
strmatch("17.4","1??4") returns 1.
How to use strmatch command in Stata |
Wildcards in Stata
In s2, "?" means that one character goes here, and "*" means that zero or more bytes go here. Note that a Unicode character may contain multiple bytes; thus, using "*" with Unicode characters can infrequently result in matches that do not occur at a character boundary.
How to use strmatch command in Stata |
Generate bank name variable
We have a sample dataset consist of company name, bank name, shop name in one variable. If we want to extract the bank name, shop name and company into tree variables we need the command strmatch to help. Please download the sample dataset here.
Firstly we generate the variable bank
gen bank = com_name if strmatch(com_name,"ທະນາຄານ*")
How to use strmatch command in Stata |
Generate shop name variable
Next generate the shop name variable;
gen shop = com_name if strmatch(com_name,"ຮ້ານ*")
How to use strmatch command in Stata |
Generate company name variable
gen company = com_name if strmatch(com_name, "ບໍລິສັດ*")
How to use strmatch command in Stata |
Comments
Post a Comment