Hi all,
I have 55 datasets, all with the same set of 60 variables, but some of them have missing data for some of the variables. I want to loop my code over each dataset, but select which variables to choose for each command based on which variables don't have missing data. I am trying something like this to create a local macro with variable names that don't have missing data. I have created a new local macro `data', that is 0 when the data is missing. Is there a way to remove these from the list, as well as the related variable names in `x_all'? i.e. in the example below, to create a new local macro x_all_2 with only rep78 and turn.
Thanks,
Sonia
I have 55 datasets, all with the same set of 60 variables, but some of them have missing data for some of the variables. I want to loop my code over each dataset, but select which variables to choose for each command based on which variables don't have missing data. I am trying something like this to create a local macro with variable names that don't have missing data. I have created a new local macro `data', that is 0 when the data is missing. Is there a way to remove these from the list, as well as the related variable names in `x_all'? i.e. in the example below, to create a new local macro x_all_2 with only rep78 and turn.
Code:
sysuse auto, clear
gen colour = .
local x_all rep78 turn colour
local data
foreach empty of local x_all {
tab `empty'
local data `data' `r(N)'
}
di "`data'"
Sonia

Comment