I have a question that feels painfully straightforward, but is giving me some trouble.
I have a list of variable names (ie. v1, v2, v3, v4...) and I want to loop over a bunch of datasets and drop any variables that are not contained in the list from each dataset
The simple idea is that I create a local list of these variables, and then essentially say:
That last command in quotes is my problem (hence the fact that it isn't an actual command). I'm only familiar with using the if option on the keep and drop commands when I'm keeping or dropping observations, but I need to apply it here to variables
I have a list of variable names (ie. v1, v2, v3, v4...) and I want to loop over a bunch of datasets and drop any variables that are not contained in the list from each dataset
The simple idea is that I create a local list of these variables, and then essentially say:
HTML Code:
loc varlist v1 v2 v3 v4... foreach dataset in ds1 ds2 ds3 { use `dataset', clear "keep if var is contained in varlist" }
Comment