Hello,
I am looking to code a foreach loop that completes a ustrlen() command for all string values of a variable, not just the distinct values. I have been able to get some success with the following code, but as expected of the levelsof command it only completes the ustrlen() command to only distinct string values.
. levelsof variable, local(levels)
. foreach v of local levels {
2. display ((ustrlen("`v'")-3)/4)+1
3. }
I have been referencing the related documentation and this page, https://www.stata.com/support/faqs/d...-with-foreach/, but have not been able to find success with Method 1. Is there a command similar to levelsof that would allow me to complete this loop?
Thanks very much in advance!
0 Response to Creating a foreach loop for all string values of a variable.
Post a Comment