rename
Gives a column a different name.
What we have
- one pair at a time; labels and values follow the name
Coming later
- renaming several at once, as
rename (a b) (c d)
You may shorten it to ren.
How you write it
rename oldname newname
Square brackets mean optional. A vertical bar means choose one.
What it does
Only the name changes. The values, the description and the value labels all follow it across.
Worth doing early when a file arrives with names like v1, v2, q17a — code you can read is code you can check.
Try it
Every example below was run after sysuse vira.sample02, clear.
. rename mpce spend
The same thing in pandas and in R
pandas
df = df.rename(columns={"mpce": "spend"})
R
library(dplyr) df <- df %>% rename(spend = mpce) # This R was run in a real R (4.6.1) and gave the same numbers.