*! version 1.0.0  02/02/93  STB-13: dm13.1
program define replword
	version 3.0
	local old "`1'"
	local new "`2'"
	local n "`3'"
	if "`3'"=="" { error 198 }
	mac shift
	mac shift
	mac shift
	local varlist "req ex max(1)"
	local if "opt"
	local in "opt"
	parse "`*'"

	if "`n'"=="." { local n 100 }
	confirm integer number `n'
	if `n'==0 { exit }

	if "`old'"=="" { error 198 }

	tempvar res
	quietly {
		local type : type `varlist'
		local d=min(real(substr("`type'",4,.))+2,80)
		gen str`d' `res'=" "+`varlist'+" " `if' `in'
		if "`new'"=="" {
			local new " "
		}
		else	local new " `new' "
		replstr " `old' " "`new'" `n' `res' `if' `in'
		replace `res'=substr(`res',2,length(`res')-2)
		replace `res'="" if `res'==" "
		compress `res'
		local type : type `res'
		minlen `type' `varlist'
		replace `varlist'=`res' `if' `in'
	}
end