Greetings everybody,
I have one big dataset with variables starting from v4 to v66, and I want to divide this big dataset into 21 separate datasets with 3 variables in each set. (dataset 1 includes variable v4, v5 and v6 dataset 2 includes variable v7, v8 and v9 ....and the like) I made this macro
local i 4
while `i' <= 66 {
insheet using "C:\Users\Lenovo\FileName.csv", comma clear
keep v`i' v`i+1' v`i+2'
save `i'.dta, replace
local i = `i' + 3
}
The "keep" command does not recognise v`i+1' and v`i+2'; it only keeps v`i'. Any ideas on how to tell Stata to keep the three variables for each dataset?
Thanks in advance.
L.
Related Posts with Loops and local macro
Categorical covariate for Parametric Survival ModelHello House, I am running parametric survival models using Code: streg Xlist distribution () time f…
inquire about ORDERED LOGISTIC REGRESSIONHello, in my research paper, I have a dependent variable: financial stress level 1-10. I have a set …
Manual -xtprobit, fe- and -xtoprobit, fe-?Dear listers, after estimating fixed effect regressions for an outcome with a limited number of val…
Error while trying to add legend to a KM plot.Hi, I am trying to create Kaplan-Meier curves and trying to see the difference according to age cate…
Combine string variables to make one idHi, I would like to combine string variables to make one id for each variable. The dataset looks l…
Subscribe to:
Post Comments (Atom)
0 Response to Loops and local macro
Post a Comment