I have a short .ado file to standardize string variables from multiple sources. The program takes one string variable, renames it with a suffix, then replaces the original variable with a standardized name.
But syntaxit does not handle the comma correctly after the string variable. That is, instead of transmitting, countryit transmits country,and gives an error.
Is space between varnameand required ,? Or do I have a misunderstanding of how I should use syntaxand varlist?
clear
set obs 10
generate country = "United States of America"
* runs fine without `suffix()` options
country_names country
list
* but gives error with `suffix()`
country_names country, suffix(_orig)
* `set trace on` reveals comma passed as part of `varlist`
set trace on
country_names country, suffix(_orig)
* if I leave space before comma, then program works
country_names country , suffix(_orig)
list
Here is the .ado file.
*! 0.1 Richard Herron 2/11/2014
program country_names
version 11.2
syntax varname(string) [, Suffix(string) ]
quietly {
if "`suffix'" == "" local suffix "_0"
rename `1' `1'`suffix'
/* first standardize capitalization */
generate `1' = proper(`1'`suffix')
replace `1' = "United States" ///
if inlist(`1', "United States Of America")
local name: variable label `1'`suffix'
label variable `1' "`name'"
label variable `1'`suffix' "`name' (orig)"
}
end
source
share