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!
Related Posts with Creating a foreach loop for all string values of a variable.
Difference-in-Difference with three time periods when age assigns treatmentDear Statalist, I am trying to estimate the effect of a pension reform on work status of poor peopl…
panel data regression at higher level of aggregationHi, I have data in individual level but want to run a regression to test for the correlation between…
Generate new variable by command "if"Hi I want to create a new variable (var3) using an existing variable (var2). Like the attached photo…
Advice on which model to use with binary dependent variable and endogenous ordinal independent variableHello, I have come to a roadblock in my research. I am trying to figure out what type of model to us…
mean through several variables Hello, I have 4 different variables, each with the expression 1-5. the variables include mental he…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a foreach loop for all string values of a variable.
Post a Comment