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
Simultaneous Quantile Regression with PweightsDoes anyone know how to run a simultaneous quantile regression with pweights? I am trying to test wh…
How to: Regression with ARMA errors?Hello everyone! I need to estimate a regression model with ARMA errors but am not sure how to do so…
Getting around the time limit imposed by the serverDear all, Hope everyone is staying well in this difficult time. I am bootstrapping standard errors…
Labelling automatically deleted observations in logistical regression with backward stepwise method.Dear stata users, I am conduction research after risk factors for mortality in thoracic trauma. I a…
How to save quantiles as new variables?Hi! I am trying to create new variables using quantiles. This is what I have done so far: Using xt…
Subscribe to:
Post Comments (Atom)
0 Response to Foreach code is not limiting to varlist
Post a Comment