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
Coding all subsequent observations per group after an eventHello everyone, I have an unbalanced daily panel data which looks like below. "Pastdefault" and "No…
Weighting binary response based on certaintyHi everyone, If I have a binary response variable (yes/no to a hypothetical referendum on a survey)…
Quantile-Quantile plotsHi, I have been given a particular dataset which has the beta values and the corresponding z-scores…
mlogit/mprobit: Standard error for marginal effect on combination of outcomesDear statalist users, when estimating a multinomial logit or probit model for a dependent variable …
Generated regressor in interaction termHi everyone Short form of question Can you use standard corrections for generated regressors when t…
Subscribe to:
Post Comments (Atom)
0 Response to Loops and local macro
Post a Comment