The same commands are used for dropping / keeping variables or cases.

drop var17-var103 var314 var317

will delete the variables listed after "drop" from your data set. Using "keep" instead of drop would delete all variables not listed. Note that, in contrast to SPSS, you cannot drop or keep variables while saving a data set.

drop if income == 0

will delete all cases whose income equals zero. Using "keep" instead of drop would keep all cases with no income.

Temporarily dropping cases

Note that there seems to be no simple way to temporarily exclude cases from analyse ss (in analogy to the filter by command in SPSS). However, you can do analyses for a subset of your data using the if clause.

Another way for achieving this is using the preserve - restore clause. This allows you to drop cases, do your analyses and finally return to the full data set. A very brief example could go like this:

drop if income == 0
corr income education tenure gender
regress income education tenure gender

But note that (in contrast to SPSS's filter command) any changes made to the data after preserve will be "undone" by restore. In other words, any data transformations effected within the preserve - restore clause will be lost once you have restored the original data.

© W. Ludwig-Mayerhofer, Stata Guide | Last update: 14 May 2012