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
That’s just a new variable with the value 0 for all observations in the dataset. Not very useful, so let’s drop it:
Another use case would be dropping missing values. The rep78 (repair records from 1978), for instance has some missing values in it:
We can see that the variable rep78 has 5 missing values in it (denoted by .). Let’s drop these:
drop if rep78 == .
Now we can see that the missing values were dropped from the variable.
Written by Johan Osterberg who lives and works in Gothenburg, Sweden as a developer specialized in e-commerce. Connect with me on Linkedin