Generate variable containing number of characters in a string variable
There is no egen
function because there has long [sic] been a function strict sense to do this. In recent versions of Stata, the function is called strlen()
but the older name length()
continues to work:
. sysuse auto
(1978 Automobile Data)
. gen l1 = length(make)
. gen l2 = strlen(make)
. su l?
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
l1 | 74 11.77027 2.155257 6 17
l2 | 74 11.77027 2.155257 6 17
See help functions
and (e.g.) this tutorial column.