I was wondering what would be the best way to extract selected variables from a large dataset (DHS data). I will be working with 40-50 datsets, from which I will need to extract 10-20 variables and merge those into a new dataset.
Kindly advise how to avoid copy - paste.
To save a bit of time, in addition to what wangwang has suggested if you are bringing them in from another location like excel you can use -insheet- and specify the variables you want. If its always the same variable names you can loop this along with the merge. If the data are already in Stata format you wont need to do that, but I couldn't tell from your post what was the case.
On a kind of random note, can merge be used directly with non-Stata files? I've never thoguht about trying it, so maybe I am being really inefficient!
Thank you both. I am not so advanced as to create a local macro
The datasets are all in stata format already and normally all variables should be standardised (to double check). I was wondering whether there is any stata command which would allow to extract variables into a new dataset....
Any time efficient and simple solutions?
When you say extract what do you mean? Do you mean export to some other program?
Like wangwang said before, you use -keep- to specify which variables you want (if you want to keep it in Stata format) and then save. If you want to take it into another program you can use something like -outsheet-. Do you want to put everything into one file in which case you can use merge or append? If the problem is writing the loop we can probably provide examples, once we know a little more.
I'm sorry I don't think I have understood your question so I don't think this is helpful at all.
I agree with duskstar. It is very unclear what you're actually trying to do. I suggest providing a "before & after" example.
Advertise on Talk Stats