Recoding variables in Stata is very simple. It is useful in many scenarios, for instance where you would want to merge a variable containing many values into a few distinct categories. Let’s use the nlsw88 dataset and the age variable:
sysuse nlsw88, clear
tab age
This variable has quite a few values, let’s say we’d want to merge them into three distinct categories. To achieve this in Stata, we use the recode command and applying the ranges we want to merge.
recode age (30/37=1) (38/41=2) (42/46=3)
tab age
And now all values are recoded into three new distinct categories.