Making and changing variables
Adding columns, fixing values, renaming, sorting, labelling.
What we have
- Adds a new column, worked out from the ones you already have.
- Changes values in a column you already have.
- Adds a column holding a group summary — the group's average, total, biggest.
- Turns values into other values by rule — ages into age bands, say.
- Gives a column a different name.
- Moves columns to the front so they are the first thing you see.
- Removes columns, or removes rows.
- The opposite of
drop: keeps only what you name and removes the rest. - Puts the rows in order, smallest first.
- Sorts with a direction you choose for each column.
- Attaches readable text to a column, or to the codes inside it.
- Turns a text column into numbered categories.
- Turns a coded number back into the words it stands for.
- Turns a column of text that is really numbers into actual numbers.
- Turns a number column into text.
- Takes a snapshot of the data so you can get it back.
- Puts back the data that
preservesaved.
Coming later
- Stata's
bysort x (y):, which sorts within the group on the same line — usesortthenby format(), to control how the number is written outformat— there is no way to set how a number printslabel language, for more than one set of labels at a timelabel()— accepted, but the label set is still named after the new variableorder, alphabeticpctile(),rank(),cut()and the rest of Stata's egen libraryrecode's label options, which name the new categories as they are maderuniform()and the other random-number functions- renaming several at once, as
rename (a b) (c d)
generateAdds a new column, worked out from the ones you already have.
replaceChanges values in a column you already have.
egenAdds a column holding a group summary — the group's average, total, biggest.
recodeTurns values into other values by rule — ages into age bands, say.
renameGives a column a different name.
orderMoves columns to the front so they are the first thing you see.
dropRemoves columns, or removes rows.
keepThe opposite of drop: keeps only what you name and removes the rest.
sortPuts the rows in order, smallest first.
gsortSorts with a direction you choose for each column.
labelAttaches readable text to a column, or to the codes inside it.
encodeTurns a text column into numbered categories.
decodeTurns a coded number back into the words it stands for.
destringTurns a column of text that is really numbers into actual numbers.
tostringTurns a number column into text.
preserveTakes a snapshot of the data so you can get it back.
restorePuts back the data that preserve saved.