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.
Saving coefficient estimates and using them for kdensityDear all, I am trying to figure out how after a regression, I can save the coefficient estimates an…
Reshaping and Transposing Data in StataDear Stata Users: I have the following table in STATA. The problem is all the data is in one row. I …
Abnormality when plotting discrete-time survival functionsHi all, thanks for reading! I'm running discrete-time survival analysis and trying to plot the step-…
Comparing and assessing the fit of SUR models in StataI have two SUR models for which I want to assess the fit. I understand there is controversy as to wh…
Survival analysis, discrete time - question on the model set up and goodness of fitHello Statalisters, I am trying to teach myself survival analysis estimation in STATA and at the mo…
Subscribe to:
Post Comments (Atom)
0 Response to Creating a foreach loop for all string values of a variable.
Post a Comment