Keep & drop variables

Keep & drop variables

* drop
drop medage // drop variable
drop death-divorce // drop variable list --> order important!
drop in 1/5 // drop observations 1-5 --> sort important! (avoid this!!!)
drop if state=="Ohio" // drop observations with variable state=="Ohio"

* keep
keep state pop* // keep variable state and all variables starting with "pop"
keep if pop>=1000000 // keep observations with variable pop>=1 million
keep if state!="Maine" // keep all observations but Maine

Exercise

Load the pre-installed dataset auto.

  1. Drop the variables turn, displacement, gear_ratio
  2. Drop observations with missing information on the repair record.
  3. Keep the variables make, price, mpg, length, and rep78.
  4. Keep only observations of cars which are up to 200 inches long and are domestic.