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
keeping observation with lowest value and get the median of thatHello, I have a panel data and I want to keep the observation with the minimum value of Days for eac…
Wide to Long Reshaping Hi all, I have data in the following format: Code: * Example generated by -dataex-. For mo…
Choosing between Mean Group and Pooled Mean Group in ARDL modelsDear Stata users, Kindly help me with this problem. I am trying to choose the best model between t…
Difference in months between dates in year-month formatHi, I am a beginner in learning stata. I have data where I have a column for month in numbers 1 to …
Struggling with hbarI've been working to finalize my code for a figure, and I'm struggling to be able to see the entiret…
Subscribe to:
Post Comments (Atom)
0 Response to Loops and local macro
Post a Comment