Rename & label variables

Renaming and labeling variables

/*
Meaningful variable names and labels are important to understand the data.
Labels are also useful for graphs, tables etc.
*/

sysuse census.dta, clear

* Rename variables
rename medage median_age // rename variable "medage" "median_age"
help rename group // you can rename variables in groups
rename pop* population* // one example of rename group
rename (state state2) (state_name state_code) // another example of rename group


* Label variables
describe pop* label variable populationlt5 "Population ages 0-4" // overwrite label
label variable population5_17 "" // delete label
describe pop*

// For value labels, see categorical variables

Exercise

Load the pre-installed dataset auto.

  1. Rename the variable “foreign” “origin” and label it “Car origin”.
  2. Use the group rename to rename “make” as “car”, “mpg” as “mileage”, and “rep78” as “repairs”..