Create a new variable based on an expression that can include multiple variables and/or values. This works pretty much like a calculator.
Below, two examples are presented.
Practical example 1
Dataset
StataData1.dta
Variable name
unemp_42
Variable label
Days in unemployment (Age 42, Year 2012)
Value labels
N/A
Variable name
unemp_43
Variable label
Days in unemployment (Age 43, Year 2013)
Value labels
N/A
Variable name
unemp_44
Variable label
Days in unemployment (Age 44, Year 2014)
Value labels
N/A
Variable name
unemp_45
Variable label
Days in unemployment (Age 45, Year 2015)
Value labels
N/A
gen unemp=unemp_42+unemp_43+unemp_44+unemp_45
The new variable unempcontains the sum of the other four variables.
sum unemp_42 unemp_43 unemp_44 unemp_45 unemp
browse unemp_42 unemp_43 unemp_44 unemp_45 unemp
Note If any of the variables that you include in the expression have missing values, the value for the new variable will be missing as well.
Practical example 2
Dataset
StataData1.dta
Variable name
bweight
Variable label
Birth weight (Age 0, Year 1970)
Value labels
N/A
gen bweight_grams=bweight*100
The old variable bweightshows birth weight in hectograms, but now we have created the new variable bweight_gramswhich shows birth weight in grams instead.