~dricottone/ado-personal

0e0681676824534589231032090e2035965e1744 — dricottone 3 years ago 247704c
Add count_nonascii
1 files changed, 25 insertions(+), 0 deletions(-)

A count_nonascii.ado
A count_nonascii.ado => count_nonascii.ado +25 -0
@@ 0,0 1,25 @@

program count_nonascii
	syntax [varlist(string default=none)]

	if "`varlist'"=="" {
		quietly ds, has(type string)
		local varlist `r(varlist)'
	}

	local affected 0
	local total 0

	foreach v of varlist `varlist' {
		quietly count if ustrregexm(`v',"[^ -~]")
		local affected = `affected' + r(N)

		quietly generate int _nonascii = ustrlen(`v') - ustrlen(ustrregexra(`v',"[^ -~]",""))
		quietly egen _subtotal = total(_nonascii)
		local total = `total' + _subtotal[1]

		quietly drop _nonascii _subtotal
	}

	display "There are `total' Unicode characters in `affected' values"
end