Hello,
I am sorry if this is something simple I am missing, and thank you in advance for your thoughts. I have a data set with 50+ variables, and I want to destring 20 of those variables and do not want to do anything to the other variables. When I destring, I also need to ignore(".,"). So I am attempting to write a simple foreach loop and limit this to the 20 variable columns. I have tried multiple different ways of writing this code, but every way I write the foreach loop it cycles through all variables in my data set (which I do not want). Here are some examples of the foreach code attempts I have made. (the varlist is u1 - u20). For some reason every way I attempt this Stata runs through every column and does the operation which is in brackets. I think I must be missing something here, but I just don't see it. Thank you again for your attention here.
foreach var in varlist u1 u2 u3 u4 u5 u6 u7 u8 u9 u10 u11 u12 u13 u14 u15 u16 u17 u18 u19 u20 {
destring, replace ignore(".,")
}
I have also tried....
foreach v in u1-u20 {
destring, replace ignore(".,")
}
And also tried....
foreach v in varlist u1-u20 {
destring, replace ignore(".,")
}
I also tried to use a local macro:
local vars u1 u2 u3
foreach var of local vars {
destring, replace ignore(".,")
}
Related Posts with Foreach code is not limiting to varlist
Fixed effects with multiple region-level observationsHi, I am using survey level data for the US which is divided at the county level, and I have multip…
Statistical significance for sigma_u and rho from Stata’s xtprobit commandDear all, I'm estimating a dynamic random effects probit model assuming a first order Markov proces…
Matrix - loop across variablesHi there, I wonder if anybody could help. This might be very obvious to more experienced users so I…
Help on regexmI have a multiple response variable codes as 00 01 02 03 04 05 06 07 08 09 10 11 12 as string variab…
What is wrong with my merge? (data examples are provided)I am merging the following two datasets. But I got 0 matched ((_merge==3) is zero). The code I used …
Subscribe to:
Post Comments (Atom)
0 Response to Foreach code is not limiting to varlist
Post a Comment