*! version 1.0.2 PS/PR 25Apr96.
* mkname1 var , prefix() checkin() banned() noclear
program define mkname1
version 4.0
local varlist "req ex min(1) max(1)"
local options "Prefix(string) Checkin(string) BANned(str) noCLear"
parse "`*'"
if "`prefix'"=="" | length("`prefix'")>7 {
	di in red "invalid prefix()"
	exit 198
}
if "`checkin'"!=""{
	if index("`checkin'","`varlist'") == 0 {
		di in red "`varlist' not in check list"
		exit 111
	}
}
local l=8-length("`prefix'")
local i 0
local new ="`prefix'"+substr("`varlist'",1,`l')
local rc = index("`banned'","`new'")
if "`clear'"!=""{
	capture confirm new var `new'
	local rc2=_rc
}
else local rc2 0
while (`rc2' | `rc') & length("`new'")<9 {
	local i=`i'+1
	local new "`prefix'`i'"
	local rc = index("`banned'","`new'")
	if "`clear'"!=""{
		capture confirm new var `new'
		local rc2=_rc
	}
}
if length("`new'")>8 {
  di in red "Unable to create unique name. " in blue "Try shorter prefix."
	exit
}
global S_1 `new'
end