Generating variables in Stata is quite simple, especially if you want to generate a new variable from an already existing variable. Researchers often generate new variables that are copies of a current one if they want to change or recode the data, while also keeping the original data so it is not lost. There is no formula for generating a new variable as it is likened to “copy” and “paste”.
Below is the code for generating the variable age1 from an already existing variable age.
Code
We are creating the new variable, age1, which is <- (equal) to the already existing variable age.
Below is the output for generating a new variable that is a copy of already existing data.
Output
> SLID$age1 <- SLID$age
The output is simply the code above. RStudio only gives us this output to tell us the code ran correctly and there are no issues. Another way to check is to go to the SLID dataset in RStudio and look for our new variable age1 as an added column.