Generating and ordering a variable simultaneously

风格不统一 提交于 2020-01-15 11:55:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!