问题
I would like to avoid re-ordering the data to place the generated variable in the first column:
sysuse auto, clear
gen random = runiform()
order random
Is it possible to generate a variable and at the same time order it?
The idea is to be able to directly observe the generated variable when I browse the data in the editor, which is not easy when I have several variables.
回答1:
You can use the before()
option:
sysuse auto, clear
generate random = runiform(), before(make)
You can also further automate this process as follows:
unab var : *
gettoken var : var
generate random = runiform(), before(`var')
来源:https://stackoverflow.com/questions/57234995/generating-and-ordering-a-variable-simultaneously