Dropping values in Stata

April 22, 2019

Dropping values in Stata is achieved by the drop command. Let’s load the auto training dataset and create a new variable:

gen my_car = 0
tab my_car

Generating a new variable

That’s just a new variable with the value 0 for all observations in the dataset. Not very useful, so let’s drop it:

drop my_car

Another use case would be dropping missing values. The rep78 (repair records from 1978), for instance has some missing values in it:

misstable summarize

Result of misstable summarize

We can see that the variable rep78 has 5 missing values in it (denoted by .). Let’s drop these:

drop if rep78 == .

Result of drop cmd

Now we can see that the missing values were dropped from the variable.


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