Keeping variables in Stata

April 26, 2019

As an alternative to dropping variables, it’s possible to choose which ones to keep in a dataset. You can use the Variables Manager in Stata, or preferably the command line interface and the keep varlist command. For instance, working with the nlsw88 dataset:

keep age race married collgrad south union wage ttl_exp 

The above command keeps the listed variables in the dataset while the remainder is dropped. To undo, just reload the dataset in question.


Profile picture

Written by Johan Osterberg who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin

2024 © Johan Osterberg