In a survey dataset I have a string variable (type: str244
) with qualitative responses. I want to count the number of characters in each response/string and generate a new variable containing this number.
Using the egenmore
I have already counted the number of words using nwords
, but I cannot find the counterpart for counting characters.
EXAMPLE:
egen countvar = nwords(stringvar)
where countvar
is the new variable name and stringvar
is the string variable.
Does such an egen
function exist for counting characters?
wordcount()
in Stata makes the older add-onnwords()
redundant. Noteegenmore
is downloaded usingssc inst egenmore
. – Deliquesceegenmore
does point towordcount()
. N.B.nwords()
(written for Stata 6) is very slow. – Deliquescegen countvar = wordcount(stringvar)
works like a charm. I wasn't aware thatwordcount
was used withgen
, notegen
. Perfect! – Potiche